#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 EOF;
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(int);
int fscan(int /*<<< orphan*/ *, char *, int *);
int trace_reader(int argc, char *argv[]) {
  assert(argv[1] != NULL);
  FILE *filepntr;
  filepntr = fopen(argv[1], "r");
  int retVal;
  int mem_address;
  while ((retVal = fscan(filepntr, "%x", &mem_address)) != EOF) {
    return mem_address;
  }
  fclose(filepntr);
  free(retVal);
  free(mem_address);
}


x86 assembly (clang, -O0):
<trace_reader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6a(%rip),%rsi
lea    -0x20(%rbp),%rdx
call   1050 <fscan@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e3d(%rip),%rcx
cmp    (%rcx),%eax
je     11be <trace_reader+0x6e>
mov    -0x20(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11d7 <trace_reader+0x87>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x1c(%rbp),%edi
call   1030 <free@plt>
mov    -0x20(%rbp),%edi
call   1030 <free@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trace_reader>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
xor    %edi,%edi
cmpq   $0x0,0x8(%rsi)
setne  %dil
call   1060 <assert@plt>
mov    0x8(%rbx),%rdi
lea    0xe8f(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1050 <fscan@plt>
mov    %eax,%ebp
mov    0x2e52(%rip),%rax
cmp    (%rax),%ebp
jne    11b4 <trace_reader+0x64>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%edi
call   1030 <free@plt>
mov    0x4(%rsp),%edi
call   1030 <free@plt>
jmp    11b8 <trace_reader+0x68>
mov    0x4(%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%x\00"
@EOF = global i32 0
define i32 @trace_reader(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = load i8*, i8** %4
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = bitcast i32* %3 to i8*
%12 = call i32 @fscan(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %3)
%13 = load i32, i32* @EOF
%14 = icmp eq i32 %12, %13
br i1 %14, label %17, label %15
15: ; preds = %2
%16 = load i32, i32* %3
br label %22
17: ; preds = %2
%18 = call i32 @fclose(i32* %10)
%19 = call i32 @free(i32 %12)
%20 = load i32, i32* %3
%21 = call i32 @free(i32 %20)
br label %22
22: ; preds = %17, %15
%23 = phi i32 [ %16, %15 ], [ undef, %17 ]
ret i32 %23
}