#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 */
scalar_t__ fork();
int getpid();
int getppid();
int /*<<< orphan*/ printf(char *, int, ...);
int /*<<< orphan*/ wait();
int main() {
  int i = 0;
  if (fork()) {
    wait();
    i++;
    printf("in if %d %d\n", getpid(), getppid());
    printf("%d\n", i);
  } else {
    i--;
    printf("%d %d\n", getpid(), getppid());
    printf("%d\n", i);
  }
  i += 2;
  printf("%d\n", i);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     11c1 <main+0x71>
mov    $0x0,%al
call   1060 <wait@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0xc(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0xc(%rbp),%esi
mov    %eax,%edx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe54(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11ff <main+0xaf>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x10(%rbp)
mov    $0x0,%al
call   1050 <getppid@plt>
mov    -0x10(%rbp),%esi
mov    %eax,%edx
lea    0xe1f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     117f <main+0x2f>
xor    %eax,%eax
call   1060 <wait@plt>
mov    $0x3,%r14d
mov    $0x1,%r15d
lea    0xe83(%rip),%rbx
jmp    1192 <main+0x42>
mov    $0x1,%r14d
mov    $0xffffffff,%r15d
lea    0xe74(%rip),%rbx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <getppid@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%edx
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe52(%rip),%rbx
mov    %rbx,%rdi
mov    %r15d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"in if %d %d\0A\00"
@.str.1 = [4 x i8] c"%d\0A\00"
@.str.2 = [7 x i8] c"%d %d\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @fork()
%2 = icmp eq i64 %1, 0
br i1 %2, label %5, label %3
3: ; preds = %0
%4 = tail call i32 (...) @wait()
br label %5
5: ; preds = %0, %3
%6 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), %3 ], [ getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), %0 ]
%7 = phi i32 [ 1, %3 ], [ -1, %0 ]
%8 = phi i32 [ 3, %3 ], [ 1, %0 ]
%9 = tail call i32 (...) @getpid()
%10 = tail call i32 (...) @getppid()
%11 = tail call i32 (i8*, i32, ...) @printf(i8* %6, i32 %9, i32 %10)
%12 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%13 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %8)
ret i32 0
}