#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*/ SometimesSafePrint(char *, int);
int /*<<< orphan*/ printf(char *, int);
void *ThreadBody2(void *arg) {
  int i;
  for (i = 0; i < 100; i++) {
    if (arg != NULL) {
      printf("Thread 2: %d\n", i);
    } else {
      SometimesSafePrint("Thread 2: ", i);
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<ThreadBody2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x64,-0xc(%rbp)
jge    117e <ThreadBody2+0x5e>
cmpq   $0x0,-0x8(%rbp)
je     115c <ThreadBody2+0x3c>
mov    -0xc(%rbp),%esi
lea    0xeae(%rip),%rdi
call   1030 <printf@plt>
jmp    116b <ThreadBody2+0x4b>
mov    -0xc(%rbp),%esi
lea    0xea8(%rip),%rdi
call   1040 <SometimesSafePrint@plt>
jmp    1170 <ThreadBody2+0x50>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1133 <ThreadBody2+0x13>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ThreadBody2>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
xor    %ebp,%ebp
lea    0xedb(%rip),%r14
lea    0xec6(%rip),%r15
jmp    1152 <ThreadBody2+0x32>
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %ebp,%esi
call   1040 <SometimesSafePrint@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
je     1163 <ThreadBody2+0x43>
test   %rbx,%rbx
je     1140 <ThreadBody2+0x20>
mov    %r15,%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
jmp    114a <ThreadBody2+0x2a>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [14 x i8] c"Thread 2: %d\0A\00"
@.str.1 = [11 x i8] c"Thread 2: \00"
define noalias i8* @ThreadBody2(i8* readnone %0) {
%2 = icmp eq i8* %0, null
br label %3
3: ; preds = %1, %9
%4 = phi i32 [ 0, %1 ], [ %10, %9 ]
br i1 %2, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i32 %4)
br label %9
7: ; preds = %3
%8 = tail call i32 @SometimesSafePrint(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i32 %4)
br label %9
9: ; preds = %5, %7
%10 = add nuw nsw i32 %4, 1
%11 = icmp eq i32 %10, 100
br i1 %11, label %12, label %3
12: ; preds = %9
ret i8* null
}