#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("testcase", "r")) == NULL) {
    printf("testcase 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    0xea3(%rip),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    118f <create_msg+0x4f>
lea    0xe8d(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1205 <create_msg+0xc5>
jmp    1194 <create_msg+0x54>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,%ecx
mov    %ecx,-0x28(%rbp)
xor    %eax,%eax
mov    0x2e3d(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x29(%rbp)
je     11c2 <create_msg+0x82>
mov    -0x24(%rbp),%eax
cmp    -0x14(%rbp),%eax
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11d2 <create_msg+0x92>
jmp    11f6 <create_msg+0xb6>
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    1194 <create_msg+0x54>
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    0xeab(%rip),%rdi
lea    0xead(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b7 <create_msg+0x77>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <fgetc@plt>
mov    0x2e70(%rip),%r12
xor    %ebp,%ebp
cmp    (%r12),%eax
je     11ad <create_msg+0x6d>
test   %r15d,%r15d
jle    11ad <create_msg+0x6d>
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
cltq
mov    %rax,(%r14,%rbp,8)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1050 <fgetc@plt>
cmp    (%r12),%eax
je     11ad <create_msg+0x6d>
cmp    %r15d,%ebp
jl     1190 <create_msg+0x50>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11c8 <create_msg+0x88>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"testcase\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [21 x i8] c"testcase not found!\0A\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 ([9 x i8], [9 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 %13
11: ; preds = %2
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %36
13: ; preds = %2
br label %14
14: ; preds = %25, %13
%15 = load i32*, i32** %6
%16 = call i32 @fgetc(i32* %15)
store i32 %16, i32* %8
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %16, %17
br i1 %18, label %19, label %23
19: ; preds = %14
%20 = load i32, i32* %7
%21 = load i32, i32* %5
%22 = icmp slt i32 %20, %21
br label %23
23: ; preds = %19, %14
%24 = phi i1 [ false, %14 ], [ %22, %19 ]
br i1 %24, label %25, label %32
25: ; preds = %23
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = load i64*, i64** %4
%29 = getelementptr inbounds i64, i64* %28, i32 1
store i64* %29, i64** %4
store i64 %27, i64* %28
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
br label %14
32: ; preds = %23
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
%35 = load i32, i32* %7
store i32 %35, i32* %3
br label %36
36: ; preds = %32, %11
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [9 x i8] c"testcase\00"
@.str.1 = [2 x i8] c"r\00"
@EOF = global i32 0
@str = [20 x i8] c"testcase not found!\00"
define i32 @create_msg(i64* nocapture writeonly %0, i32 %1) {
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 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 %11, 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 %13, label %25
11: ; preds = %2
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str, i64 0, i64 0))
br label %28
13: ; preds = %5, %13
%14 = phi i32 [ %20, %13 ], [ %6, %5 ]
%15 = phi i32 [ %19, %13 ], [ 0, %5 ]
%16 = phi i64* [ %18, %13 ], [ %0, %5 ]
%17 = sext i32 %14 to i64
%18 = getelementptr inbounds i64, i64* %16, i64 1
store i64 %17, i64* %16
%19 = add nuw nsw i32 %15, 1
%20 = tail call i32 @fgetc(i32* %3)
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
%23 = icmp slt i32 %19, %1
%24 = select i1 %22, i1 %23, i1 false
br i1 %24, label %13, label %25
25: ; preds = %13, %5
%26 = phi i32 [ 0, %5 ], [ %19, %13 ]
%27 = tail call i32 @fclose(i32* %3)
br label %28
28: ; preds = %25, %11
%29 = phi i32 [ -1, %11 ], [ %26, %25 ]
ret i32 %29
}