#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 S_IROTH;
int S_IRWXG;
int S_IRWXU;
int S_IXOTH;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
void ptimer_init(int FEAT_TIME, const char funname[], FILE **ptfilepntr,
                 int *run_flag) {
  char fullfile[50];
  if (FEAT_TIME) {
    mkdir("/tmp/edu", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    mkdir("/tmp/edu/ptimes", S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
    sprintf(fullfile, "/tmp/edu/ptimes/pt_%s.txt", funname);
    *ptfilepntr = fopen(fullfile, "wb");
    if (*ptfilepntr == NULL) {
      printf("Error opening ptimes file! \n");
      if (run_flag != NULL) {
        *run_flag = 0;
      }
      return;
    } else {
      fclose(*ptfilepntr);
      *ptfilepntr = fopen(fullfile, "a");
    }
  }
}


x86 assembly (clang, -O0):
<ptimer_init>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     125e <ptimer_init+0x10e>
mov    0x2e70(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
mov    0x2e3e(%rip),%rax
or     (%rax),%esi
mov    0x2e4d(%rip),%rax
or     (%rax),%esi
lea    0xe64(%rip),%rdi
call   1030 <mkdir@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%esi
mov    0x2e27(%rip),%rax
or     (%rax),%esi
mov    0x2e0e(%rip),%rax
or     (%rax),%esi
mov    0x2e1d(%rip),%rax
or     (%rax),%esi
lea    0xe3d(%rip),%rdi
call   1030 <mkdir@plt>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe39(%rip),%rsi
call   1070 <sprintf@plt>
lea    -0x60(%rbp),%rdi
lea    0xe43(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1233 <ptimer_init+0xe3>
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
cmpq   $0x0,-0x20(%rbp)
je     122e <ptimer_init+0xde>
mov    -0x20(%rbp),%rax
movl   $0x0,(%rax)
jmp    125e <ptimer_init+0x10e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1040 <fclose@plt>
lea    -0x60(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    125e <ptimer_init+0x10e>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ptimer_init>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
test   %edi,%edi
je     1225 <ptimer_init+0xd5>
mov    %rdx,%r15
mov    %rsi,%r12
mov    %rcx,0x8(%rsp)
mov    0x2e70(%rip),%r13
mov    0x2e59(%rip),%rbx
mov    (%rbx),%esi
or     0x0(%r13),%esi
mov    0x2e3c(%rip),%rbp
or     0x0(%rbp),%esi
mov    0x2e4a(%rip),%r14
or     (%r14),%esi
lea    0xe60(%rip),%rdi
call   1030 <mkdir@plt>
mov    (%rbx),%esi
or     0x0(%r13),%esi
or     0x0(%rbp),%esi
or     (%r14),%esi
lea    0xe51(%rip),%rdi
call   1030 <mkdir@plt>
lea    0xe55(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %r12,%rdx
call   1070 <sprintf@plt>
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     1209 <ptimer_init+0xb9>
mov    %rax,%rdi
call   1050 <fclose@plt>
lea    0xe3c(%rip),%rsi
lea    0x10(%rsp),%rdi
call   1060 <fopen@plt>
mov    %rax,(%r15)
jmp    1225 <ptimer_init+0xd5>
lea    0xe28(%rip),%rdi
call   1040 <puts@plt>
mov    0x8(%rsp),%rax
test   %rax,%rax
je     1225 <ptimer_init+0xd5>
movl   $0x0,(%rax)
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"/tmp/edu\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str.1 = [16 x i8] c"/tmp/edu/ptimes\00"
@.str.2 = [26 x i8] c"/tmp/edu/ptimes/pt_%s.txt\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.4 = [29 x i8] c"Error opening ptimes file! \0A\00"
@.str.5 = [2 x i8] c"a\00"
define void @ptimer_init(i32 %0, i8* %1, i32** %2, i32* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32**
%8 = alloca i32*
%9 = alloca [50 x i8]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i32** %2, i32*** %7
store i32* %3, i32** %8
%10 = load i32, i32* %5
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %53
12: ; preds = %4
%13 = load i32, i32* @S_IRWXU
%14 = load i32, i32* @S_IRWXG
%15 = or i32 %13, %14
%16 = load i32, i32* @S_IROTH
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IXOTH
%19 = or i32 %17, %18
%20 = call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i32, i32* @S_IRWXU
%22 = load i32, i32* @S_IRWXG
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IROTH
%25 = or i32 %23, %24
%26 = load i32, i32* @S_IXOTH
%27 = or i32 %25, %26
%28 = call i32 @mkdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %27)
%29 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%30 = load i8*, i8** %6
%31 = call i32 @sprintf(i8* %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%34 = load i32**, i32*** %7
store i32* %33, i32** %34
%35 = load i32**, i32*** %7
%36 = load i32*, i32** %35
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %45
38: ; preds = %12
%39 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0))
%40 = load i32*, i32** %8
%41 = icmp ne i32* %40, null
br i1 %41, label %42, label %44
42: ; preds = %38
%43 = load i32*, i32** %8
store i32 0, i32* %43
br label %44
44: ; preds = %42, %38
br label %53
45: ; preds = %12
%46 = load i32**, i32*** %7
%47 = load i32*, i32** %46
%48 = call i32 @fclose(i32* %47)
%49 = getelementptr inbounds [50 x i8], [50 x i8]* %9, i64 0, i64 0
%50 = call i32* @fopen(i8* %49, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%51 = load i32**, i32*** %7
store i32* %50, i32** %51
br label %52
52: ; preds = %45
br label %53
53: ; preds = %44, %52, %4
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"/tmp/edu\00"
@S_IRWXU = global i32 0
@S_IRWXG = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str.1 = [16 x i8] c"/tmp/edu/ptimes\00"
@.str.2 = [26 x i8] c"/tmp/edu/ptimes/pt_%s.txt\00"
@.str.3 = [3 x i8] c"wb\00"
@.str.5 = [2 x i8] c"a\00"
@str = [28 x i8] c"Error opening ptimes file! \00"
define void @ptimer_init(i32 %0, i8* %1, i32** nocapture writeonly %2, i32* writeonly %3) {
%5 = alloca [50 x i8]
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%7 = icmp eq i32 %0, 0
br i1 %7, label %35, label %8
8: ; preds = %4
%9 = load i32, i32* @S_IRWXU
%10 = load i32, i32* @S_IRWXG
%11 = or i32 %10, %9
%12 = load i32, i32* @S_IROTH
%13 = or i32 %11, %12
%14 = load i32, i32* @S_IXOTH
%15 = or i32 %13, %14
%16 = tail call i32 @mkdir(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @S_IRWXU
%18 = load i32, i32* @S_IRWXG
%19 = or i32 %18, %17
%20 = load i32, i32* @S_IROTH
%21 = or i32 %19, %20
%22 = load i32, i32* @S_IXOTH
%23 = or i32 %21, %22
%24 = tail call i32 @mkdir(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %23)
%25 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %1)
%26 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %26, i32** %2
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %8
%29 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%30 = icmp eq i32* %3, null
br i1 %30, label %35, label %31
31: ; preds = %28
store i32 0, i32* %3
br label %35
32: ; preds = %8
%33 = tail call i32 @fclose(i32* %26)
%34 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %34, i32** %2
br label %35
35: ; preds = %4, %32, %28, %31
ret void
}