#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 *, int);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int cmp_ad() {
  FILE *pFcomp;
  int a, b;
  pFcomp = fopen("temp_mem_ad.txt", "r");
  fscanf(pFcomp, "%x", &a);
  fclose(pFcomp);
  pFcomp = fopen("emp_mem_ad.txt", "w");
  fprintf(pFcomp, "%d", (a - 0x40000000));
  fclose(pFcomp);
  pFcomp = fopen("emp_mem_ad.txt", "r");
  fscanf(pFcomp, "%d", &b);
  fclose(pFcomp);
  return b;
}


x86 assembly (clang, -O0):
<cmp_ad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xeb1(%rip),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea8(%rip),%rsi
lea    -0xc(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe7e(%rip),%rdi
lea    0xe8b(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
sub    $0x40000000,%edx
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
lea    0xe45(%rip),%rdi
lea    0xe4d(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe40(%rip),%rsi
lea    -0x10(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cmp_ad>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xeb1(%rip),%rdi
lea    0xeba(%rip),%r14
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
lea    0xeaa(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
lea    0xe7d(%rip),%r15
lea    0xe8a(%rip),%rsi
mov    %r15,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    $0xc0000000,%edx
add    0x4(%rsp),%edx
lea    0xe71(%rip),%r12
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%rdx
mov    %rax,%rdi
mov    %r12,%rsi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%rsp),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [16 x i8] c"temp_mem_ad.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [15 x i8] c"emp_mem_ad.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @cmp_ad() {
%1 = alloca i32*
%2 = alloca i32
%3 = alloca i32
%4 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 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** %1
%5 = load i32*, i32** %1
%6 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%7 = load i32*, i32** %1
%8 = call i32 @fclose(i32* %7)
%9 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %9, i32** %1
%10 = load i32*, i32** %1
%11 = load i32, i32* %2
%12 = sub nsw i32 %11, 1073741824
%13 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %12)
%14 = load i32*, i32** %1
%15 = call i32 @fclose(i32* %14)
%16 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %1
%17 = load i32*, i32** %1
%18 = call i32 @fscanf(i32* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %3)
%19 = load i32*, i32** %1
%20 = call i32 @fclose(i32* %19)
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@.str = [16 x i8] c"temp_mem_ad.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [3 x i8] c"%x\00"
@.str.3 = [15 x i8] c"emp_mem_ad.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @cmp_ad() {
%1 = alloca i32
%2 = alloca i32
%3 = bitcast i32* %1 to i8*
%4 = bitcast i32* %2 to i8*
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %1)
%7 = call i32 @fclose(i32* %5)
%8 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = load i32, i32* %1
%10 = add nsw i32 %9, -1073741824
%11 = call i32 @fprintf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 %10)
%12 = call i32 @fclose(i32* %8)
%13 = call i32* @fopen(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %2)
%15 = call i32 @fclose(i32* %13)
%16 = load i32, i32* %2
ret i32 %16
}