#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 */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ alarm(int);
int /*<<< orphan*/ execl(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pause();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *);
int main(void) {
  pid_t childPid;
  childPid = fork();
  if (childPid < 0) {
    perror("fork error");
    exit(EXIT_FAILURE);
  }
  if (childPid == 0) {
    printf("this is child process\n");
    alarm(5);
    printf("Alarm is set to 5 seconds and is ticking now\n");
    execl("./child.exe", "child.exe", NULL);
    perror("execl");
    exit(EXIT_FAILURE);
  }
  while (1) {
    pause();
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jge    11af <main+0x3f>
lea    0xe64(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x10(%rbp)
jne    120d <main+0x9d>
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
mov    $0x5,%edi
call   1040 <alarm@plt>
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
lea    0xe6d(%rip),%rdi
lea    0xe68(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1080 <execl@plt>
lea    0xe62(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dda(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    1212 <main+0xa2>
mov    $0x0,%al
call   1050 <pause@plt>
jmp    1212 <main+0xa2>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
js     1189 <main+0x19>
je     1192 <main+0x22>
nop
xor    %eax,%eax
call   1050 <pause@plt>
jmp    1180 <main+0x10>
lea    0xe70(%rip),%rdi
jmp    11d0 <main+0x60>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
mov    $0x5,%edi
call   1040 <alarm@plt>
lea    0xe84(%rip),%rdi
call   1030 <puts@plt>
lea    0xe50(%rip),%rdi
lea    0xe4b(%rip),%rsi
xor    %edx,%edx
call   1080 <execl@plt>
lea    0xe47(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [11 x i8] c"fork error\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [23 x i8] c"this is child process\0A\00"
@.str.2 = [46 x i8] c"Alarm is set to 5 seconds and is ticking now\0A\00"
@.str.3 = [12 x i8] c"./child.exe\00"
@.str.4 = [10 x i8] c"child.exe\00"
@.str.5 = [6 x i8] c"execl\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
store i32 0, i32* %1
%3 = call i64 (...) @fork()
store i64 %3, i64* %2
%4 = load i64, i64* %2
%5 = icmp slt i64 %4, 0
br i1 %5, label %6, label %10
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = call i32 @exit(i32 %8)
unreachable
10: ; preds = %0
%11 = load i64, i64* %2
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %21
13: ; preds = %10
%14 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @alarm(i32 5)
%16 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0))
%17 = call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* null)
%18 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %10
br label %22
22: ; preds = %21, %22
%23 = call i32 (...) @pause()
br label %22
}

LLVM IR (-O2):
@.str = [11 x i8] c"fork error\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [12 x i8] c"./child.exe\00"
@.str.4 = [10 x i8] c"child.exe\00"
@.str.5 = [6 x i8] c"execl\00"
@EXIT_SUCCESS = global i32 0
@str = [22 x i8] c"this is child process\00"
@str.6 = [45 x i8] c"Alarm is set to 5 seconds and is ticking now\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp slt i64 %1, 0
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @EXIT_FAILURE
%6 = tail call i32 @exit(i32 %5)
unreachable
7: ; preds = %0
%8 = icmp eq i64 %1, 0
br i1 %8, label %9, label %17
9: ; preds = %7
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%11 = tail call i32 @alarm(i32 5)
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @str.6, i64 0, i64 0))
%13 = tail call i32 @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i32* null)
%14 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%15 = load i32, i32* @EXIT_FAILURE
%16 = tail call i32 @exit(i32 %15)
unreachable
17: ; preds = %7, %17
%18 = tail call i32 (...) @pause()
br label %17
}