#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*/ free(char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *);
int main() {
  FILE *file_ptr = fopen("test.txt", "r");
  if (file_ptr == NULL)
    return 1;
  char *string = malloc(256);
  fscanf(file_ptr, "%s", string);
  fclose(file_ptr);
  reverse(string);
  printf("%s\n", string);
  free(string);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe7a(%rip),%rdi
lea    0xe7c(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ad <main+0x3d>
movl   $0x1,-0x4(%rbp)
jmp    1201 <main+0x91>
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe41(%rip),%rsi
call   1070 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <reverse@plt>
mov    -0x18(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
lea    0xe85(%rip),%rdi
lea    0xe87(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     11d9 <main+0x69>
mov    %rax,%rbx
mov    $0x100,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
lea    0xe68(%rip),%rsi
mov    %rbx,%rdi
mov    %rax,%rdx
call   1070 <fscanf@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <reverse@plt>
lea    0xe49(%rip),%rdi
mov    %r14,%rsi
call   1060 <printf@plt>
mov    %r14,%rdi
call   1040 <free@plt>
xor    %eax,%eax
jmp    11de <main+0x6e>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
store i32 0, i32* %1
%4 = 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* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %8
7: ; preds = %0
store i32 1, i32* %1
br label %21
8: ; preds = %0
%9 = call i8* @malloc(i32 256)
store i8* %9, i8** %3
%10 = load i32*, i32** %2
%11 = load i8*, i8** %3
%12 = call i32 @fscanf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %2
%14 = call i32 @fclose(i32* %13)
%15 = load i8*, i8** %3
%16 = call i32 @reverse(i8* %15)
%17 = load i8*, i8** %3
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%19 = load i8*, i8** %3
%20 = call i32 @free(i8* %19)
store i32 0, i32* %1
br label %21
21: ; preds = %8, %7
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = 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))
%2 = icmp eq i32* %1, null
br i1 %2, label %10, label %3
3: ; preds = %0
%4 = tail call dereferenceable_or_null(256) i8* @malloc(i32 256)
%5 = tail call i32 @fscanf(i32* %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%6 = tail call i32 @fclose(i32* %1)
%7 = tail call i32 @reverse(i8* %4)
%8 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %4)
%9 = tail call i32 @free(i8* %4)
br label %10
10: ; preds = %0, %3
%11 = phi i32 [ 0, %3 ], [ 1, %0 ]
ret i32 %11
}