#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*/ _exit(int);
int /*<<< orphan*/ execv(char *const, char *const *);
int fork();
int /*<<< orphan*/ perror(char *);
int zombize(char *const argv[]) {
  pid_t pid = fork();
  if (pid == -1) {
    perror("fork");
    return -1;
  }
  if (pid)
    return 0;
  execv(argv[0], argv);
  perror("execv");
  _exit(127);
}


x86 assembly (clang, -O0):
<zombize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x0,%al
call   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1178 <zombize+0x38>
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b4 <zombize+0x74>
cmpl   $0x0,-0x14(%rbp)
je     118e <zombize+0x4e>
movl   $0x0,-0x4(%rbp)
jmp    11b4 <zombize+0x74>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execv@plt>
lea    0xe60(%rip),%rdi
call   1040 <perror@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<zombize>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <fork@plt>
cmp    $0xffffffff,%eax
je     1161 <zombize+0x21>
test   %eax,%eax
je     1174 <zombize+0x34>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe98(%rip),%rdi
call   1040 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1158 <zombize+0x18>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execv@plt>
lea    0xe7f(%rip),%rdi
call   1040 <perror@plt>
mov    $0x7f,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"execv\00"
define i32 @zombize(i8** %0) {
%2 = alloca i32
%3 = alloca i8**
%4 = alloca i32
store i8** %0, i8*** %3
%5 = call i32 (...) @fork()
store i32 %5, i32* %4
%6 = load i32, i32* %4
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %2
br label %22
10: ; preds = %1
%11 = load i32, i32* %4
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %10
store i32 0, i32* %2
br label %22
14: ; preds = %10
%15 = load i8**, i8*** %3
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = load i8**, i8*** %3
%19 = call i32 @execv(i8* %17, i8** %18)
%20 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @_exit(i32 127)
unreachable
22: ; preds = %13, %8
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [6 x i8] c"execv\00"
define i32 @zombize(i8** %0) {
%2 = tail call i32 (...) @fork()
switch i32 %2, label %10 [
i32 -1, label %3
i32 0, label %5
]
3: ; preds = %1
%4 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %10
5: ; preds = %1
%6 = load i8*, i8** %0
%7 = tail call i32 @execv(i8* %6, i8** %0)
%8 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%9 = tail call i32 @_exit(i32 127)
unreachable
10: ; preds = %1, %3
%11 = phi i32 [ -1, %3 ], [ 0, %1 ]
ret i32 %11
}