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

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
scalar_t__ WIFSTOPPED(int);
int WTERMSIG(int);
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ execl(char const *, char const *, char *, char *, char *,
                         char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int snprintf(char *, int, char *, char const *, char const *);
int /*<<< orphan*/ stderr;
int wait(int *);
int run_integrit(const char *ibin, const char *cdir, const char *cfile) {
  char cpath_buf[1024];
  int status;
  int snprintf_ret =
      snprintf(cpath_buf, sizeof(cpath_buf), "%s/%s", cdir, cfile);
  if ((snprintf_ret == -1) || (snprintf_ret > (((int)sizeof(cpath_buf)) - 1))) {
    fputs("integrit-run Error: config file path too long\n", stderr);
    exit(EXIT_FAILURE);
  }
  switch (fork()) {
  case -1:
    perror("fork");
    exit(EXIT_FAILURE);
    break;
  case 0:
    execl(ibin, ibin, "-C", cpath_buf, "-c", "-u", NULL);
    perror("execl");
    _exit(EXIT_FAILURE);
    break;
  default:
    break;
  }
  for (;;) {
    if (wait(&status) == -1) {
      perror("wait");
      exit(EXIT_FAILURE);
    }
    if (WIFEXITED(status))
      return WEXITSTATUS(status);
    else if (WIFSIGNALED(status))
      return -(WTERMSIG(status));
    else if (WIFSTOPPED(status))
      continue;
  }
  fputs("integrit-run Error: undefined child status\n", stderr);
  exit(EXIT_FAILURE);
  return 0;
}


x86 assembly (clang, -O0):
<run_integrit>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    $0x400,%esi
lea    0xdfe(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x428(%rbp)
cmpl   $0xffffffff,-0x428(%rbp)
je     122a <run_integrit+0x5a>
cmpl   $0x3ff,-0x428(%rbp)
jle    124d <run_integrit+0x7d>
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
lea    0xdcc(%rip),%rdi
call   1050 <fputs@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %eax,%eax
call   10f0 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x42c(%rbp)
sub    $0xffffffff,%eax
je     127d <run_integrit+0xad>
jmp    126a <run_integrit+0x9a>
mov    -0x42c(%rbp),%eax
test   %eax,%eax
je     1297 <run_integrit+0xc7>
jmp    12e4 <run_integrit+0x114>
lea    0xdb1(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x420(%rbp),%rcx
lea    0xd8d(%rip),%rdx
lea    0xd89(%rip),%r8
lea    0xd85(%rip),%r9
xor    %eax,%eax
movq   $0x0,(%rsp)
call   10d0 <execl@plt>
lea    0xd72(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
jmp    12e9 <run_integrit+0x119>
jmp    12ee <run_integrit+0x11e>
lea    -0x424(%rbp),%rdi
call   10e0 <wait@plt>
cmp    $0xffffffff,%eax
jne    131d <run_integrit+0x14d>
lea    0xd3f(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cc2(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    -0x424(%rbp),%edi
call   10b0 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1345 <run_integrit+0x175>
mov    -0x424(%rbp),%edi
call   1090 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
jmp    139c <run_integrit+0x1cc>
mov    -0x424(%rbp),%edi
call   1060 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     1373 <run_integrit+0x1a3>
mov    -0x424(%rbp),%edi
call   1080 <WTERMSIG@plt>
mov    %eax,%ecx
xor    %eax,%eax
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
jmp    139c <run_integrit+0x1cc>
mov    -0x424(%rbp),%edi
call   1070 <WIFSTOPPED@plt>
cmp    $0x0,%rax
je     138d <run_integrit+0x1bd>
jmp    12ee <run_integrit+0x11e>
jmp    1392 <run_integrit+0x1c2>
jmp    1397 <run_integrit+0x1c7>
jmp    12ee <run_integrit+0x11e>
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run_integrit>:
push   %rbx
sub    $0x410,%rsp
mov    %rdx,%r8
mov    %rsi,%rcx
mov    %rdi,%rbx
lea    0xe18(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x400,%esi
call   1040 <snprintf@plt>
cmp    $0xffffffff,%eax
je     12a3 <run_integrit+0xd3>
cmp    $0x400,%eax
jge    12a3 <run_integrit+0xd3>
xor    %eax,%eax
call   10f0 <fork@plt>
cmp    $0xffffffff,%eax
je     12ba <run_integrit+0xea>
test   %eax,%eax
je     12c3 <run_integrit+0xf3>
lea    0xc(%rsp),%rdi
call   10e0 <wait@plt>
cmp    $0xffffffff,%eax
je     1272 <run_integrit+0xa2>
lea    0xc(%rsp),%rbx
nopw   0x0(%rax,%rax,1)
mov    0xc(%rsp),%edi
call   10b0 <WIFEXITED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
jne    128c <run_integrit+0xbc>
call   1060 <WIFSIGNALED@plt>
mov    0xc(%rsp),%edi
test   %rax,%rax
jne    1293 <run_integrit+0xc3>
call   1070 <WIFSTOPPED@plt>
mov    %rbx,%rdi
call   10e0 <wait@plt>
cmp    $0xffffffff,%eax
jne    1240 <run_integrit+0x70>
lea    0xdd0(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2d53(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
call   1090 <WEXITSTATUS@plt>
jmp    129a <run_integrit+0xca>
call   1080 <WTERMSIG@plt>
neg    %eax
add    $0x410,%rsp
pop    %rbx
ret
mov    0x2d36(%rip),%rax
mov    (%rax),%esi
lea    0xd53(%rip),%rdi
call   1050 <fputs@plt>
jmp    127e <run_integrit+0xae>
lea    0xd74(%rip),%rdi
jmp    1279 <run_integrit+0xa9>
movq   $0x0,(%rsp)
lea    0xd68(%rip),%rdx
lea    0xd64(%rip),%r8
lea    0xd60(%rip),%r9
lea    0x10(%rsp),%rcx
mov    %rbx,%rdi
mov    %rbx,%rsi
call   10d0 <execl@plt>
lea    0xd4c(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [47 x i8] c"integrit-run Error: config file path too long\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [3 x i8] c"-C\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.5 = [3 x i8] c"-u\00"
@.str.6 = [6 x i8] c"execl\00"
@.str.7 = [5 x i8] c"wait\00"
define i32 @run_integrit(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca [1024 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%12 = load i8*, i8** %6
%13 = load i8*, i8** %7
%14 = call i32 @snprintf(i8* %11, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %13)
store i32 %14, i32* %10
%15 = load i32, i32* %10
%16 = icmp eq i32 %15, -1
br i1 %16, label %20, label %17
17: ; preds = %3
%18 = load i32, i32* %10
%19 = icmp sgt i32 %18, 1023
br i1 %19, label %20, label %25
20: ; preds = %17, %3
%21 = load i32, i32* @stderr
%22 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = load i32, i32* @EXIT_FAILURE
%24 = call i32 @exit(i32 %23)
unreachable
25: ; preds = %17
%26 = call i32 (...) @fork()
switch i32 %26, label %39 [
i32 -1, label %27
i32 0, label %31
]
27: ; preds = %25
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %25
%32 = load i8*, i8** %5
%33 = load i8*, i8** %5
%34 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%35 = call i32 @execl(i8* %32, i8* %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* null)
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @_exit(i32 %37)
unreachable
39: ; preds = %25
br label %40
40: ; preds = %39
br label %41
41: ; preds = %70, %67, %40
%42 = call i32 @wait(i32* %9)
%43 = icmp eq i32 %42, -1
br i1 %43, label %44, label %48
44: ; preds = %41
%45 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%46 = load i32, i32* @EXIT_FAILURE
%47 = call i32 @exit(i32 %46)
unreachable
48: ; preds = %41
%49 = load i32, i32* %9
%50 = call i64 @WIFEXITED(i32 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %48
%53 = load i32, i32* %9
%54 = call i32 @WEXITSTATUS(i32 %53)
store i32 %54, i32* %4
br label %71
55: ; preds = %48
%56 = load i32, i32* %9
%57 = call i64 @WIFSIGNALED(i32 %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %63
59: ; preds = %55
%60 = load i32, i32* %9
%61 = call i32 @WTERMSIG(i32 %60)
%62 = sub nsw i32 0, %61
store i32 %62, i32* %4
br label %71
63: ; preds = %55
%64 = load i32, i32* %9
%65 = call i64 @WIFSTOPPED(i32 %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %68
67: ; preds = %63
br label %41
68: ; preds = %63
br label %69
69: ; preds = %68
br label %70
70: ; preds = %69
br label %41
71: ; preds = %59, %52
%72 = load i32, i32* %4
ret i32 %72
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [47 x i8] c"integrit-run Error: config file path too long\0A\00"
@stderr = global i32 0
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"fork\00"
@.str.3 = [3 x i8] c"-C\00"
@.str.4 = [3 x i8] c"-c\00"
@.str.5 = [3 x i8] c"-u\00"
@.str.6 = [6 x i8] c"execl\00"
@.str.7 = [5 x i8] c"wait\00"
define i32 @run_integrit(i8* %0, i8* %1, i8* %2) {
%4 = alloca [1024 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
%8 = call i32 @snprintf(i8* %6, i32 1024, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %1, i8* %2)
%9 = icmp eq i32 %8, -1
%10 = icmp sgt i32 %8, 1023
%11 = or i1 %9, %10
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = call i32 @fputs(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %3
%18 = call i32 (...) @fork()
switch i32 %18, label %19 [
i32 -1, label %22
i32 0, label %26
]
19: ; preds = %17
%20 = call i32 @wait(i32* %5)
%21 = icmp eq i32 %20, -1
br i1 %21, label %31, label %35
22: ; preds = %17
%23 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %17
%27 = call i32 @execl(i8* %0, i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* null)
%28 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @_exit(i32 %29)
unreachable
31: ; preds = %49, %19
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%33 = load i32, i32* @EXIT_FAILURE
%34 = call i32 @exit(i32 %33)
unreachable
35: ; preds = %19, %49
%36 = load i32, i32* %5
%37 = call i64 @WIFEXITED(i32 %36)
%38 = icmp eq i64 %37, 0
%39 = load i32, i32* %5
br i1 %38, label %42, label %40
40: ; preds = %35
%41 = call i32 @WEXITSTATUS(i32 %39)
br label %53
42: ; preds = %35
%43 = call i64 @WIFSIGNALED(i32 %39)
%44 = icmp eq i64 %43, 0
%45 = load i32, i32* %5
br i1 %44, label %49, label %46
46: ; preds = %42
%47 = call i32 @WTERMSIG(i32 %45)
%48 = sub nsw i32 0, %47
br label %53
49: ; preds = %42
%50 = call i64 @WIFSTOPPED(i32 %45)
%51 = call i32 @wait(i32* %5)
%52 = icmp eq i32 %51, -1
br i1 %52, label %31, label %35
53: ; preds = %46, %40
%54 = phi i32 [ %41, %40 ], [ %48, %46 ]
ret i32 %54
}