#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 *, 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 destroy_ubuntu(void) {
  int status, ret;
  pid_t pid = fork();
  if (pid < 0) {
    perror("fork");
    return -1;
  }
  if (pid == 0) {
    ret = execlp("lxc-destroy", "lxc-destroy", "-f", "-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):
<destroy_ubuntu>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    11b4 <destroy_ubuntu+0x34>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <destroy_ubuntu+0x12c>
cmpl   $0x0,-0x10(%rbp)
jne    1200 <destroy_ubuntu+0x80>
lea    0xe40(%rip),%rsi
lea    0xe45(%rip),%rdx
lea    0xe41(%rip),%rcx
lea    0xe3d(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    %rsi,%rdi
call   1090 <execlp@plt>
mov    %eax,-0xc(%rbp)
lea    0xe2f(%rip),%rdi
call   1060 <perror@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
jmp    1205 <destroy_ubuntu+0x85>
mov    -0x10(%rbp),%edi
lea    -0x8(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1259 <destroy_ubuntu+0xd9>
mov    0x2db1(%rip),%rax
mov    (%rax),%eax
xor    %ecx,%ecx
mov    0x2d9e(%rip),%rdx
sub    (%rdx),%ecx
cmp    %ecx,%eax
jne    1241 <destroy_ubuntu+0xc1>
jmp    1205 <destroy_ubuntu+0x85>
lea    0xdde(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <destroy_ubuntu+0x12c>
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
je     126a <destroy_ubuntu+0xea>
jmp    1205 <destroy_ubuntu+0x85>
mov    -0x8(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%eax
jne    12a1 <destroy_ubuntu+0x121>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
lea    0xda3(%rip),%rsi
mov    $0x39,%edx
call   1030 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <destroy_ubuntu+0x12c>
mov    -0x8(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<destroy_ubuntu>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
js     1202 <destroy_ubuntu+0x82>
je     1228 <destroy_ubuntu+0xa8>
mov    %eax,%ebx
lea    0x4(%rsp),%r14
mov    0x2e31(%rip),%r15
mov    0x2e22(%rip),%r12
jmp    11b9 <destroy_ubuntu+0x39>
mov    (%r15),%eax
add    (%r12),%eax
jne    120b <destroy_ubuntu+0x8b>
mov    %ebx,%edi
mov    %r14,%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
je     11b0 <destroy_ubuntu+0x30>
cmp    %ebx,%eax
jne    11b9 <destroy_ubuntu+0x39>
mov    0x4(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %eax,%eax
je     11e6 <destroy_ubuntu+0x66>
mov    0x4(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
jmp    121c <destroy_ubuntu+0x9c>
mov    0x2df3(%rip),%rax
mov    (%rax),%edi
lea    0xe38(%rip),%rsi
mov    $0x39,%edx
call   1030 <fprintf@plt>
jmp    1217 <destroy_ubuntu+0x97>
lea    0xdf7(%rip),%rdi
jmp    1212 <destroy_ubuntu+0x92>
lea    0xe14(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
lea    0xdd6(%rip),%rdi
lea    0xddb(%rip),%rdx
lea    0xdd7(%rip),%rcx
lea    0xdd3(%rip),%r8
mov    %rdi,%rsi
xor    %r9d,%r9d
call   1090 <execlp@plt>
lea    0xdca(%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 = [12 x i8] c"lxc-destroy\00"
@.str.2 = [3 x i8] c"-f\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [9 x i8] c"lxctest1\00"
@.str.5 = [6 x i8] c"execl\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.6 = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.7 = [34 x i8] c"%d: lxc-create exited abnormally\0A\00"
define i32 @destroy_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 ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 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 ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, 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.5, 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.6, 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.7, 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 = [12 x i8] c"lxc-destroy\00"
@.str.2 = [3 x i8] c"-f\00"
@.str.3 = [3 x i8] c"-n\00"
@.str.4 = [9 x i8] c"lxctest1\00"
@.str.5 = [6 x i8] c"execl\00"
@errno = global i32 0
@EINTR = global i32 0
@.str.6 = [8 x i8] c"waitpid\00"
@stderr = global i32 0
@.str.7 = [34 x i8] c"%d: lxc-create exited abnormally\0A\00"
define i32 @destroy_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 ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 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 ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0), i32* null)
%11 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, 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.6, 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.7, 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
}