#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 */
char getchar();
int getpid();
int /*<<< orphan*/ printf(char *, int, ...);
int in_child(int ppid) {
  printf("This is child [%d]\n", getpid());
  int i = 0;
  for (i = 0; i < 10; i++) {
    char c = getchar();
    printf("child [%d] : c = [%c]\n", getpid(), c);
  }
  return 0;
}


x86 assembly (clang, -O0):
<in_child>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    119d <in_child+0x6d>
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %al,-0x9(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,%esi
movsbl -0x9(%rbp),%edx
lea    0xe8c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1160 <in_child+0x30>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<in_child>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1030 <getpid@plt>
lea    0xebe(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
lea    0xeaf(%rip),%r14
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
movsbl %bl,%edx
mov    %r14,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [20 x i8] c"This is child [%d]\0A\00"
@.str.1 = [23 x i8] c"child [%d] : c = [%c]\0A\00"
define i32 @in_child(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8
store i32 %0, i32* %2
%5 = call i32 (...) @getpid()
%6 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 0, i32* %3
store i32 0, i32* %3
br label %7
7: ; preds = %16, %1
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = call signext i8 (...) @getchar()
store i8 %11, i8* %4
%12 = call i32 (...) @getpid()
%13 = load i8, i8* %4
%14 = sext i8 %13 to i32
%15 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %12, i32 %14)
br label %16
16: ; preds = %10
%17 = load i32, i32* %3
%18 = add nsw i32 %17, 1
store i32 %18, i32* %3
br label %7
19: ; preds = %7
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"This is child [%d]\0A\00"
@.str.1 = [23 x i8] c"child [%d] : c = [%c]\0A\00"
define i32 @in_child(i32 %0) {
%2 = tail call i32 (...) @getpid()
%3 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = tail call signext i8 (...) @getchar()
%5 = tail call i32 (...) @getpid()
%6 = sext i8 %4 to i32
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %5, i32 %6)
%8 = tail call signext i8 (...) @getchar()
%9 = tail call i32 (...) @getpid()
%10 = sext i8 %8 to i32
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %9, i32 %10)
%12 = tail call signext i8 (...) @getchar()
%13 = tail call i32 (...) @getpid()
%14 = sext i8 %12 to i32
%15 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %14)
%16 = tail call signext i8 (...) @getchar()
%17 = tail call i32 (...) @getpid()
%18 = sext i8 %16 to i32
%19 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %17, i32 %18)
%20 = tail call signext i8 (...) @getchar()
%21 = tail call i32 (...) @getpid()
%22 = sext i8 %20 to i32
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %21, i32 %22)
%24 = tail call signext i8 (...) @getchar()
%25 = tail call i32 (...) @getpid()
%26 = sext i8 %24 to i32
%27 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26)
%28 = tail call signext i8 (...) @getchar()
%29 = tail call i32 (...) @getpid()
%30 = sext i8 %28 to i32
%31 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %29, i32 %30)
%32 = tail call signext i8 (...) @getchar()
%33 = tail call i32 (...) @getpid()
%34 = sext i8 %32 to i32
%35 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %33, i32 %34)
%36 = tail call signext i8 (...) @getchar()
%37 = tail call i32 (...) @getpid()
%38 = sext i8 %36 to i32
%39 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %37, i32 %38)
%40 = tail call signext i8 (...) @getchar()
%41 = tail call i32 (...) @getpid()
%42 = sext i8 %40 to i32
%43 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i32 %41, i32 %42)
ret i32 0
}