#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*/ STDOUT_FILENO;
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ write(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int main(void) {
  int i;
  pid_t pid;
  char str[10];
  pid = fork();
  switch (pid) {
  case -1:
    perror("fork");
    break;
  case 0:
    for (i = 1; i <= 50000; i++) {
      sprintf(str, "-%d", i);
      write(STDOUT_FILENO, str, strlen(str));
    }
    break;
  default:
    for (i = 1; i <= 50000; i++) {
      sprintf(str, "+%d", i);
      write(STDOUT_FILENO, str, strlen(str));
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
call   1070 <fork@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0xffffffff,%eax
je     118d <main+0x3d>
jmp    117d <main+0x2d>
mov    -0x1c(%rbp),%eax
test   %eax,%eax
je     119e <main+0x4e>
jmp    1203 <main+0xb3>
lea    0xe6c(%rip),%rdi
call   1050 <perror@plt>
jmp    1268 <main+0x118>
movl   $0x1,-0x8(%rbp)
cmpl   $0xc350,-0x8(%rbp)
jg     11fe <main+0xae>
lea    -0x16(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xe45(%rip),%rsi
call   1060 <sprintf@plt>
mov    0x2e24(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x16(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x16(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11a5 <main+0x55>
jmp    1268 <main+0x118>
movl   $0x1,-0x8(%rbp)
cmpl   $0xc350,-0x8(%rbp)
jg     1263 <main+0x113>
lea    -0x16(%rbp),%rdi
mov    -0x8(%rbp),%edx
lea    0xde4(%rip),%rsi
call   1060 <sprintf@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x16(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x16(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    120a <main+0xba>
jmp    1268 <main+0x118>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1070 <fork@plt>
test   %eax,%eax
je     11c2 <main+0x72>
cmp    $0xffffffff,%eax
je     121f <main+0xcf>
mov    $0x1,%ebx
lea    0xe8d(%rip),%r14
lea    0x6(%rsp),%r15
mov    0x2e68(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    (%r12),%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x1,%ebx
cmp    $0xc351,%ebx
jne    1190 <main+0x40>
jmp    1210 <main+0xc0>
mov    $0x1,%ebx
lea    0xe37(%rip),%r14
lea    0x6(%rsp),%r15
mov    0x2e16(%rip),%r12
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r14,%rsi
mov    %ebx,%edx
call   1060 <sprintf@plt>
mov    (%r12),%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <write@plt>
add    $0x1,%ebx
cmp    $0xc351,%ebx
jne    11e0 <main+0x90>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdda(%rip),%rdi
call   1050 <perror@plt>
jmp    1210 <main+0xc0>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [4 x i8] c"-%d\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [4 x i8] c"+%d\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
store i32 0, i32* %1
%5 = call i32 (...) @fork()
store i32 %5, i32* %3
%6 = load i32, i32* %3
switch i32 %6, label %26 [
i32 -1, label %7
i32 0, label %9
]
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %43
9: ; preds = %0
store i32 1, i32* %2
br label %10
10: ; preds = %22, %9
%11 = load i32, i32* %2
%12 = icmp sle i32 %11, 50000
br i1 %12, label %13, label %25
13: ; preds = %10
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @sprintf(i8* %14, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @STDOUT_FILENO
%18 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @write(i32 %17, i8* %18, i32 %20)
br label %22
22: ; preds = %13
%23 = load i32, i32* %2
%24 = add nsw i32 %23, 1
store i32 %24, i32* %2
br label %10
25: ; preds = %10
br label %43
26: ; preds = %0
store i32 1, i32* %2
br label %27
27: ; preds = %39, %26
%28 = load i32, i32* %2
%29 = icmp sle i32 %28, 50000
br i1 %29, label %30, label %42
30: ; preds = %27
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%32 = load i32, i32* %2
%33 = call i32 @sprintf(i8* %31, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %32)
%34 = load i32, i32* @STDOUT_FILENO
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%36 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%37 = call i32 @strlen(i8* %36)
%38 = call i32 @write(i32 %34, i8* %35, i32 %37)
br label %39
39: ; preds = %30
%40 = load i32, i32* %2
%41 = add nsw i32 %40, 1
store i32 %41, i32* %2
br label %27
42: ; preds = %27
br label %43
43: ; preds = %42, %25, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [4 x i8] c"-%d\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [4 x i8] c"+%d\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @fork()
switch i32 %3, label %14 [
i32 -1, label %4
i32 0, label %6
]
4: ; preds = %0
%5 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
6: ; preds = %0, %6
%7 = phi i32 [ %12, %6 ], [ 1, %0 ]
%8 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @STDOUT_FILENO
%10 = call i32 @strlen(i8* %2)
%11 = call i32 @write(i32 %9, i8* %2, i32 %10)
%12 = add nuw nsw i32 %7, 1
%13 = icmp eq i32 %12, 50001
br i1 %13, label %22, label %6
14: ; preds = %0, %14
%15 = phi i32 [ %20, %14 ], [ 1, %0 ]
%16 = call i32 @sprintf(i8* %2, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @STDOUT_FILENO
%18 = call i32 @strlen(i8* %2)
%19 = call i32 @write(i32 %17, i8* %2, i32 %18)
%20 = add nuw nsw i32 %15, 1
%21 = icmp eq i32 %20, 50001
br i1 %21, label %22, label %14
22: ; preds = %6, %14, %4
ret i32 0
}