#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 */
int /*<<< orphan*/ EINTR;
int WEXITSTATUS(int);
int /*<<< orphan*/ WIFEXITED(int);
int /*<<< orphan*/ errno;
int execlp(char *, char *, char *, char *, char *, char *, char *, char *,
           int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int waitpid(int, int *, int /*<<< orphan*/);
int create_ubuntu(void) {
  int status, ret;
  pid_t pid = fork();
  if (pid < 0) {
    perror("fork");
    return -1;
  }
  if (pid == 0) {
    ret = execlp("lxc-create", "lxc-create", "-t", "ubuntu", "-f",
                 "/etc/lxc/default.conf", "-n", "lxctest1", NULL);
    perror("execl");
    exit(1);
  }
again:
  ret = waitpid(pid, &status, 0);
  if (ret == -1) {
    if (errno == -EINTR)
      goto again;
    perror("waitpid");
    return -1;
  }
  if (ret != pid)
    goto again;
  if (!WIFEXITED(status)) {
    fprintf(stderr, "%d: lxc-create exited abnormally\n", 57);
    return -1;
  }
  return WEXITSTATUS(status);
}


x86 assembly (clang, -O0):
<create_ubuntu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11b4 <create_ubuntu+0x34>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d0 <create_ubuntu+0x150>
cmpl   $0x0,-0x10(%rbp)
jne    1224 <create_ubuntu+0xa4>
lea    0xe40(%rip),%rsi
lea    0xe44(%rip),%rdx
lea    0xe40(%rip),%rcx
lea    0xe40(%rip),%r8
lea    0xe3c(%rip),%r9
lea    0xe4b(%rip),%r10
lea    0xe47(%rip),%rax
xor    %edi,%edi
mov    %rsi,%rdi
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
call   1090 <execlp@plt>
mov    %eax,-0xc(%rbp)
lea    0xe2a(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1229 <create_ubuntu+0xa9>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    127d <create_ubuntu+0xfd>
mov    0x2d8d(%rip),%rax
mov    (%rax),%eax
xor    %ecx,%ecx
mov    0x2d7a(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jne    1265 <create_ubuntu+0xe5>
jmp    1229 <create_ubuntu+0xa9>
lea    0xdd9(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d0 <create_ubuntu+0x150>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     128e <create_ubuntu+0x10e>
jmp    1229 <create_ubuntu+0xa9>
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    12c5 <create_ubuntu+0x145>
mov    0x2d3a(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
mov    $0x39,%edx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d0 <create_ubuntu+0x150>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_ubuntu>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
js     1202 <create_ubuntu+0x82>
je     1228 <create_ubuntu+0xa8>
mov    %eax,%ebx
lea    0x4(%rsp),%r14
mov    0x2e31(%rip),%r15
mov    0x2e22(%rip),%r12
jmp    11b9 <create_ubuntu+0x39>
mov    (%r15),%eax
add    (%r12),%eax
jne    120b <create_ubuntu+0x8b>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
je     11b0 <create_ubuntu+0x30>
cmp    %ebx,%eax
jne    11b9 <create_ubuntu+0x39>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %eax,%eax
je     11e6 <create_ubuntu+0x66>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
jmp    121c <create_ubuntu+0x9c>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe57(%rip),%rsi
mov    $0x39,%edx
call   1030 <fprintf@plt>
jmp    1217 <create_ubuntu+0x97>
lea    0xdf7(%rip),%rdi
jmp    1212 <create_ubuntu+0x92>
lea    0xe33(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
sub    $0x8,%rsp
lea    0xe03(%rip),%rax
lea    0xdf9(%rip),%rbx
lea    0xdc4(%rip),%rdi
lea    0xdc8(%rip),%rdx
lea    0xdc4(%rip),%rcx
lea    0xdc4(%rip),%r8
lea    0xdc0(%rip),%r9
mov    %rdi,%rsi
push   $0x0
push   %rax
push   %rbx
call   1090 <execlp@plt>
add    $0x20,%rsp
lea    0xdcb(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [11 x i8] c"lxc-create\00"
@.str.2 = [3 x i8] c"-t\00"
@.str.3 = [7 x i8] c"ubuntu\00"
@.str.4 = [3 x i8] c"-f\00"
@.str.5 = [22 x i8] c"/etc/lxc/default.conf\00"
@.str.6 = [3 x i8] c"-n\00"
@.str.7 = [9 x i8] c"lxctest1\00"
@.str.8 = [6 x i8] c"execl\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.9 = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.10 = [34 x i8] c"%d: lxc-create exited abnormally\0A\00"
define i32 @create_ubuntu() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = call i32 (...) @fork()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
10: ; preds = %0
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %10
%14 = call i32 @execlp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32* null)
store i32 %14, i32* %3
%15 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %10
br label %18
18: ; preds = %35, %28, %17
%19 = load i32, i32* %4
%20 = call i32 @waitpid(i32 %19, i32* %2, i32 0)
store i32 %20, i32* %3
%21 = load i32, i32* %3
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %31
23: ; preds = %18
%24 = load i32, i32* @errno
%25 = load i32, i32* @EINTR
%26 = sub nsw i32 0, %25
%27 = icmp eq i32 %24, %26
br i1 %27, label %28, label %29
28: ; preds = %23
br label %18
29: ; preds = %23
%30 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
store i32 -1, i32* %1
br label %46
31: ; preds = %18
%32 = load i32, i32* %3
%33 = load i32, i32* %4
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %36
35: ; preds = %31
br label %18
36: ; preds = %31
%37 = load i32, i32* %2
%38 = call i32 @WIFEXITED(i32 %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 57)
store i32 -1, i32* %1
br label %46
43: ; preds = %36
%44 = load i32, i32* %2
%45 = call i32 @WEXITSTATUS(i32 %44)
store i32 %45, i32* %1
br label %46
46: ; preds = %43, %40, %29, %8
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [11 x i8] c"lxc-create\00"
@.str.2 = [3 x i8] c"-t\00"
@.str.3 = [7 x i8] c"ubuntu\00"
@.str.4 = [3 x i8] c"-f\00"
@.str.5 = [22 x i8] c"/etc/lxc/default.conf\00"
@.str.6 = [3 x i8] c"-n\00"
@.str.7 = [9 x i8] c"lxctest1\00"
@.str.8 = [6 x i8] c"execl\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.9 = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.10 = [34 x i8] c"%d: lxc-create exited abnormally\0A\00"
define i32 @create_ubuntu() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32 (...) @fork()
%4 = icmp slt i32 %3, 0
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %36
7: ; preds = %0
%8 = icmp eq i32 %3, 0
br i1 %8, label %9, label %13
9: ; preds = %7
%10 = tail call i32 @execlp(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32* null)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.8, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %7, %21
%14 = call i32 @waitpid(i32 %3, i32* %1, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %24
16: ; preds = %13
%17 = load i32, i32* @errno
%18 = load i32, i32* @EINTR
%19 = sub nsw i32 0, %18
%20 = icmp eq i32 %17, %19
br i1 %20, label %21, label %22
21: ; preds = %16, %24
br label %13
22: ; preds = %16
%23 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0))
br label %36
24: ; preds = %13
%25 = icmp eq i32 %14, %3
br i1 %25, label %26, label %21
26: ; preds = %24
%27 = load i32, i32* %1
%28 = call i32 @WIFEXITED(i32 %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* @stderr
%32 = call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.10, i64 0, i64 0), i32 57)
br label %36
33: ; preds = %26
%34 = load i32, i32* %1
%35 = call i32 @WEXITSTATUS(i32 %34)
br label %36
36: ; preds = %33, %30, %22, %5
%37 = phi i32 [ -1, %5 ], [ -1, %22 ], [ %35, %33 ], [ -1, %30 ]
ret i32 %37
}