#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 int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
char *read_file(int /*<<< orphan*/ *);
int /*<<< orphan*/ smb___free(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int test_read_file(void) {
  FILE *f = fopen("res/file.txt", "r");
  char *expected = "This is the first line of my file.\n"
                   "This is the second line of my file.\n";
  char *str = read_file(f);
  do {
    if (strcmp((expected), (str)) != 0) {
      fprintf(stderr, "Assertion failed: \"%s\" != \"%s\"\n", expected, str);
      return 32;
    }
  } while (0);
  smb___free(str);
  fclose(f);
  return 0;
}


x86 assembly (clang, -O0):
<test_read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xe91(%rip),%rdi
lea    0xe97(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    0xe89(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <read_file@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11d7 <test_read_file+0x77>
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe91(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x20,-0x4(%rbp)
jmp    11f5 <test_read_file+0x95>
jmp    11dc <test_read_file+0x7c>
mov    -0x20(%rbp),%rdi
call   1030 <smb___free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_read_file>:
push   %r14
push   %rbx
push   %rax
lea    0xe95(%rip),%rdi
lea    0xe9b(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <read_file@plt>
mov    %rax,%rbx
lea    0xe83(%rip),%rdi
mov    %rax,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11bf <test_read_file+0x5f>
mov    0x2e40(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
lea    0xe5f(%rip),%rdx
mov    %rbx,%rcx
call   1060 <fprintf@plt>
mov    $0x20,%eax
jmp    11d1 <test_read_file+0x71>
mov    %rbx,%rdi
call   1030 <smb___free@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [13 x i8] c"res/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [72 x i8] c"This is the first line of my file.\0AThis is the second line of my file.\0A\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Assertion failed: \22%s\22 != \22%s\22\0A\00"
define i32 @test_read_file() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i8*
%5 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %5, i32** %2
store i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8** %3
%6 = load i32*, i32** %2
%7 = call i8* @read_file(i32* %6)
store i8* %7, i8** %4
br label %8
8: ; preds = %0
%9 = load i8*, i8** %3
%10 = load i8*, i8** %4
%11 = call i64 @strcmp(i8* %9, i8* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %18
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* %16)
store i32 32, i32* %1
br label %24
18: ; preds = %8
br label %19
19: ; preds = %18
%20 = load i8*, i8** %4
%21 = call i32 @smb___free(i8* %20)
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
store i32 0, i32* %1
br label %24
24: ; preds = %19, %13
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [13 x i8] c"res/file.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [72 x i8] c"This is the first line of my file.\0AThis is the second line of my file.\0A\00"
@stderr = global i32 0
@.str.3 = [32 x i8] c"Assertion failed: \22%s\22 != \22%s\22\0A\00"
define i32 @test_read_file() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = tail call i8* @read_file(i32* %1)
%3 = tail call i64 @strcmp(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* %2)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %11
8: ; preds = %0
%9 = tail call i32 @smb___free(i8* %2)
%10 = tail call i32 @fclose(i32* %1)
br label %11
11: ; preds = %8, %5
%12 = phi i32 [ 32, %5 ], [ 0, %8 ]
ret i32 %12
}