#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 /*<<< orphan*/);
scalar_t__ fork();
scalar_t__ getpid();
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char *buf;
  char cmdline[64];
  int i;
  buf = malloc(10485760);
  memset(buf, 0, 10485760);
  printf("in parent:\n");
  sprintf(cmdline, "pmap -d %d", (int)getpid());
  system(cmdline);
  sprintf(cmdline, "cat /proc/%d/smaps", (int)getpid());
  system(cmdline);
  for (i = 0; i < 10; ++i) {
    if (0 == fork()) {
      sleep(60);
      _exit(0);
    }
  }
  if (0 == fork()) {
    printf("\n\nin child:\n");
    sprintf(cmdline, "pmap -d %d", (int)getpid());
    system(cmdline);
    sprintf(cmdline, "cat /proc/%d/smaps", (int)getpid());
    system(cmdline);
    _exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0xa00000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0xa00000,%edx
call   1070 <memset@plt>
lea    0xe32(%rip),%rdi
call   1060 <printf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x78(%rbp),%rdi
mov    %eax,%edx
lea    0xe1d(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <system@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%edx
lea    0xdfe(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <system@plt>
movl   $0x0,-0x64(%rbp)
cmpl   $0xa,-0x64(%rbp)
jge    1271 <main+0xe1>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    125e <main+0xce>
mov    $0x3c,%edi
call   10a0 <sleep@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
jmp    1263 <main+0xd3>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    122e <main+0x9e>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
jne    12f3 <main+0x163>
lea    0xd9d(%rip),%rdi
call   1060 <printf@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x88(%rbp),%rdi
mov    %eax,%edx
lea    0xd58(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <system@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    $0x0,%al
call   1040 <getpid@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%edx
lea    0xd39(%rip),%rsi
call   1090 <sprintf@plt>
lea    -0x60(%rbp),%rdi
call   1050 <system@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x40,%rsp
mov    $0xa00000,%edi
call   1080 <malloc@plt>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0xa00000,%edx
call   1070 <memset@plt>
lea    0xe69(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe38(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xe20(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     128d <main+0xfd>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
je     129e <main+0x10e>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbx
ret
mov    $0x3c,%edi
call   10a0 <sleep@plt>
xor    %edi,%edi
call   1030 <_exit@plt>
lea    0xd84(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd48(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xd30(%rip),%rsi
mov    %rbx,%rdi
mov    %eax,%edx
call   1090 <sprintf@plt>
mov    %rbx,%rdi
call   1060 <system@plt>
xor    %edi,%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"in parent:\0A\00"
@.str.1 = [11 x i8] c"pmap -d %d\00"
@.str.2 = [19 x i8] c"cat /proc/%d/smaps\00"
@.str.3 = [13 x i8] c"\0A\0Ain child:\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [64 x i8]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = call i8* @malloc(i32 10485760)
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = call i32 @memset(i8* %10, i32 0, i32 10485760)
%12 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%13 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%14 = call i64 (...) @getpid()
%15 = trunc i64 %14 to i32
%16 = call i32 @sprintf(i8* %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%18 = call i32 @system(i8* %17)
%19 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%20 = call i64 (...) @getpid()
%21 = trunc i64 %20 to i32
%22 = call i32 @sprintf(i8* %19, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%24 = call i32 @system(i8* %23)
store i32 0, i32* %8
br label %25
25: ; preds = %35, %2
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 10
br i1 %27, label %28, label %38
28: ; preds = %25
%29 = call i64 (...) @fork()
%30 = icmp eq i64 0, %29
br i1 %30, label %31, label %34
31: ; preds = %28
%32 = call i32 @sleep(i32 60)
%33 = call i32 @_exit(i32 0)
unreachable
34: ; preds = %28
br label %35
35: ; preds = %34
%36 = load i32, i32* %8
%37 = add nsw i32 %36, 1
store i32 %37, i32* %8
br label %25
38: ; preds = %25
%39 = call i64 (...) @fork()
%40 = icmp eq i64 0, %39
br i1 %40, label %41, label %56
41: ; preds = %38
%42 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
%43 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%44 = call i64 (...) @getpid()
%45 = trunc i64 %44 to i32
%46 = call i32 @sprintf(i8* %43, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %45)
%47 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%48 = call i32 @system(i8* %47)
%49 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%50 = call i64 (...) @getpid()
%51 = trunc i64 %50 to i32
%52 = call i32 @sprintf(i8* %49, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %51)
%53 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%54 = call i32 @system(i8* %53)
%55 = call i32 @_exit(i32 0)
unreachable
56: ; preds = %38
%57 = load i32, i32* %3
ret i32 %57
}

LLVM IR (-O2):
@.str.1 = [11 x i8] c"pmap -d %d\00"
@.str.2 = [19 x i8] c"cat /proc/%d/smaps\00"
@str = [11 x i8] c"in parent:\00"
@str.4 = [12 x i8] c"\0A\0Ain child:\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%5 = tail call dereferenceable_or_null(10485760) i8* @malloc(i32 10485760)
%6 = tail call i32 @memset(i8* %5, i32 0, i32 10485760)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%8 = tail call i64 (...) @getpid()
%9 = trunc i64 %8 to i32
%10 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %9)
%11 = call i32 @system(i8* %4)
%12 = tail call i64 (...) @getpid()
%13 = trunc i64 %12 to i32
%14 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %13)
%15 = call i32 @system(i8* %4)
%16 = tail call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %48, label %18
18: ; preds = %2
%19 = tail call i64 (...) @fork()
%20 = icmp eq i64 %19, 0
br i1 %20, label %48, label %21
21: ; preds = %18
%22 = tail call i64 (...) @fork()
%23 = icmp eq i64 %22, 0
br i1 %23, label %48, label %24
24: ; preds = %21
%25 = tail call i64 (...) @fork()
%26 = icmp eq i64 %25, 0
br i1 %26, label %48, label %27
27: ; preds = %24
%28 = tail call i64 (...) @fork()
%29 = icmp eq i64 %28, 0
br i1 %29, label %48, label %30
30: ; preds = %27
%31 = tail call i64 (...) @fork()
%32 = icmp eq i64 %31, 0
br i1 %32, label %48, label %33
33: ; preds = %30
%34 = tail call i64 (...) @fork()
%35 = icmp eq i64 %34, 0
br i1 %35, label %48, label %36
36: ; preds = %33
%37 = tail call i64 (...) @fork()
%38 = icmp eq i64 %37, 0
br i1 %38, label %48, label %39
39: ; preds = %36
%40 = tail call i64 (...) @fork()
%41 = icmp eq i64 %40, 0
br i1 %41, label %48, label %42
42: ; preds = %39
%43 = tail call i64 (...) @fork()
%44 = icmp eq i64 %43, 0
br i1 %44, label %48, label %45
45: ; preds = %42
%46 = tail call i64 (...) @fork()
%47 = icmp eq i64 %46, 0
br i1 %47, label %51, label %62
48: ; preds = %42, %39, %36, %33, %30, %27, %24, %21, %18, %2
%49 = tail call i32 @sleep(i32 60)
%50 = tail call i32 @_exit(i32 0)
unreachable
51: ; preds = %45
%52 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.4, i64 0, i64 0))
%53 = tail call i64 (...) @getpid()
%54 = trunc i64 %53 to i32
%55 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %54)
%56 = call i32 @system(i8* %4)
%57 = tail call i64 (...) @getpid()
%58 = trunc i64 %57 to i32
%59 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %58)
%60 = call i32 @system(i8* %4)
%61 = tail call i32 @_exit(i32 0)
unreachable
62: ; preds = %45
ret i32 0
}