#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 /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
char *malloc(scalar_t__);
int /*<<< orphan*/ mkdir(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int openOutFile(char *inname, FILE **outfile) {
  char *name;
  char *t;
  FILE *infile;
  name = malloc(strlen(inname) + 1);
  strcpy(name, inname);
  for (t = name; *t; t++) {
    if (*t == '\\') {
      *t = '\0';
      mkdir(name, 0744);
      *t = '\\';
    }
  }
  if (!(infile = fopen(name, "rb"))) {
    *outfile = fopen(name, "wb");
    free(name);
    return 0;
  } else {
    fclose(infile);
    return 1;
  }
}


x86 assembly (clang, -O0):
<openOutFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1070 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmpb   $0x0,(%rax)
je     11fd <openOutFile+0x8d>
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x5c,%eax
jne    11e7 <openOutFile+0x77>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    $0x1e4,%esi
call   1050 <mkdir@plt>
mov    -0x28(%rbp),%rax
movb   $0x5c,(%rax)
jmp    11ec <openOutFile+0x7c>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11ae <openOutFile+0x3e>
mov    -0x20(%rbp),%rdi
lea    0xdf8(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    124a <openOutFile+0xda>
mov    -0x20(%rbp),%rdi
lea    0xddd(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    125a <openOutFile+0xea>
mov    -0x30(%rbp),%rdi
call   1060 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<openOutFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
call   1070 <strlen@plt>
lea    0x1(%rax),%rdi
call   1080 <malloc@plt>
mov    %rax,%r12
mov    %rax,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
mov    %r12,%rbx
jmp    11b7 <openOutFile+0x47>
nop
movb   $0x0,(%rbx)
mov    %r12,%rdi
mov    $0x1e4,%esi
call   1050 <mkdir@plt>
movb   $0x5c,(%rbx)
add    $0x1,%rbx
movzbl (%rbx),%eax
cmp    $0x5c,%al
je     11a0 <openOutFile+0x30>
test   %al,%al
jne    11b3 <openOutFile+0x43>
lea    0xe37(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
test   %rax,%rax
je     11e5 <openOutFile+0x75>
mov    %rax,%rdi
call   1060 <fclose@plt>
mov    $0x1,%eax
jmp    1201 <openOutFile+0x91>
lea    0xe17(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
mov    %rax,(%r14)
mov    %r12,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @openOutFile(i8* %0, i32** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32*
store i8* %0, i8** %4
store i32** %1, i32*** %5
%9 = load i8*, i8** %4
%10 = call i64 @strlen(i8* %9)
%11 = add nsw i64 %10, 1
%12 = call i8* @malloc(i64 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %13, i8* %14)
%16 = load i8*, i8** %6
store i8* %16, i8** %7
br label %17
17: ; preds = %32, %2
%18 = load i8*, i8** %7
%19 = load i8, i8* %18
%20 = icmp ne i8 %19, 0
br i1 %20, label %21, label %35
21: ; preds = %17
%22 = load i8*, i8** %7
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 92
br i1 %25, label %26, label %31
26: ; preds = %21
%27 = load i8*, i8** %7
store i8 0, i8* %27
%28 = load i8*, i8** %6
%29 = call i32 @mkdir(i8* %28, i32 484)
%30 = load i8*, i8** %7
store i8 92, i8* %30
br label %31
31: ; preds = %26, %21
br label %32
32: ; preds = %31
%33 = load i8*, i8** %7
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %7
br label %17
35: ; preds = %17
%36 = load i8*, i8** %6
%37 = call i32* @fopen(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %37, i32** %8
%38 = icmp ne i32* %37, null
br i1 %38, label %45, label %39
39: ; preds = %35
%40 = load i8*, i8** %6
%41 = call i32* @fopen(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%42 = load i32**, i32*** %5
store i32* %41, i32** %42
%43 = load i8*, i8** %6
%44 = call i32 @free(i8* %43)
store i32 0, i32* %3
br label %48
45: ; preds = %35
%46 = load i32*, i32** %8
%47 = call i32 @fclose(i32* %46)
store i32 1, i32* %3
br label %48
48: ; preds = %45, %39
%49 = load i32, i32* %3
ret i32 %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [3 x i8] c"wb\00"
define i32 @openOutFile(i8* %0, i32** nocapture writeonly %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 1
%5 = tail call i8* @malloc(i64 %4)
%6 = tail call i32 @strcpy(i8* %5, i8* %0)
br label %7
7: ; preds = %12, %2
%8 = phi i8* [ %5, %2 ], [ %13, %12 ]
%9 = load i8, i8* %8
switch i8 %9, label %12 [
i8 0, label %14
i8 92, label %10
]
10: ; preds = %7
store i8 0, i8* %8
%11 = tail call i32 @mkdir(i8* %5, i32 484)
store i8 92, i8* %8
br label %12
12: ; preds = %7, %10
%13 = getelementptr inbounds i8, i8* %8, i64 1
br label %7
14: ; preds = %7
%15 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %1
%19 = tail call i32 @free(i8* %5)
br label %22
20: ; preds = %14
%21 = tail call i32 @fclose(i32* %15)
br label %22
22: ; preds = %20, %17
%23 = phi i32 [ 1, %20 ], [ 0, %17 ]
ret i32 %23
}