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

/* Variables and functions */
int /*<<< orphan*/ fork();
int getpid();
int /*<<< orphan*/ sprintf(char *, char *, int, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void main(void) {
  pid_t pid;
  int i = 0;
  char buf[100];
  fork();
  fork();
  pid = getpid();
  while (1) {
    i++;
    sprintf(buf, "Hello World! from pid %d, value = %d\n", pid, i);
    write(1, buf, strlen(buf));
    int ca;
    for (ca = 0; ca < 50000000; ca++) {
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x8(%rbp)
mov    $0x0,%al
call   1070 <fork@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x4(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe6c(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
movl   $0x0,-0x74(%rbp)
cmpl   $0x2faf080,-0x74(%rbp)
jge    11e1 <main+0x91>
jmp    11d3 <main+0x83>
mov    -0x74(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x74(%rbp)
jmp    11c1 <main+0x71>
jmp    117a <main+0x2a>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1070 <fork@plt>
xor    %eax,%eax
call   1040 <getpid@plt>
mov    %eax,%r15d
mov    $0x1,%ebp
lea    0xe82(%rip),%r14
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1050 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x1,%ebp
jmp    1190 <main+0x40>

LLVM IR (-O0):
@.str = [38 x i8] c"Hello World! from pid %d, value = %d\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i8]
%4 = alloca i32
store i32 0, i32* %2
%5 = call i32 (...) @fork()
%6 = call i32 (...) @fork()
%7 = call i32 (...) @getpid()
store i32 %7, i32* %1
br label %8
8: ; preds = %0, %26
%9 = load i32, i32* %2
%10 = add nsw i32 %9, 1
store i32 %10, i32* %2
%11 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* %1
%13 = load i32, i32* %2
%14 = call i32 @sprintf(i8* %11, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%17 = call i32 @strlen(i8* %16)
%18 = call i32 @write(i32 1, i8* %15, i32 %17)
store i32 0, i32* %4
br label %19
19: ; preds = %23, %8
%20 = load i32, i32* %4
%21 = icmp slt i32 %20, 50000000
br i1 %21, label %22, label %26
22: ; preds = %19
br label %23
23: ; preds = %22
%24 = load i32, i32* %4
%25 = add nsw i32 %24, 1
store i32 %25, i32* %4
br label %19
26: ; preds = %19
br label %8
}

LLVM IR (-O2):
@.str = [38 x i8] c"Hello World! from pid %d, value = %d\0A\00"
define void @main() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @fork()
%4 = tail call i32 (...) @fork()
%5 = tail call i32 (...) @getpid()
br label %6
6: ; preds = %6, %0
%7 = phi i32 [ 0, %0 ], [ %8, %6 ]
%8 = add nuw nsw i32 %7, 1
%9 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %5, i32 %8)
%10 = call i32 @strlen(i8* %2)
%11 = call i32 @write(i32 1, i8* %2, i32 %10)
br label %6
}