#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*/ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  pid_t pid;
  pid = fork();
  if (pid < 0) {
    fprintf(stderr, "Err.(%s) fork() failed\n", strerror(errno));
    exit(EXIT_FAILURE);
  } else if (pid > 0)
    sleep(30);
  else
    exit(0);
  return (EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jge    11b6 <main+0x66>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x1c(%rbp),%edi
mov    %rax,%rdx
lea    0xe5d(%rip),%rsi
call   1030 <fprintf@plt>
mov    0x2e21(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
jle    11d0 <main+0x80>
mov    $0x1e,%edi
call   1060 <sleep@plt>
jmp    11d7 <main+0x87>
xor    %edi,%edi
call   1040 <exit@plt>
jmp    11dc <main+0x8c>
mov    0x2de5(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
js     1174 <main+0x24>
je     11aa <main+0x5a>
mov    $0x1e,%edi
call   1060 <sleep@plt>
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
pop    %rbx
ret
mov    0x2e65(%rip),%rax
mov    (%rax),%ebx
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe6e(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1030 <fprintf@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%edi
call   1040 <exit@plt>
xor    %edi,%edi
call   1040 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = call i64 (...) @fork()
store i64 %7, i64* %6
%8 = load i64, i64* %6
%9 = icmp slt i64 %8, 0
br i1 %9, label %10, label %17
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i32, i32* @errno
%13 = call i8* @strerror(i32 %12)
%14 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %2
%18 = load i64, i64* %6
%19 = icmp sgt i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = call i32 @sleep(i32 30)
br label %24
22: ; preds = %17
%23 = call i32 @exit(i32 0)
unreachable
24: ; preds = %20
br label %25
25: ; preds = %24
%26 = load i32, i32* @EXIT_SUCCESS
ret i32 %26
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [24 x i8] c"Err.(%s) fork() failed\0A\00"
@errno = global i32 0
@EXIT_FAILURE = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp slt i64 %3, 0
br i1 %4, label %5, label %12
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @EXIT_FAILURE
%11 = tail call i32 @exit(i32 %10)
unreachable
12: ; preds = %2
%13 = icmp eq i64 %3, 0
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = tail call i32 @sleep(i32 30)
%16 = load i32, i32* @EXIT_SUCCESS
ret i32 %16
17: ; preds = %12
%18 = tail call i32 @exit(i32 0)
unreachable
}