#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 *);
scalar_t__ EEXIST;
scalar_t__ EINVAL;
scalar_t__ ENOENT;
scalar_t__ ENOTDIR;
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ S_ISREG(int /*<<< orphan*/);
char *dirname(int /*<<< orphan*/);
scalar_t__ 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 *);
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/Ansahmadiba/bazel/refs/"
                    "heads/master/src/main/tools/namespace-sandbox.c"
                    ":"
                    "338"
                    ": ");
    perror("CreateTarget(dirname(strdupa(path)), true)");
    exit(EXIT_FAILURE);
  };
  if (is_directory) {
    if ((mkdir(path, 0755)) == -1) {
      fprintf(stderr, "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/"
                      "outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/"
                      "refs/heads/master/src/main/tools/namespace-sandbox.c"
                      ":"
                      "341"
                      ": ");
      perror("mkdir(path, 0755)");
      exit(EXIT_FAILURE);
    };
  } else {
    CreateFile(path);
  }
  return 0;
}


x86 assembly (clang, -O0):
<CreateTarget>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ea <CreateTarget+0x3a>
mov    0x2de7(%rip),%rax
mov    (%rax),%rcx
mov    0x2ded(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    137b <CreateTarget+0x1cb>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
jne    1296 <CreateTarget+0xe6>
cmpl   $0x0,-0x14(%rbp)
je     1229 <CreateTarget+0x79>
mov    -0x18(%rbp),%edi
call   1040 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1229 <CreateTarget+0x79>
movl   $0x0,-0x4(%rbp)
jmp    137b <CreateTarget+0x1cb>
cmpl   $0x0,-0x14(%rbp)
jne    1251 <CreateTarget+0xa1>
mov    -0x18(%rbp),%edi
call   1090 <S_ISREG@plt>
cmp    $0x0,%rax
je     1251 <CreateTarget+0xa1>
movl   $0x0,-0x4(%rbp)
jmp    137b <CreateTarget+0x1cb>
cmpl   $0x0,-0x14(%rbp)
je     126e <CreateTarget+0xbe>
mov    0x2d96(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    127c <CreateTarget+0xcc>
mov    0x2d63(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rcx
mov    0x2d41(%rip),%rax
mov    %rcx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
jmp    137b <CreateTarget+0x1cb>
mov    0x2d2b(%rip),%rax
mov    (%rax),%rax
mov    0x2d01(%rip),%rcx
cmp    (%rcx),%rax
je     12bc <CreateTarget+0x10c>
movl   $0xffffffff,-0x4(%rbp)
jmp    137b <CreateTarget+0x1cb>
jmp    12c1 <CreateTarget+0x111>
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    1316 <CreateTarget+0x166>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xd09(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xda4(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cb1(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     136b <CreateTarget+0x1bb>
mov    -0x10(%rbp),%rdi
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
cmp    $0xffffffff,%eax
jne    1366 <CreateTarget+0x1b6>
mov    0x2c92(%rip),%rax
mov    (%rax),%edi
lea    0xd8b(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xe26(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
jmp    1374 <CreateTarget+0x1c4>
mov    -0x10(%rbp),%rdi
call   1080 <CreateFile@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CreateTarget>:
push   %rbp
push   %rbx
push   %rax
test   %rdi,%rdi
je     124e <CreateTarget+0x9e>
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rsi
call   1070 <stat@plt>
test   %rax,%rax
je     1269 <CreateTarget+0xb9>
mov    0x2def(%rip),%rax
mov    (%rax),%rcx
mov    0x2dc5(%rip),%rdx
mov    $0xffffffff,%eax
cmp    (%rdx),%rcx
jne    129a <CreateTarget+0xea>
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     12aa <CreateTarget+0xfa>
mov    %rbx,%rdi
test   %ebp,%ebp
je     1293 <CreateTarget+0xe3>
mov    $0x1ed,%esi
call   1030 <mkdir@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    129a <CreateTarget+0xea>
mov    0x2d99(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xf2d(%rip),%rdi
jmp    12c6 <CreateTarget+0x116>
mov    0x2d63(%rip),%rax
mov    (%rax),%rax
mov    0x2d69(%rip),%rcx
mov    %rax,(%rcx)
mov    $0xffffffff,%eax
jmp    129a <CreateTarget+0xea>
mov    (%rsp),%edi
test   %ebp,%ebp
je     1277 <CreateTarget+0xc7>
call   1040 <S_ISDIR@plt>
jmp    127c <CreateTarget+0xcc>
call   1090 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    129a <CreateTarget+0xea>
test   %ebp,%ebp
jne    12a1 <CreateTarget+0xf1>
mov    0x2d47(%rip),%rax
jmp    1255 <CreateTarget+0xa5>
call   1080 <CreateFile@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2d50(%rip),%rax
jmp    1255 <CreateTarget+0xa5>
mov    0x2d1f(%rip),%rax
mov    (%rax),%edi
lea    0xd46(%rip),%rsi
call   1060 <fprintf@plt>
lea    0xde1(%rip),%rdi
call   10c0 <perror@plt>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

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

LLVM IR (-O2):
%struct.stat = type { i32 }
@EINVAL = global i64 0
@errno = global i64 0
@ENOTDIR = global i64 0
@EEXIST = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/refs/heads/master/src/main/tools/namespace-sandbox.c:338: \00"
@.str.1 = [43 x i8] c"CreateTarget(dirname(strdupa(path)), true)\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [167 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/Ansahmadiba/bazel/refs/heads/master/src/main/tools/namespace-sandbox.c:341: \00"
@.str.3 = [18 x i8] c"mkdir(path, 0755)\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 i64, i64* @EINVAL
store i64 %6, i64* @errno
br label %55
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 %53
18: ; preds = %11
%19 = call i64 @S_ISREG(i32 %14)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %53
21: ; preds = %15, %18
%22 = load i64, i64* @ENOTDIR
%23 = load i64, i64* @EEXIST
%24 = select i1 %12, i64 %23, i64 %22
store i64 %24, i64* @errno
br label %53
25: ; preds = %7
%26 = load i64, i64* @errno
%27 = load i64, i64* @ENOENT
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %53
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 @fprintf(i32 %35, i8* getelementptr inbounds ([167 x i8], [167 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 %51, 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 %53
45: ; preds = %42
%46 = load i32, i32* @stderr
%47 = call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([167 x i8], [167 x i8]* @.str.2, i64 0, i64 0))
%48 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0))
%49 = load i32, i32* @EXIT_FAILURE
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %40
%52 = call i32 @CreateFile(i8* %0)
br label %53
53: ; preds = %51, %42, %25, %18, %15, %21
%54 = phi i32 [ -1, %21 ], [ 0, %15 ], [ 0, %18 ], [ -1, %25 ], [ 0, %42 ], [ 0, %51 ]
br label %55
55: ; preds = %53, %5
%56 = phi i32 [ -1, %5 ], [ %54, %53 ]
ret i32 %56
}