#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*/ fread(long *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, long);
long aroma_isexist_mem(void *x) {
  char pn[256];
  snprintf(pn, 256, "%s/%i", "/tmp/aroma-memory", (long)x);
  FILE *fp = fopen(pn, "r");
  if (fp) {
    long sz = 0;
    fread(&sz, 1, sizeof(long), fp);
    fclose(fp);
    return sz;
  }
  return 0;
}


x86 assembly (clang, -O0):
<aroma_isexist_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x10(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%r8
mov    $0x100,%esi
lea    0xe9a(%rip),%rdx
lea    0xe99(%rip),%rcx
call   1050 <snprintf@plt>
lea    -0x110(%rbp),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11de <aroma_isexist_mem+0x9e>
movq   $0x0,-0x120(%rbp)
mov    -0x118(%rbp),%rcx
lea    -0x120(%rbp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
call   1030 <fread@plt>
mov    -0x118(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x120(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11e6 <aroma_isexist_mem+0xa6>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<aroma_isexist_mem>:
push   %rbx
sub    $0x110,%rsp
mov    %rdi,%r8
lea    0xeae(%rip),%rdx
lea    0xead(%rip),%rcx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1050 <snprintf@plt>
lea    0xea6(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11b1 <aroma_isexist_mem+0x71>
mov    %rax,%rbx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
mov    $0x1,%esi
mov    $0x8,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    0x8(%rsp),%rax
jmp    11b3 <aroma_isexist_mem+0x73>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%i\00"
@.str.1 = [18 x i8] c"/tmp/aroma-memory\00"
@.str.2 = [2 x i8] c"r\00"
define i64 @aroma_isexist_mem(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca [256 x i8]
%5 = alloca i32*
%6 = alloca i64
store i8* %0, i8** %3
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = load i8*, i8** %3
%9 = ptrtoint i8* %8 to i64
%10 = call i32 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %9)
%11 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %12, i32** %5
%13 = load i32*, i32** %5
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %21
15: ; preds = %1
store i64 0, i64* %6
%16 = load i32*, i32** %5
%17 = call i32 @fread(i64* %6, i32 1, i32 8, i32* %16)
%18 = load i32*, i32** %5
%19 = call i32 @fclose(i32* %18)
%20 = load i64, i64* %6
store i64 %20, i64* %2
br label %22
21: ; preds = %1
store i64 0, i64* %2
br label %22
22: ; preds = %21, %15
%23 = load i64, i64* %2
ret i64 %23
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%i\00"
@.str.1 = [18 x i8] c"/tmp/aroma-memory\00"
@.str.2 = [2 x i8] c"r\00"
define i64 @aroma_isexist_mem(i8* %0) {
%2 = alloca [256 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%5 = ptrtoint i8* %0 to i64
%6 = call i32 @snprintf(i8* %4, i32 256, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i64 %5)
%7 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %14, label %9
9: ; preds = %1
%10 = bitcast i64* %3 to i8*
store i64 0, i64* %3
%11 = call i32 @fread(i64* %3, i32 1, i32 8, i32* %7)
%12 = call i32 @fclose(i32* %7)
%13 = load i64, i64* %3
br label %14
14: ; preds = %1, %9
%15 = phi i64 [ %13, %9 ], [ 0, %1 ]
ret i64 %15
}