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

/* Variables and functions */
int /*<<< orphan*/ SIGALRM;
int /*<<< orphan*/ SIG_DFL;
scalar_t__ execve(char *, char **, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ getpid();
int /*<<< orphan*/ ignore_signal(int /*<<< orphan*/);
scalar_t__ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ set_signal_handler(int /*<<< orphan*/, int /*<<< orphan*/);
void test_execve_start(char *self) {
  ignore_signal(SIGALRM);
  set_signal_handler(SIGALRM, SIG_DFL);
  do {
    if (kill(getpid(), SIGALRM) < 0) {
      perror("kill(getpid(), SIGALRM) < 0");
      exit(1);
    }
  } while (0);
  char *argv[] = {self, "cont", NULL};
  do {
    if (execve(self, argv, NULL)) {
      perror("execve(self, argv, NULL)");
      exit(1);
    }
  } while (0);
}


x86 assembly (clang, -O0):
<test_execve_start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1070 <ignore_signal@plt>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
mov    0x2e3e(%rip),%rax
mov    (%rax),%esi
call   1040 <set_signal_handler@plt>
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%edi
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
call   1060 <kill@plt>
cmp    $0x0,%rax
jge    11d8 <test_execve_start+0x68>
lea    0xe37(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    11dd <test_execve_start+0x6d>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xe30(%rip),%rax
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <execve@plt>
cmp    $0x0,%rax
je     1229 <test_execve_start+0xb9>
lea    0xe07(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jmp    122e <test_execve_start+0xbe>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_execve_start>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e67(%rip),%r14
mov    (%r14),%edi
call   1070 <ignore_signal@plt>
mov    (%r14),%edi
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
call   1040 <set_signal_handler@plt>
xor    %eax,%eax
call   1030 <getpid@plt>
mov    (%r14),%esi
mov    %eax,%edi
call   1060 <kill@plt>
test   %rax,%rax
js     11e3 <test_execve_start+0x73>
mov    %rbx,(%rsp)
lea    0xe61(%rip),%rax
mov    %rax,0x8(%rsp)
movq   $0x0,0x10(%rsp)
mov    %rsp,%rsi
mov    %rbx,%rdi
xor    %edx,%edx
call   1050 <execve@plt>
test   %rax,%rax
jne    11ec <test_execve_start+0x7c>
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe16(%rip),%rdi
jmp    11f3 <test_execve_start+0x83>
lea    0xe2e(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@SIGALRM = global i32 0
@SIG_DFL = global i32 0
@.str = [28 x i8] c"kill(getpid(), SIGALRM) < 0\00"
@.str.1 = [5 x i8] c"cont\00"
@.str.2 = [25 x i8] c"execve(self, argv, NULL)\00"
define void @test_execve_start(i8* %0) {
%2 = alloca i8*
%3 = alloca [3 x i8*]
store i8* %0, i8** %2
%4 = load i32, i32* @SIGALRM
%5 = call i32 @ignore_signal(i32 %4)
%6 = load i32, i32* @SIGALRM
%7 = load i32, i32* @SIG_DFL
%8 = call i32 @set_signal_handler(i32 %6, i32 %7)
br label %9
9: ; preds = %1
%10 = call i32 (...) @getpid()
%11 = load i32, i32* @SIGALRM
%12 = call i64 @kill(i32 %10, i32 %11)
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9
%15 = call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %9
br label %18
18: ; preds = %17
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%20 = load i8*, i8** %2
store i8* %20, i8** %19
%21 = getelementptr inbounds i8*, i8** %19, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %21
%22 = getelementptr inbounds i8*, i8** %21, i64 1
store i8* null, i8** %22
br label %23
23: ; preds = %18
%24 = load i8*, i8** %2
%25 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
%26 = call i64 @execve(i8* %24, i8** %25, i32* null)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %31
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @exit(i32 1)
unreachable
31: ; preds = %23
br label %32
32: ; preds = %31
ret void
}

LLVM IR (-O2):
@SIGALRM = global i32 0
@SIG_DFL = global i32 0
@.str = [28 x i8] c"kill(getpid(), SIGALRM) < 0\00"
@.str.1 = [5 x i8] c"cont\00"
@.str.2 = [25 x i8] c"execve(self, argv, NULL)\00"
define void @test_execve_start(i8* %0) {
%2 = alloca [3 x i8*]
%3 = load i32, i32* @SIGALRM
%4 = tail call i32 @ignore_signal(i32 %3)
%5 = load i32, i32* @SIGALRM
%6 = load i32, i32* @SIG_DFL
%7 = tail call i32 @set_signal_handler(i32 %5, i32 %6)
%8 = tail call i32 (...) @getpid()
%9 = load i32, i32* @SIGALRM
%10 = tail call i64 @kill(i32 %8, i32 %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %1
%13 = tail call i32 @perror(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %1
%16 = bitcast [3 x i8*]* %2 to i8*
%17 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 0
store i8* %0, i8** %17
%18 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 1
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [3 x i8*], [3 x i8*]* %2, i64 0, i64 2
store i8* null, i8** %19
%20 = call i64 @execve(i8* %0, i8** %17, i32* null)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %15
%23 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @exit(i32 1)
unreachable
25: ; preds = %15
ret void
}