#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 time_t;

/* Variables and functions */
int WEXITSTATUS(int);
scalar_t__ WIFEXITED(int);
int /*<<< orphan*/ WUNTRACED;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sleep(int);
int spawn_child(int, int *);
int waitpid(int, int *, int /*<<< orphan*/);
int main(void) {
  time_t timestamp;
  int status;
  int pid;
  timestamp = 256;
  pid = spawn_child(timestamp, &status);
  if (pid < 0) {
    return (1);
  } else if (pid == 0) {
    return (status);
  };
  sleep(1);
  pid = waitpid(pid, &status, WUNTRACED);
  if (pid != 0) {
    if (WIFEXITED(status)) {
      status = WEXITSTATUS(status);
      printf("Timestamp: %i\n", status);
    } else {
      printf("Still running");
    };
  } else {
    printf("No such process");
  };
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x100,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc(%rbp),%rsi
call   1060 <spawn_child@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
jge    119b <main+0x3b>
movl   $0x1,-0x4(%rbp)
jmp    123c <main+0xdc>
cmpl   $0x0,-0x10(%rbp)
jne    11b0 <main+0x50>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    123c <main+0xdc>
jmp    11b5 <main+0x55>
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    -0x10(%rbp),%edi
mov    0x2e17(%rip),%rax
mov    (%rax),%edx
lea    -0xc(%rbp),%rsi
call   1050 <waitpid@plt>
mov    %eax,-0x10(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1227 <main+0xc7>
mov    -0xc(%rbp),%edi
call   1070 <WIFEXITED@plt>
cmp    $0x0,%rax
je     1214 <main+0xb4>
mov    -0xc(%rbp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdf8(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1222 <main+0xc2>
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1235 <main+0xd5>
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rsi
mov    $0x100,%edi
call   1060 <spawn_child@plt>
test   %eax,%eax
js     11ce <main+0x6e>
je     11d5 <main+0x75>
mov    %eax,%ebx
mov    $0x1,%edi
call   1080 <sleep@plt>
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
call   1050 <waitpid@plt>
test   %eax,%eax
je     11db <main+0x7b>
mov    0xc(%rsp),%edi
call   1070 <WIFEXITED@plt>
test   %rax,%rax
je     11e4 <main+0x84>
mov    0xc(%rsp),%edi
call   1040 <WEXITSTATUS@plt>
mov    %eax,0xc(%rsp)
lea    0xe3f(%rip),%rdi
xor    %ebx,%ebx
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11f4 <main+0x94>
mov    $0x1,%ebx
jmp    11f4 <main+0x94>
mov    0xc(%rsp),%ebx
jmp    11f4 <main+0x94>
lea    0xe3b(%rip),%rdi
jmp    11eb <main+0x8b>
lea    0xe24(%rip),%rdi
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@WUNTRACED = global i32 0
@.str = [15 x i8] c"Timestamp: %i\0A\00"
@.str.1 = [14 x i8] c"Still running\00"
@.str.2 = [16 x i8] c"No such process\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
store i32 0, i32* %1
store i32 256, i32* %2
%5 = load i32, i32* %2
%6 = call i32 @spawn_child(i32 %5, i32* %3)
store i32 %6, i32* %4
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %0
store i32 1, i32* %1
br label %38
10: ; preds = %0
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = load i32, i32* %3
store i32 %14, i32* %1
br label %38
15: ; preds = %10
br label %16
16: ; preds = %15
%17 = call i32 @sleep(i32 1)
%18 = load i32, i32* %4
%19 = load i32, i32* @WUNTRACED
%20 = call i32 @waitpid(i32 %18, i32* %3, i32 %19)
store i32 %20, i32* %4
%21 = load i32, i32* %4
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %35
23: ; preds = %16
%24 = load i32, i32* %3
%25 = call i64 @WIFEXITED(i32 %24)
%26 = icmp ne i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %23
%28 = load i32, i32* %3
%29 = call i32 @WEXITSTATUS(i32 %28)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %34
32: ; preds = %23
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %27
br label %37
35: ; preds = %16
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %37
37: ; preds = %35, %34
store i32 0, i32* %1
br label %38
38: ; preds = %37, %13, %9
%39 = load i32, i32* %1
ret i32 %39
}

LLVM IR (-O2):
@WUNTRACED = global i32 0
@.str = [15 x i8] c"Timestamp: %i\0A\00"
@.str.1 = [14 x i8] c"Still running\00"
@.str.2 = [16 x i8] c"No such process\00"
define i32 @main() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 @spawn_child(i32 256, i32* %1)
%4 = icmp slt i32 %3, 0
br i1 %4, label %26, label %5
5: ; preds = %0
%6 = icmp eq i32 %3, 0
br i1 %6, label %7, label %9
7: ; preds = %5
%8 = load i32, i32* %1
br label %26
9: ; preds = %5
%10 = call i32 @sleep(i32 1)
%11 = load i32, i32* @WUNTRACED
%12 = call i32 @waitpid(i32 %3, i32* %1, i32 %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %9
%15 = load i32, i32* %1
%16 = call i64 @WIFEXITED(i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = load i32, i32* %1
%20 = call i32 @WEXITSTATUS(i32 %19)
store i32 %20, i32* %1
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i32 %20)
br label %26
22: ; preds = %14
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
br label %26
24: ; preds = %9
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %26
26: ; preds = %24, %22, %18, %0, %7
%27 = phi i32 [ %8, %7 ], [ 1, %0 ], [ 0, %18 ], [ 0, %22 ], [ 0, %24 ]
ret i32 %27
}