#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*/ _exit(int);
int fork();
int /*<<< orphan*/ printf(char *);
int waitpid(int, int *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  int r;
  r = fork();
  if (r == 0) {
    _exit(0x123);
  } else {
    int child = r;
    int status = 0;
    r = waitpid(-1, &status, 0);
    if (r != child)
      return 1;
    if (status != 0x2300)
      return 1;
  }
  printf("ok\n");
  return 0;
}


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   1060 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1174 <main+0x34>
mov    $0x123,%edi
call   1030 <_exit@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    $0xffffffff,%edi
lea    -0x1c(%rbp),%rsi
xor    %edx,%edx
call   1050 <waitpid@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     11ac <main+0x6c>
movl   $0x1,-0x4(%rbp)
jmp    11dd <main+0x9d>
cmpl   $0x2300,-0x1c(%rbp)
je     11c5 <main+0x85>
movl   $0x1,-0x4(%rbp)
jmp    11dd <main+0x9d>
jmp    11ca <main+0x8a>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1060 <fork@plt>
test   %eax,%eax
je     1199 <main+0x59>
mov    %eax,%ebx
movl   $0x0,0xc(%rsp)
lea    0xc(%rsp),%rsi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    %ebx,%eax
jne    118e <main+0x4e>
cmpl   $0x2300,0xc(%rsp)
mov    $0x1,%eax
jne    1193 <main+0x53>
lea    0xe7b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
jmp    1193 <main+0x53>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    $0x123,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"ok\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i32 (...) @fork()
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @_exit(i32 291)
unreachable
14: ; preds = %2
%15 = load i32, i32* %6
store i32 %15, i32* %7
store i32 0, i32* %8
%16 = call i32 @waitpid(i32 -1, i32* %8, i32 0)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = load i32, i32* %7
%19 = icmp ne i32 %17, %18
br i1 %19, label %20, label %21
20: ; preds = %14
store i32 1, i32* %3
br label %28
21: ; preds = %14
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 8960
br i1 %23, label %24, label %25
24: ; preds = %21
store i32 1, i32* %3
br label %28
25: ; preds = %21
br label %26
26: ; preds = %25
%27 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %28
28: ; preds = %26, %24, %20
%29 = load i32, i32* %3
ret i32 %29
}

LLVM IR (-O2):
@str = [3 x i8] c"ok\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = tail call i32 (...) @fork()
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = tail call i32 @_exit(i32 291)
unreachable
8: ; preds = %2
%9 = bitcast i32* %3 to i8*
store i32 0, i32* %3
%10 = call i32 @waitpid(i32 -1, i32* %3, i32 0)
%11 = icmp eq i32 %10, %4
br i1 %11, label %13, label %12
12: ; preds = %8
br label %18
13: ; preds = %8
%14 = load i32, i32* %3
%15 = icmp eq i32 %14, 8960
br i1 %15, label %16, label %18
16: ; preds = %13
%17 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @str, i64 0, i64 0))
br label %18
18: ; preds = %12, %13, %16
%19 = phi i32 [ 0, %16 ], [ 1, %13 ], [ 1, %12 ]
ret i32 %19
}