#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ mkdir(char const *, int);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
int stat(char const *, struct stat *);
int strlen(char const *);
void saveMatrixDescriptor(int *desc, 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/descriptor.txt", location);
  FILE *store = fopen(file_name, "w");
  free(file_name);
  int i;
  for (i = 0; i < 9; i++) {
    fprintf(store, "%d\n", desc[i]);
  }
  fclose(store);
}


x86 assembly (clang, -O0):
<saveMatrixDescriptor>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x4,%edx
call   1070 <memset@plt>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1090 <stat@plt>
cmp    $0xffffffff,%eax
jne    11e4 <saveMatrixDescriptor+0x44>
mov    -0x10(%rbp),%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
add    $0x12c,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xdee(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x20(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0x9,-0x2c(%rbp)
jge    126e <saveMatrixDescriptor+0xce>
mov    -0x28(%rbp),%rdi
mov    -0x8(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xdb9(%rip),%rsi
call   1080 <fprintf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    123b <saveMatrixDescriptor+0x9b>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<saveMatrixDescriptor>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
movl   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1080 <stat@plt>
cmp    $0xffffffff,%eax
jne    11c6 <saveMatrixDescriptor+0x36>
mov    %rbx,%rdi
mov    $0x1c0,%esi
call   1040 <mkdir@plt>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x12c(%rax),%edi
call   1090 <malloc@plt>
mov    %rax,%r15
lea    0xe1d(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   10b0 <sprintf@plt>
lea    0xe1d(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbx
mov    %r15,%rdi
call   1030 <free@plt>
mov    (%r14),%edx
lea    0xe02(%rip),%r15
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0x4(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0x8(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0xc(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0x10(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0x14(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0x18(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0x1c(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    0x20(%r14),%edx
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <fprintf@plt>
mov    %rbx,%rdi
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <fclose@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [18 x i8] c"%s/descriptor.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%d\0A\00"
define void @saveMatrixDescriptor(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
%9 = bitcast %struct.stat* %5 to i8*
%10 = load i8*, i8** %4
%11 = call i32 @stat(i8* %10, %struct.stat* %5)
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @mkdir(i8* %14, i32 448)
br label %16
16: ; preds = %13, %2
%17 = load i8*, i8** %4
%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** %6
%24 = load i8*, i8** %6
%25 = load i8*, i8** %4
%26 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %6
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i8*, i8** %6
%30 = call i32 @free(i8* %29)
store i32 0, i32* %8
br label %31
31: ; preds = %42, %16
%32 = load i32, i32* %8
%33 = icmp slt i32 %32, 9
br i1 %33, label %34, label %45
34: ; preds = %31
%35 = load i32*, i32** %7
%36 = load i32*, i32** %3
%37 = load i32, i32* %8
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds i32, i32* %36, i64 %38
%40 = load i32, i32* %39
%41 = call i32 @fprintf(i32* %35, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %40)
br label %42
42: ; preds = %34
%43 = load i32, i32* %8
%44 = add nsw i32 %43, 1
store i32 %44, i32* %8
br label %31
45: ; preds = %31
%46 = load i32*, i32** %7
%47 = call i32 @fclose(i32* %46)
ret void
}

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