#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*/ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ sleep(int);
int main() {
  pid_t p = fork();
  if (p)
    printf("%d\n", p);
  else {
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);
    for (;;)
      sleep(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     1187 <main+0x37>
mov    -0x8(%rbp),%esi
lea    0xe83(%rip),%rdi
call   1030 <printf@plt>
jmp    11c0 <main+0x70>
mov    0x2e42(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    11b1 <main+0x61>
xor    %edi,%edi
call   1050 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
jne    119c <main+0x4c>
mov    0x2e6d(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
cs nopw 0x0(%rax,%rax,1)
mov    $0x1,%edi
call   1060 <sleep@plt>
jmp    1190 <main+0x40>
lea    0xe5d(%rip),%rdi
mov    %eax,%esi
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"%d\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
%3 = call i32 (...) @fork()
store i32 %3, i32* %2
%4 = load i32, i32* %2
%5 = icmp ne i32 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = load i32, i32* %2
%8 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %18
9: ; preds = %0
%10 = load i32, i32* @STDIN_FILENO
%11 = call i32 @close(i32 %10)
%12 = load i32, i32* @STDOUT_FILENO
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* @STDERR_FILENO
%15 = call i32 @close(i32 %14)
br label %16
16: ; preds = %16, %9
%17 = call i32 @sleep(i32 1)
br label %16
18: ; preds = %6
%19 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [4 x i8] c"%d\0A\00"
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@STDERR_FILENO = global i32 0
define i32 @main() {
%1 = tail call i32 (...) @fork()
%2 = icmp eq i32 %1, 0
br i1 %2, label %6, label %3
3: ; preds = %0
%4 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%5 = tail call i32 @exit(i32 0)
unreachable
6: ; preds = %0
%7 = load i32, i32* @STDIN_FILENO
%8 = tail call i32 @close(i32 %7)
%9 = load i32, i32* @STDOUT_FILENO
%10 = tail call i32 @close(i32 %9)
%11 = load i32, i32* @STDERR_FILENO
%12 = tail call i32 @close(i32 %11)
br label %13
13: ; preds = %13, %6
%14 = tail call i32 @sleep(i32 1)
br label %13
}