#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 pid_t;

/* Variables and functions */
scalar_t__ EINTR;
int /*<<< orphan*/ __NR_gettid;
int chdir(char *);
scalar_t__ errno;
int execv(char *, char **);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ syscall(int /*<<< orphan*/);
int waitpid(int, int *, int /*<<< orphan*/);
int init_compile(int what_todo, char *base_dir, char *hname) {
  int status;
  pid_t pid;
  char *dirname;
  char *command;
  if ((dirname = malloc(sizeof(char) * 2048)) == NULL) {
    perror("init_compile(): dirname malloc()");
    return 1;
  }
  if ((command = malloc(sizeof(char) * 1024)) == NULL) {
    perror("init_compile(): dirname malloc()");
    return 1;
  }
  what_todo ? sprintf(command, "make -s") : sprintf(command, "make -s clean");
  sprintf(dirname, "%s/%s.%ld", base_dir, hname, syscall(__NR_gettid));
  if (chdir(dirname) == -1) {

    ;
    perror("init_compile() chdir()");
    free(dirname);
    return 1;
  };
  if ((pid = fork()) == -1) {
    perror("init_compile(): fork()");
    return 1;
  }
  if (!pid) {
    char *argv[4];
    argv[0] = "/bin/sh";
    argv[1] = "-c";
    argv[2] = command;
    argv[3] = 0;
    if (execv("/bin/sh", argv) == -1) {
      perror("init_compile(): execv()");
      return 1;
    }
  }
  do {
    if (waitpid(pid, &status, 0) == -1) {
      if (errno != EINTR) {
        fprintf(stderr, "init_compile(): waitpid() failed\n");
        return 1;
      }
    } else {
      if (chdir(base_dir) == -1) {

        ;
        perror("init_compile(): chdir()");
        return 1;
      };
      ;
      return status;
    }
  } while (1);
}


x86 assembly (clang, -O0):
<init_compile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0x800,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11e3 <init_compile+0x43>
lea    0xe2e(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    1213 <init_compile+0x73>
lea    0xdfe(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
cmpl   $0x0,-0x8(%rbp)
je     1234 <init_compile+0x94>
mov    -0x30(%rbp),%rdi
lea    0xdf9(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
jmp    1246 <init_compile+0xa6>
mov    -0x30(%rbp),%rdi
lea    0xdea(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1060 <syscall@plt>
mov    -0x68(%rbp),%rdi
mov    -0x60(%rbp),%rdx
mov    -0x58(%rbp),%rcx
mov    %eax,%r8d
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   10a0 <sprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    12bc <init_compile+0x11c>
lea    0xd9f(%rip),%rdi
call   1090 <perror@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
mov    $0x0,%al
call   10c0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmp    $0xffffffff,%eax
jne    12e7 <init_compile+0x147>
lea    0xd82(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
cmpl   $0x0,-0x20(%rbp)
jne    134d <init_compile+0x1ad>
lea    0xd77(%rip),%rax
mov    %rax,-0x50(%rbp)
lea    0xd74(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x40(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x50(%rbp),%rsi
lea    0xd4d(%rip),%rdi
call   10b0 <execv@plt>
cmp    $0xffffffff,%eax
jne    1348 <init_compile+0x1a8>
lea    0xd43(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
jmp    134d <init_compile+0x1ad>
jmp    1352 <init_compile+0x1b2>
mov    -0x20(%rbp),%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    13a9 <init_compile+0x209>
mov    0x2c60(%rip),%rax
mov    (%rax),%rax
mov    0x2c4e(%rip),%rcx
cmp    (%rcx),%rax
je     13a4 <init_compile+0x204>
mov    0x2c4e(%rip),%rax
mov    (%rax),%edi
lea    0xcff(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
jmp    13de <init_compile+0x23e>
mov    -0x10(%rbp),%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
jne    13d3 <init_compile+0x233>
lea    0xcf2(%rip),%rdi
call   1090 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    13f2 <init_compile+0x252>
jmp    13e3 <init_compile+0x243>
mov    $0x1,%al
test   $0x1,%al
jne    1352 <init_compile+0x1b2>
jmp    13f2 <init_compile+0x252>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<init_compile>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r12
mov    %rsi,%r14
mov    %edi,%ebp
mov    $0x800,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12f4 <init_compile+0x154>
mov    %rax,%rbx
mov    $0x400,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     12f4 <init_compile+0x154>
mov    %rax,%r15
test   %ebp,%ebp
je     11f0 <init_compile+0x50>
movabs $0x732d20656b616d,%rax
jmp    1208 <init_compile+0x68>
movabs $0x6e61656c632073,%rax
mov    %rax,0x6(%r15)
movabs $0x20732d20656b616d,%rax
2d 73 20
mov    %rax,(%r15)
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
call   1060 <syscall@plt>
lea    0xe0f(%rip),%rsi
mov    %rbx,%rdi
mov    %r14,%rdx
mov    %r12,%rcx
mov    %eax,%r8d
xor    %eax,%eax
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1302 <init_compile+0x162>
xor    %eax,%eax
call   10c0 <fork@plt>
mov    %eax,%ebx
test   %eax,%eax
je     1262 <init_compile+0xc2>
cmp    $0xffffffff,%ebx
jne    1298 <init_compile+0xf8>
lea    0xdf3(%rip),%rdi
jmp    12fb <init_compile+0x15b>
lea    0xdfe(%rip),%rdi
mov    %rdi,(%rsp)
lea    0xdfb(%rip),%rax
mov    %rax,0x8(%rsp)
mov    %r15,0x10(%rsp)
movq   $0x0,0x18(%rsp)
mov    %rsp,%rsi
call   10b0 <execv@plt>
cmp    $0xffffffff,%eax
je     1328 <init_compile+0x188>
mov    %rsp,%r15
mov    0x2d2e(%rip),%r12
mov    0x2d1f(%rip),%rbp
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r15,%rsi
xor    %edx,%edx
call   1080 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    12e2 <init_compile+0x142>
mov    (%r12),%rax
cmp    0x0(%rbp),%rax
je     12b0 <init_compile+0x110>
mov    0x2d06(%rip),%rax
mov    (%rax),%edi
lea    0xdaf(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1316 <init_compile+0x176>
mov    %r14,%rdi
call   1040 <chdir@plt>
cmp    $0xffffffff,%eax
je     1331 <init_compile+0x191>
mov    (%rsp),%eax
jmp    131b <init_compile+0x17b>
lea    0xd05(%rip),%rdi
call   1090 <perror@plt>
jmp    1316 <init_compile+0x176>
lea    0xd30(%rip),%rdi
call   1090 <perror@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd43(%rip),%rdi
jmp    12fb <init_compile+0x15b>
lea    0xd74(%rip),%rdi
jmp    12fb <init_compile+0x15b>

LLVM IR (-O0):
@.str = [33 x i8] c"init_compile(): dirname malloc()\00"
@.str.1 = [8 x i8] c"make -s\00"
@.str.2 = [14 x i8] c"make -s clean\00"
@.str.3 = [10 x i8] c"%s/%s.%ld\00"
@__NR_gettid = global i32 0
@.str.4 = [23 x i8] c"init_compile() chdir()\00"
@.str.5 = [23 x i8] c"init_compile(): fork()\00"
@.str.6 = [8 x i8] c"/bin/sh\00"
@.str.7 = [3 x i8] c"-c\00"
@.str.8 = [24 x i8] c"init_compile(): execv()\00"
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str.9 = [34 x i8] c"init_compile(): waitpid() failed\0A\00"
@.str.10 = [24 x i8] c"init_compile(): chdir()\00"
define i32 @init_compile(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca [4 x i8*]
store i32 %0, i32* %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%13 = call i8* @malloc(i32 2048)
store i8* %13, i8** %10
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %3
%16 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %89
17: ; preds = %3
%18 = call i8* @malloc(i32 1024)
store i8* %18, i8** %11
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
store i32 1, i32* %4
br label %89
22: ; preds = %17
%23 = load i32, i32* %5
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %22
%26 = load i8*, i8** %11
%27 = call i32 (i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %31
28: ; preds = %22
%29 = load i8*, i8** %11
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %31
31: ; preds = %28, %25
%32 = phi i32 [ %27, %25 ], [ %30, %28 ]
%33 = load i8*, i8** %10
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = load i32, i32* @__NR_gettid
%37 = call i32 @syscall(i32 %36)
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %33, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %35, i32 %37)
%39 = load i8*, i8** %10
%40 = call i32 @chdir(i8* %39)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %46
42: ; preds = %31
%43 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%44 = load i8*, i8** %10
%45 = call i32 @free(i8* %44)
store i32 1, i32* %4
br label %89
46: ; preds = %31
%47 = call i32 (...) @fork()
store i32 %47, i32* %9
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %51
49: ; preds = %46
%50 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
store i32 1, i32* %4
br label %89
51: ; preds = %46
%52 = load i32, i32* %9
%53 = icmp ne i32 %52, 0
br i1 %53, label %66, label %54
54: ; preds = %51
%55 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %55
%56 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %56
%57 = load i8*, i8** %11
%58 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 2
store i8* %57, i8** %58
%59 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 3
store i8* null, i8** %59
%60 = getelementptr inbounds [4 x i8*], [4 x i8*]* %12, i64 0, i64 0
%61 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %60)
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %65
63: ; preds = %54
%64 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
store i32 1, i32* %4
br label %89
65: ; preds = %54
br label %66
66: ; preds = %65, %51
br label %67
67: ; preds = %88, %66
%68 = load i32, i32* %9
%69 = call i32 @waitpid(i32 %68, i32* %8, i32 0)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %79
71: ; preds = %67
%72 = load i64, i64* @errno
%73 = load i64, i64* @EINTR
%74 = icmp ne i64 %72, %73
br i1 %74, label %75, label %78
75: ; preds = %71
%76 = load i32, i32* @stderr
%77 = call i32 @fprintf(i32 %76, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
store i32 1, i32* %4
br label %89
78: ; preds = %71
br label %87
79: ; preds = %67
%80 = load i8*, i8** %6
%81 = call i32 @chdir(i8* %80)
%82 = icmp eq i32 %81, -1
br i1 %82, label %83, label %85
83: ; preds = %79
%84 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
store i32 1, i32* %4
br label %89
85: ; preds = %79
%86 = load i32, i32* %8
store i32 %86, i32* %4
br label %89
87: ; preds = %78
br label %88
88: ; preds = %87
br i1 true, label %67, label %89
89: ; preds = %15, %20, %42, %49, %63, %75, %83, %85, %88
%90 = load i32, i32* %4
ret i32 %90
}

LLVM IR (-O2):
@.str = [33 x i8] c"init_compile(): dirname malloc()\00"
@.str.2 = [14 x i8] c"make -s clean\00"
@.str.3 = [10 x i8] c"%s/%s.%ld\00"
@__NR_gettid = global i32 0
@.str.4 = [23 x i8] c"init_compile() chdir()\00"
@.str.5 = [23 x i8] c"init_compile(): fork()\00"
@.str.6 = [8 x i8] c"/bin/sh\00"
@.str.7 = [3 x i8] c"-c\00"
@.str.8 = [24 x i8] c"init_compile(): execv()\00"
@errno = global i64 0
@EINTR = global i64 0
@stderr = global i32 0
@.str.9 = [34 x i8] c"init_compile(): waitpid() failed\0A\00"
@.str.10 = [24 x i8] c"init_compile(): chdir()\00"
define i32 @init_compile(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca [4 x i8*]
%6 = bitcast i32* %4 to i8*
%7 = tail call dereferenceable_or_null(2048) i8* @malloc(i32 2048)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %63
11: ; preds = %3
%12 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @perror(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
br label %63
16: ; preds = %11
%17 = icmp eq i32 %0, 0
br i1 %17, label %20, label %18
18: ; preds = %16
%19 = bitcast i8* %12 to i64*
store i64 32419239485464941, i64* %19
br label %21
20: ; preds = %16
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(14) %12, i8* align 1 dereferenceable(14) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i64 14, i1 false)
br label %21
21: ; preds = %20, %18
%22 = load i32, i32* @__NR_gettid
%23 = tail call i32 @syscall(i32 %22)
%24 = tail call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %2, i32 %23)
%25 = tail call i32 @chdir(i8* %7)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %21
%28 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%29 = tail call i32 @free(i8* %7)
br label %63
30: ; preds = %21
%31 = tail call i32 (...) @fork()
switch i32 %31, label %45 [
i32 -1, label %32
i32 0, label %34
]
32: ; preds = %30
%33 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
br label %63
34: ; preds = %30
%35 = bitcast [4 x i8*]* %5 to i8*
%36 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 0
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %36
%37 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 1
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8** %37
%38 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 2
store i8* %12, i8** %38
%39 = getelementptr inbounds [4 x i8*], [4 x i8*]* %5, i64 0, i64 3
store i8* null, i8** %39
%40 = call i32 @execv(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0), i8** %36)
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %44
42: ; preds = %34
%43 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
br label %63
44: ; preds = %34
br label %45
45: ; preds = %44, %30
br label %46
46: ; preds = %45, %49
%47 = call i32 @waitpid(i32 %31, i32* %4, i32 0)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %56
49: ; preds = %46
%50 = load i64, i64* @errno
%51 = load i64, i64* @EINTR
%52 = icmp eq i64 %50, %51
br i1 %52, label %46, label %53
53: ; preds = %49
%54 = load i32, i32* @stderr
%55 = call i32 @fprintf(i32 %54, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0))
br label %63
56: ; preds = %46
%57 = call i32 @chdir(i8* %1)
%58 = icmp eq i32 %57, -1
br i1 %58, label %59, label %61
59: ; preds = %56
%60 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.10, i64 0, i64 0))
br label %63
61: ; preds = %56
%62 = load i32, i32* %4
br label %63
63: ; preds = %42, %61, %59, %53, %32, %27, %14, %9
%64 = phi i32 [ 1, %9 ], [ 1, %14 ], [ 1, %27 ], [ 1, %32 ], [ 1, %53 ], [ 1, %59 ], [ %62, %61 ], [ 1, %42 ]
ret i32 %64
}