#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ u_char;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *);
int create_msg(u_char *msg, int len) {
  FILE *f;
  int i = 0;
  int c;
  if ((f = fopen("iquery-file", "r")) == NULL) {
    if (0)
      printf("iquery-file not found!\n");
    return -1;
  }
  while (((c = fgetc(f)) != EOF) && (i < len)) {
    *msg++ = (u_char)c;
    i++;
  }
  fclose(f);
  return i;
}


x86 assembly (clang, -O0):
<create_msg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movl   $0x0,-0x24(%rbp)
lea    0xeb3(%rip),%rdi
lea    0xeb8(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1173 <create_msg+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11e9 <create_msg+0xb9>
jmp    1178 <create_msg+0x48>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
xor    %eax,%eax
mov    0x2e59(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x29(%rbp)
je     11a6 <create_msg+0x76>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11b6 <create_msg+0x86>
jmp    11da <create_msg+0xaa>
movslq -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rax,%rdx
add    $0x8,%rdx
mov    %rdx,-0x10(%rbp)
mov    %rcx,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1178 <create_msg+0x48>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_msg>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %esi,%r15d
mov    %rdi,%r14
lea    0xebb(%rip),%rdi
lea    0xec0(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11a7 <create_msg+0x77>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <fgetc@plt>
mov    0x2e80(%rip),%r12
xor    %ebp,%ebp
cmp    (%r12),%eax
je     119d <create_msg+0x6d>
test   %r15d,%r15d
jle    119d <create_msg+0x6d>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cltq
mov    %rax,(%r14,%rbp,8)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%eax
je     119d <create_msg+0x6d>
cmp    %r15d,%ebp
jl     1180 <create_msg+0x50>
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11ac <create_msg+0x7c>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"iquery-file\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @create_msg(i64* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i64*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i64* %0, i64** %4
store i32 %1, i32* %5
store i32 0, i32* %7
%9 = call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %9, i32** %6
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 -1, i32* %3
br label %35
12: ; preds = %2
br label %13
13: ; preds = %24, %12
%14 = load i32*, i32** %6
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %8
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = load i32, i32* %7
%20 = load i32, i32* %5
%21 = icmp slt i32 %19, %20
br label %22
22: ; preds = %18, %13
%23 = phi i1 [ false, %13 ], [ %21, %18 ]
br i1 %23, label %24, label %31
24: ; preds = %22
%25 = load i32, i32* %8
%26 = sext i32 %25 to i64
%27 = load i64*, i64** %4
%28 = getelementptr inbounds i64, i64* %27, i32 1
store i64* %28, i64** %4
store i64 %26, i64* %27
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %13
31: ; preds = %22
%32 = load i32*, i32** %6
%33 = call i32 @fclose(i32* %32)
%34 = load i32, i32* %7
store i32 %34, i32* %3
br label %35
35: ; preds = %31, %11
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@.str = [12 x i8] c"iquery-file\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
define i32 @create_msg(i64* nocapture writeonly %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = tail call i32 @fgetc(i32* %3)
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %6, %7
%9 = icmp sgt i32 %1, 0
%10 = and i1 %8, %9
br i1 %10, label %11, label %23
11: ; preds = %5, %11
%12 = phi i32 [ %18, %11 ], [ %6, %5 ]
%13 = phi i32 [ %17, %11 ], [ 0, %5 ]
%14 = phi i64* [ %16, %11 ], [ %0, %5 ]
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i64, i64* %14, i64 1
store i64 %15, i64* %14
%17 = add nuw nsw i32 %13, 1
%18 = tail call i32 @fgetc(i32* %3)
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
%21 = icmp slt i32 %17, %1
%22 = select i1 %20, i1 %21, i1 false
br i1 %22, label %11, label %23
23: ; preds = %11, %5
%24 = phi i32 [ 0, %5 ], [ %17, %11 ]
%25 = tail call i32 @fclose(i32* %3)
br label %26
26: ; preds = %2, %23
%27 = phi i32 [ %24, %23 ], [ -1, %2 ]
ret i32 %27
}