#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;
  char buf[100];
  fork();
  pid = getpid();
  for (i = 1; i <= 200; i++) {
    sprintf(buf, "This line is from pid %d, value = %d\n", pid, i);
    write(1, buf, strlen(buf));
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    $0x0,%al
call   1070 <fork@plt>
mov    $0x0,%al
call   1040 <getpid@plt>
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x8(%rbp)
cmpl   $0xc8,-0x8(%rbp)
jg     11c5 <main+0x75>
lea    -0x70(%rbp),%rdi
mov    -0x4(%rbp),%edx
mov    -0x8(%rbp),%ecx
lea    0xe6f(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x70(%rbp),%rax
mov    %rax,-0x78(%rbp)
lea    -0x70(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1173 <main+0x23>
add    $0x80,%rsp
pop    %rbp
ret

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   1040 <getpid@plt>
mov    %eax,%r15d
mov    $0x1,%ebp
lea    0xe89(%rip),%r14
mov    %rsp,%rbx
nopw   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
cmp    $0xc9,%ebp
jne    1180 <main+0x30>
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [38 x i8] c"This line is 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 (...) @getpid()
br label %5
5: ; preds = %0, %5
%6 = phi i32 [ 1, %0 ], [ %10, %5 ]
%7 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %6)
%8 = call i32 @strlen(i8* %2)
%9 = call i32 @write(i32 1, i8* %2, i32 %8)
%10 = add nuw nsw i32 %6, 1
%11 = icmp eq i32 %10, 201
br i1 %11, label %12, label %5
12: ; preds = %5
ret void
}