#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 */

/* Variables and functions */
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ strcmp(char *, char *);
int /*<<< orphan*/ w2h_file_exist(char *);
int w2h_file_open(char *);
char *w2h_get_dir(char *);
scalar_t__ w2h_make_dir(char *);
int prepare_file(char *file) {
  if (!(strcmp(file, "stdout")) || !(strcmp(file, "stderr"))) {
    return 1;
  }
  if (!(w2h_file_exist(file))) {
    char *dir;
    dir = w2h_get_dir(file);
    if (!(w2h_file_exist(dir))) {
      if ((w2h_make_dir(dir)))
        return -1;
    }
    free(dir);
  }
  return w2h_file_open(file);
}


x86 assembly (clang, -O0):
<prepare_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     119e <prepare_file+0x3e>
mov    -0x10(%rbp),%rdi
lea    0xe77(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11aa <prepare_file+0x4a>
movl   $0x1,-0x4(%rbp)
jmp    1214 <prepare_file+0xb4>
mov    -0x10(%rbp),%rdi
call   1070 <w2h_file_exist@plt>
cmp    $0x0,%eax
jne    1208 <prepare_file+0xa8>
mov    -0x10(%rbp),%rdi
call   1080 <w2h_get_dir@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <w2h_file_exist@plt>
cmp    $0x0,%eax
jne    11ff <prepare_file+0x9f>
mov    -0x18(%rbp),%rdi
call   1050 <w2h_make_dir@plt>
cmp    $0x0,%rax
je     11fa <prepare_file+0x9a>
movl   $0xffffffff,-0x4(%rbp)
jmp    1214 <prepare_file+0xb4>
jmp    11ff <prepare_file+0x9f>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <w2h_file_open@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
lea    0xe92(%rip),%rsi
call   1060 <strcmp@plt>
mov    $0x1,%ebp
test   %eax,%eax
je     11c4 <prepare_file+0x64>
lea    0xe84(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     11c4 <prepare_file+0x64>
mov    %rbx,%rdi
call   1070 <w2h_file_exist@plt>
test   %eax,%eax
jne    11d3 <prepare_file+0x73>
mov    %rbx,%rdi
call   1080 <w2h_get_dir@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1070 <w2h_file_exist@plt>
test   %eax,%eax
jne    11cb <prepare_file+0x6b>
mov    %r14,%rdi
call   1050 <w2h_make_dir@plt>
mov    $0xffffffff,%ebp
test   %rax,%rax
je     11cb <prepare_file+0x6b>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1040 <w2h_file_open@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"stdout\00"
@.str.1 = [7 x i8] c"stderr\00"
define i32 @prepare_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strcmp(i8* %5, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = call i32 @strcmp(i8* %9, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp ne i32 %10, 0
br i1 %11, label %13, label %12
12: ; preds = %8, %1
store i32 1, i32* %2
br label %35
13: ; preds = %8
%14 = load i8*, i8** %3
%15 = call i32 @w2h_file_exist(i8* %14)
%16 = icmp ne i32 %15, 0
br i1 %16, label %32, label %17
17: ; preds = %13
%18 = load i8*, i8** %3
%19 = call i8* @w2h_get_dir(i8* %18)
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = call i32 @w2h_file_exist(i8* %20)
%22 = icmp ne i32 %21, 0
br i1 %22, label %29, label %23
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = call i64 @w2h_make_dir(i8* %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %23
store i32 -1, i32* %2
br label %35
28: ; preds = %23
br label %29
29: ; preds = %28, %17
%30 = load i8*, i8** %4
%31 = call i32 @free(i8* %30)
br label %32
32: ; preds = %29, %13
%33 = load i8*, i8** %3
%34 = call i32 @w2h_file_open(i8* %33)
store i32 %34, i32* %2
br label %35
35: ; preds = %32, %27, %12
%36 = load i32, i32* %2
ret i32 %36
}

LLVM IR (-O2):
@.str = [7 x i8] c"stdout\00"
@.str.1 = [7 x i8] c"stderr\00"
define i32 @prepare_file(i8* %0) {
%2 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32 %2, 0
br i1 %3, label %21, label %4
4: ; preds = %1
%5 = tail call i32 @strcmp(i8* dereferenceable(1) %0, i8* dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %21, label %7
7: ; preds = %4
%8 = tail call i32 @w2h_file_exist(i8* %0)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = tail call i8* @w2h_get_dir(i8* %0)
%12 = tail call i32 @w2h_file_exist(i8* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = tail call i64 @w2h_make_dir(i8* %11)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %10, %14
%18 = tail call i32 @free(i8* %11)
br label %19
19: ; preds = %17, %7
%20 = tail call i32 @w2h_file_open(i8* %0)
br label %21
21: ; preds = %14, %1, %4, %19
%22 = phi i32 [ %20, %19 ], [ 1, %4 ], [ 1, %1 ], [ -1, %14 ]
ret i32 %22
}