#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*/ printf(char *, int, void *);
int /*<<< orphan*/ thread_exit();
int /*<<< orphan*/ work();
void thread_2(void *arg) {
  long long count = (long long)arg;
  for (int i = 0; i < count; i++) {
    printf("thread_2(%d, %p)\n", i, arg);
    work();
  }
  thread_exit();
}


x86 assembly (clang, -O0):
<thread_2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movslq -0x14(%rbp),%rax
cmp    -0x10(%rbp),%rax
jge    1181 <thread_2+0x51>
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rdx
lea    0xe99(%rip),%rdi
call   1050 <printf@plt>
mov    $0x0,%al
call   1030 <work@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    114b <thread_2+0x1b>
mov    $0x0,%al
call   1040 <thread_exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
jle    117d <thread_2+0x4d>
mov    %rdi,%r15
cmp    $0x2,%rdi
mov    $0x1,%r12d
cmovge %rdi,%r12
lea    0xeab(%rip),%r14
xor    %ebx,%ebx
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    %ebx,%esi
mov    %r15,%rdx
call   1050 <printf@plt>
xor    %eax,%eax
call   1030 <work@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1160 <thread_2+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <thread_exit@plt>

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

LLVM IR (-O2):
@.str = [18 x i8] c"thread_2(%d, %p)\0A\00"
define void @thread_2(i8* %0) {
%2 = icmp sgt i8* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = ptrtoint i8* %0 to i64
%5 = call i64 @llvm.smax.i64(i64 %4, i64 1)
br label %8
6: ; preds = %8, %1
%7 = tail call i32 (...) @thread_exit()
ret void
8: ; preds = %3, %8
%9 = phi i64 [ 0, %3 ], [ %13, %8 ]
%10 = trunc i64 %9 to i32
%11 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i32 %10, i8* %0)
%12 = tail call i32 (...) @work()
%13 = add nuw nsw i64 %9, 1
%14 = icmp eq i64 %13, %5
br i1 %14, label %6, label %8
}