#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*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ CreateFile(char const *);
int EEXIST;
int EINVAL;
int ENOENT;
int ENOTDIR;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
char *dirname(int /*<<< orphan*/);
int errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int mkdir(char const *, int);
int /*<<< orphan*/ perror(char *);
scalar_t__ stat(char const *, struct stat *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strdupa(char const *);
char *strerror(int);
int CreateTarget(const char *path, bool is_directory) {
  if (path == NULL) {
    errno = EINVAL;
    return -1;
  }
  struct stat sb;
  if (stat(path, &sb) == 0) {
    if (is_directory && S_ISDIR(sb.st_mode)) {
      return 0;
    } else if (!is_directory && S_ISREG(sb.st_mode)) {
      return 0;
    } else {
      errno = is_directory ? ENOTDIR : EEXIST;
      return -1;
    }
  } else {
    if (errno != ENOENT) {
      return -1;
    }
  }
  if ((CreateTarget(dirname(strdupa(path)), true)) == -1) {
    fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                    "outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/"
                    "heads/master/src/namespace-sandbox/namespace-sandbox.c"
                    ":"
                    "453"
                    ": ");
    perror("CreateTarget(dirname(strdupa(path)), true)");
    exit(EXIT_FAILURE);
  };
  if (is_directory) {
    if ((mkdir(path, 0755)) == -1) {
      int e = errno;
      fprintf(stderr,
              "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
              "2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/"
              "src/namespace-sandbox/namespace-sandbox.c"
              ":"
              "456"
              ": "
              "cannot create %s",
              path);
      fprintf(stderr, ": %s\n", strerror(e));
      exit(EXIT_FAILURE);
    };
  } else {
    CreateFile(path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<CreateTarget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f8 <CreateTarget+0x38>
mov    0x2dd7(%rip),%rax
mov    (%rax),%ecx
mov    0x2dde(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    13b1 <CreateTarget+0x1f1>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    129e <CreateTarget+0xde>
cmpl   $0x0,-0x14(%rbp)
je     1237 <CreateTarget+0x77>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1237 <CreateTarget+0x77>
movl   $0x0,-0x4(%rbp)
jmp    13b1 <CreateTarget+0x1f1>
cmpl   $0x0,-0x14(%rbp)
jne    125f <CreateTarget+0x9f>
mov    -0x18(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     125f <CreateTarget+0x9f>
movl   $0x0,-0x4(%rbp)
jmp    13b1 <CreateTarget+0x1f1>
cmpl   $0x0,-0x14(%rbp)
je     127a <CreateTarget+0xba>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    1286 <CreateTarget+0xc6>
mov    0x2d57(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%ecx
mov    0x2d38(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    13b1 <CreateTarget+0x1f1>
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    0x2cfa(%rip),%rcx
cmp    (%rcx),%eax
je     12c2 <CreateTarget+0x102>
movl   $0xffffffff,-0x4(%rbp)
jmp    13b1 <CreateTarget+0x1f1>
jmp    12c7 <CreateTarget+0x107>
mov    -0x10(%rbp),%rdi
call   10a0 <strdupa@plt>
mov    %eax,%edi
call   1050 <dirname@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   10b0 <CreateTarget@plt>
cmp    $0xffffffff,%eax
jne    131e <CreateTarget+0x15e>
mov    0x2cdc(%rip),%rax
mov    (%rax),%edi
lea    0xd03(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
lea    0xda2(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ca9(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     13a1 <CreateTarget+0x1e1>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    139c <CreateTarget+0x1dc>
mov    0x2c82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2c7e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd79(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x1c(%rbp),%edi
call   10e0 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe0e(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    0x2c2b(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    13aa <CreateTarget+0x1ea>
mov    -0x10(%rbp),%rdi
call   1080 <CreateFile@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateTarget>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
test   %rdi,%rdi
je     128e <CreateTarget+0xce>
mov    %esi,%ebp
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     12a7 <CreateTarget+0xe7>
mov    0x2dd8(%rip),%r14
mov    (%r14),%ecx
mov    0x2dae(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%ecx
jne    12dc <CreateTarget+0x11c>
mov    %rbx,%rdi
call   10a0 <strdupa@plt>
mov    %eax,%edi
call   1050 <dirname@plt>
mov    %rax,%rdi
mov    $0x1,%esi
call   10b0 <CreateTarget@plt>
cmp    $0xffffffff,%eax
je     12ee <CreateTarget+0x12e>
test   %ebp,%ebp
je     12d2 <CreateTarget+0x112>
mov    %rbx,%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    12dc <CreateTarget+0x11c>
mov    (%r14),%ebp
mov    0x2d78(%rip),%r14
mov    (%r14),%edi
lea    0xe76(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    (%r14),%ebx
mov    %ebp,%edi
call   10e0 <strerror@plt>
lea    0xf18(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    1311 <CreateTarget+0x151>
mov    0x2d23(%rip),%rax
mov    (%rax),%eax
mov    0x2d2a(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%eax
jmp    12dc <CreateTarget+0x11c>
mov    0x8(%rsp),%edi
test   %ebp,%ebp
je     12b6 <CreateTarget+0xf6>
call   1040 <S_ISDIR@plt>
jmp    12bb <CreateTarget+0xfb>
call   1090 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    12dc <CreateTarget+0x11c>
test   %ebp,%ebp
jne    12e5 <CreateTarget+0x125>
mov    0x2d08(%rip),%rax
jmp    1295 <CreateTarget+0xd5>
mov    %rbx,%rdi
call   1080 <CreateFile@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2d0c(%rip),%rax
jmp    1295 <CreateTarget+0xd5>
mov    0x2cdb(%rip),%rax
mov    (%rax),%edi
lea    0xd02(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0xda1(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2ca8(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@ENOTDIR = global i32 0
@EEXIST = global i32 0
@ENOENT = global i32 0
@stderr = global i32 0
@.str = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:453: \00"
@.str.1 = [43 x i8] c"CreateTarget(dirname(strdupa(path)), true)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [189 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:456: cannot create %s\00"
@.str.3 = [6 x i8] c": %s\0A\00"
define i32 @CreateTarget(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.stat
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = load i32, i32* @EINVAL
store i32 %11, i32* @errno
store i32 -1, i32* %3
br label %84
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i64 @stat(i8* %13, %struct.stat* %6)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %43
16: ; preds = %12
%17 = load i32, i32* %5
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%21 = load i32, i32* %20
%22 = call i64 @S_ISDIR(i32 %21)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19
store i32 0, i32* %3
br label %84
25: ; preds = %19, %16
%26 = load i32, i32* %5
%27 = icmp ne i32 %26, 0
br i1 %27, label %34, label %28
28: ; preds = %25
%29 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i64 @S_ISREG(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %28
store i32 0, i32* %3
br label %84
34: ; preds = %28, %25
%35 = load i32, i32* %5
%36 = icmp ne i32 %35, 0
br i1 %36, label %37, label %39
37: ; preds = %34
%38 = load i32, i32* @ENOTDIR
br label %41
39: ; preds = %34
%40 = load i32, i32* @EEXIST
br label %41
41: ; preds = %39, %37
%42 = phi i32 [ %38, %37 ], [ %40, %39 ]
store i32 %42, i32* @errno
store i32 -1, i32* %3
br label %84
43: ; preds = %12
%44 = load i32, i32* @errno
%45 = load i32, i32* @ENOENT
%46 = icmp ne i32 %44, %45
br i1 %46, label %47, label %48
47: ; preds = %43
store i32 -1, i32* %3
br label %84
48: ; preds = %43
br label %49
49: ; preds = %48
%50 = load i8*, i8** %4
%51 = call i32 @strdupa(i8* %50)
%52 = call i8* @dirname(i32 %51)
%53 = call i32 @CreateTarget(i8* %52, i32 1)
%54 = icmp eq i32 %53, -1
br i1 %54, label %55, label %61
55: ; preds = %49
%56 = load i32, i32* @stderr
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %56, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0))
%58 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%59 = load i32, i32* @EXIT_FAILURE
%60 = call i32 @exit(i32 %59)
unreachable
61: ; preds = %49
%62 = load i32, i32* %5
%63 = icmp ne i32 %62, 0
br i1 %63, label %64, label %80
64: ; preds = %61
%65 = load i8*, i8** %4
%66 = call i32 @mkdir(i8* %65, i32 493)
%67 = icmp eq i32 %66, -1
br i1 %67, label %68, label %79
68: ; preds = %64
%69 = load i32, i32* @errno
store i32 %69, i32* %7
%70 = load i32, i32* @stderr
%71 = load i8*, i8** %4
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([189 x i8], [189 x i8]* @.str.2, i64 0, i64 0), i8* %71)
%73 = load i32, i32* @stderr
%74 = load i32, i32* %7
%75 = call i8* @strerror(i32 %74)
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %75)
%77 = load i32, i32* @EXIT_FAILURE
%78 = call i32 @exit(i32 %77)
unreachable
79: ; preds = %64
br label %83
80: ; preds = %61
%81 = load i8*, i8** %4
%82 = call i32 @CreateFile(i8* %81)
br label %83
83: ; preds = %80, %79
store i32 0, i32* %3
br label %84
84: ; preds = %83, %47, %41, %33, %24, %10
%85 = load i32, i32* %3
ret i32 %85
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@EINVAL = global i32 0
@errno = global i32 0
@ENOTDIR = global i32 0
@EEXIST = global i32 0
@ENOENT = global i32 0
@stderr = global i32 0
@.str = [173 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:453: \00"
@.str.1 = [43 x i8] c"CreateTarget(dirname(strdupa(path)), true)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [189 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/BobBuildTool/bob/refs/heads/master/src/namespace-sandbox/namespace-sandbox.c:456: cannot create %s\00"
@.str.3 = [6 x i8] c": %s\0A\00"
define i32 @CreateTarget(i8* %0, i32 %1) {
%3 = alloca %struct.stat
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = load i32, i32* @EINVAL
store i32 %6, i32* @errno
br label %58
7: ; preds = %2
%8 = bitcast %struct.stat* %3 to i8*
%9 = call i64 @stat(i8* %0, %struct.stat* %3)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %25
11: ; preds = %7
%12 = icmp eq i32 %1, 0
%13 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%14 = load i32, i32* %13
br i1 %12, label %18, label %15
15: ; preds = %11
%16 = call i64 @S_ISDIR(i32 %14)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %56
18: ; preds = %11
%19 = call i64 @S_ISREG(i32 %14)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %56
21: ; preds = %15, %18
%22 = load i32, i32* @ENOTDIR
%23 = load i32, i32* @EEXIST
%24 = select i1 %12, i32 %23, i32 %22
store i32 %24, i32* @errno
br label %56
25: ; preds = %7
%26 = load i32, i32* @errno
%27 = load i32, i32* @ENOENT
%28 = icmp eq i32 %26, %27
br i1 %28, label %29, label %56
29: ; preds = %25
%30 = call i32 @strdupa(i8* %0)
%31 = call i8* @dirname(i32 %30)
%32 = call i32 @CreateTarget(i8* %31, i32 1)
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i32, i32* @stderr
%36 = call i32 (i32, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([173 x i8], [173 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @perror(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %29
%41 = icmp eq i32 %1, 0
br i1 %41, label %54, label %42
42: ; preds = %40
%43 = call i32 @mkdir(i8* %0, i32 493)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i32, i32* @errno
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([189 x i8], [189 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%49 = load i32, i32* @stderr
%50 = call i8* @strerror(i32 %46)
%51 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = load i32, i32* @EXIT_FAILURE
%53 = call i32 @exit(i32 %52)
unreachable
54: ; preds = %40
%55 = call i32 @CreateFile(i8* %0)
br label %56
56: ; preds = %54, %42, %25, %18, %15, %21
%57 = phi i32 [ -1, %21 ], [ 0, %15 ], [ 0, %18 ], [ -1, %25 ], [ 0, %42 ], [ 0, %54 ]
br label %58
58: ; preds = %56, %5
%59 = phi i32 [ -1, %5 ], [ %57, %56 ]
ret i32 %59
}