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

/* Variables and functions */
scalar_t__ WIFEXITED(int);
scalar_t__ WIFSIGNALED(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ execvp(char *, char **);
scalar_t__ fork();
int waitpid(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int execute(char **args) {
  pid_t pid;
  int status;
  pid = fork();
  if (pid == 0) {
    execvp(args[0], args);
  } else if (pid > 0) {
    while (1) {
      status = waitpid(pid, 0, WUNTRACED);
      if (WIFEXITED(status) || WIFSIGNALED(status)) {
        break;
      }
    }
  }
  return status;
}


x86 assembly (clang, -O0):
<execute>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1187 <execute+0x37>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <execvp@plt>
jmp    11e6 <execute+0x96>
cmpq   $0x0,-0x10(%rbp)
jle    11e1 <execute+0x91>
jmp    1197 <execute+0x47>
mov    -0x10(%rbp),%rdi
mov    0x2e3e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <waitpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <WIFEXITED@plt>
cmp    $0x0,%rax
jne    11d2 <execute+0x82>
mov    -0x14(%rbp),%edi
call   1030 <WIFSIGNALED@plt>
cmp    $0x0,%rax
je     11d7 <execute+0x87>
jmp    11dc <execute+0x8c>
jmp    1197 <execute+0x47>
jmp    11e1 <execute+0x91>
jmp    11e6 <execute+0x96>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<execute>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbp
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1199 <execute+0x49>
jle    11a5 <execute+0x55>
mov    %rax,%rbx
mov    0x2e71(%rip),%r14
nop
mov    (%r14),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1040 <waitpid@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1060 <WIFEXITED@plt>
test   %rax,%rax
jne    11a5 <execute+0x55>
mov    %ebp,%edi
call   1030 <WIFSIGNALED@plt>
test   %rax,%rax
je     1170 <execute+0x20>
jmp    11a5 <execute+0x55>
mov    0x0(%rbp),%rdi
mov    %rbp,%rsi
call   1050 <execvp@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@WUNTRACED = global i32 0
define i32 @execute(i8** %0) {
%2 = alloca i8**
%3 = alloca i64
%4 = alloca i32
store i8** %0, i8*** %2
%5 = call i64 (...) @fork()
store i64 %5, i64* %3
%6 = load i64, i64* %3
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %14
8: ; preds = %1
%9 = load i8**, i8*** %2
%10 = getelementptr inbounds i8*, i8** %9, i64 0
%11 = load i8*, i8** %10
%12 = load i8**, i8*** %2
%13 = call i32 @execvp(i8* %11, i8** %12)
br label %33
14: ; preds = %1
%15 = load i64, i64* %3
%16 = icmp sgt i64 %15, 0
br i1 %16, label %17, label %32
17: ; preds = %14
br label %18
18: ; preds = %17, %30
%19 = load i64, i64* %3
%20 = load i32, i32* @WUNTRACED
%21 = call i32 @waitpid(i64 %19, i32 0, i32 %20)
store i32 %21, i32* %4
%22 = load i32, i32* %4
%23 = call i64 @WIFEXITED(i32 %22)
%24 = icmp ne i64 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %18
%26 = load i32, i32* %4
%27 = call i64 @WIFSIGNALED(i32 %26)
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %30
29: ; preds = %25, %18
br label %31
30: ; preds = %25
br label %18
31: ; preds = %29
br label %32
32: ; preds = %31, %14
br label %33
33: ; preds = %32, %8
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
@WUNTRACED = global i32 0
define i32 @execute(i8** %0) {
%2 = tail call i64 (...) @fork()
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %7
4: ; preds = %1
%5 = load i8*, i8** %0
%6 = tail call i32 @execvp(i8* %5, i8** %0)
br label %17
7: ; preds = %1
%8 = icmp sgt i64 %2, 0
br i1 %8, label %9, label %17
9: ; preds = %7, %14
%10 = load i32, i32* @WUNTRACED
%11 = tail call i32 @waitpid(i64 %2, i32 0, i32 %10)
%12 = tail call i64 @WIFEXITED(i32 %11)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = tail call i64 @WIFSIGNALED(i32 %11)
%16 = icmp eq i64 %15, 0
br i1 %16, label %9, label %17
17: ; preds = %9, %14, %7, %4
%18 = phi i32 [ undef, %4 ], [ undef, %7 ], [ %11, %14 ], [ %11, %9 ]
ret i32 %18
}