#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);
int stat(char const *, struct stat *);
int strlen(char const *);
void openScalapackStore(FILE **store, int myrow, int mycol,
                        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/blockR%dC%d.txt", location, myrow, mycol);
  *store = fopen(file_name, "w");
  free(file_name);
}


x86 assembly (clang, -O0):
<openScalapackStore>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %rcx,-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    11ca <openScalapackStore+0x4a>
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
mov    -0x10(%rbp),%r8d
lea    0xe01(%rip),%rsi
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xe04(%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):
<openScalapackStore>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%rbx
mov    %edx,%r15d
mov    %esi,%r12d
mov    %rdi,%r14
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rcx,%rdi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    11af <openScalapackStore+0x3f>
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    0xe34(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
mov    %r12d,%ecx
mov    %r15d,%r8d
call   1090 <sprintf@plt>
lea    0xe2f(%rip),%rsi
mov    %rbp,%rdi
call   1080 <fopen@plt>
mov    %rax,(%r14)
mov    %rbp,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

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

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