#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 */
struct stat {
  int /*<<< orphan*/ member_0;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ mkdir(char const *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, int);
int stat(char const *, struct stat *);
int strlen(char const *);
void openStore(FILE **store, int i_block, const char *location) {
  struct stat st = {0};
  if (stat(location, &st) == -1) {
    mkdir(location, 0700);
  }
  char *file_name = malloc(sizeof(char) * (strlen(location) + 300));
  sprintf(file_name, "%s/block%d.txt", location, i_block);
  *store = fopen(file_name, "w");
  free(file_name);
}


x86 assembly (clang, -O0):
<openStore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1060 <memset@plt>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c7 <openStore+0x47>
mov    -0x18(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    -0x18(%rbp),%rdi
call   1050 <strlen@plt>
add    $0x12c,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%ecx
lea    0xe08(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openStore>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %esi,%r15d
mov    %rdi,%r14
movl   $0x0,(%rsp)
mov    %rsp,%rsi
mov    %rdx,%rdi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    11a4 <openStore+0x34>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
lea    0x12c(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
lea    0xe3f(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r15d,%ecx
call   1090 <sprintf@plt>
lea    0xe39(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,(%r14)
mov    %rbp,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [15 x i8] c"%s/block%d.txt\00"
@.str.1 = [2 x i8] c"w\00"
define void @openStore(i32** %0, i32 %1, i8* %2) {
%4 = alloca i32**
%5 = alloca i32
%6 = alloca i8*
%7 = alloca %struct.stat
%8 = alloca i8*
store i32** %0, i32*** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%9 = bitcast %struct.stat* %7 to i8*
%10 = load i8*, i8** %6
%11 = call i32 @stat(i8* %10, %struct.stat* %7)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %3
%14 = load i8*, i8** %6
%15 = call i32 @mkdir(i8* %14, i32 448)
br label %16
16: ; preds = %13, %3
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %18, 300
%20 = sext i32 %19 to i64
%21 = mul i64 1, %20
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i8*, i8** %6
%26 = load i32, i32* %5
%27 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %25, i32 %26)
%28 = load i8*, i8** %8
%29 = call i32* @fopen(i8* %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32**, i32*** %4
store i32* %29, i32** %30
%31 = load i8*, i8** %8
%32 = call i32 @free(i8* %31)
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [15 x i8] c"%s/block%d.txt\00"
@.str.1 = [2 x i8] c"w\00"
define void @openStore(i32** nocapture writeonly %0, i32 %1, i8* %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
%6 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
store i32 0, i32* %6
%7 = call i32 @stat(i8* %2, %struct.stat* %4)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @mkdir(i8* %2, i32 448)
br label %11
11: ; preds = %9, %3
%12 = tail call i32 @strlen(i8* %2)
%13 = add nsw i32 %12, 300
%14 = tail call i8* @malloc(i32 %13)
%15 = tail call i32 @sprintf(i8* dereferenceable(1) %14, i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %1)
%16 = tail call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %16, i32** %0
%17 = tail call i32 @free(i8* %14)
ret void
}