#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*/ fprintf(int /*<<< orphan*/, char *, int, int, int, ...);
int getpid();
int gimmeThatStuff();
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ stderr;
void *thread_loop(void *arg) {
  int i = *((int *)arg), j;
  for (j = 0; j < 100; j++) {
    fprintf(stderr, "%i: tick %04i, pid %i, tid %i\n", i, j, getpid(),
            gimmeThatStuff());
    sleep(3);
  }
  fprintf(stderr, "%i: exit, pid %i, tid %i\n", i, getpid(), gimmeThatStuff());
}


x86 assembly (clang, -O0):
<thread_loop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x64,-0x18(%rbp)
jge    11c5 <thread_loop+0x85>
mov    0x2e73(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x1c(%rbp)
mov    $0x0,%al
call   1050 <gimmeThatStuff@plt>
mov    -0x28(%rbp),%edi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%ecx
mov    -0x1c(%rbp),%r8d
mov    %eax,%r9d
lea    0xe5a(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    115c <thread_loop+0x1c>
mov    0x2e14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <getpid@plt>
mov    %eax,-0x2c(%rbp)
mov    $0x0,%al
call   1050 <gimmeThatStuff@plt>
mov    -0x34(%rbp),%edi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
mov    %eax,%r8d
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread_loop>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    (%rdi),%r15d
mov    0x2e8b(%rip),%r13
lea    0xea4(%rip),%r14
xor    %ebp,%ebp
xchg   %ax,%ax
mov    0x0(%r13),%r12d
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebx
xor    %eax,%eax
call   1050 <gimmeThatStuff@plt>
mov    %r12d,%edi
mov    %r14,%rsi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %ebx,%r8d
mov    %eax,%r9d
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x3,%edi
call   1060 <sleep@plt>
add    $0x1,%ebp
cmp    $0x64,%ebp
jne    1160 <thread_loop+0x20>
mov    0x0(%r13),%ebx
xor    %eax,%eax
call   1030 <getpid@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1050 <gimmeThatStuff@plt>
lea    0xe66(%rip),%rsi
mov    %ebx,%edi
mov    %r15d,%edx
mov    %ebp,%ecx
mov    %eax,%r8d
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fprintf@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [31 x i8] c"%i: tick %04i, pid %i, tid %i\0A\00"
@.str.1 = [26 x i8] c"%i: exit, pid %i, tid %i\0A\00"
define i8* @thread_loop(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to i32*
%8 = load i32, i32* %7
store i32 %8, i32* %4
store i32 0, i32* %5
br label %9
9: ; preds = %20, %1
%10 = load i32, i32* %5
%11 = icmp slt i32 %10, 100
br i1 %11, label %12, label %23
12: ; preds = %9
%13 = load i32, i32* @stderr
%14 = load i32, i32* %4
%15 = load i32, i32* %5
%16 = call i32 (...) @getpid()
%17 = call i32 (...) @gimmeThatStuff()
%18 = call i32 (i32, i8*, i32, i32, i32, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %14, i32 %15, i32 %16, i32 %17)
%19 = call i32 @sleep(i32 3)
br label %20
20: ; preds = %12
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %9
23: ; preds = %9
%24 = load i32, i32* @stderr
%25 = load i32, i32* %4
%26 = call i32 (...) @getpid()
%27 = call i32 (...) @gimmeThatStuff()
%28 = call i32 (i32, i8*, i32, i32, i32, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %25, i32 %26, i32 %27)
%29 = load i8*, i8** %2
ret i8* %29
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [31 x i8] c"%i: tick %04i, pid %i, tid %i\0A\00"
@.str.1 = [26 x i8] c"%i: exit, pid %i, tid %i\0A\00"
define noalias i8* @thread_loop(i8* nocapture %0) {
%2 = bitcast i8* %0 to i32*
%3 = load i32, i32* %2
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %11, %4 ]
%6 = load i32, i32* @stderr
%7 = tail call i32 (...) @getpid()
%8 = tail call i32 (...) @gimmeThatStuff()
%9 = tail call i32 (i32, i8*, i32, i32, i32, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %5, i32 %7, i32 %8)
%10 = tail call i32 @sleep(i32 3)
%11 = add nuw nsw i32 %5, 1
%12 = icmp eq i32 %11, 100
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = load i32, i32* @stderr
%15 = tail call i32 (...) @getpid()
%16 = tail call i32 (...) @gimmeThatStuff()
%17 = tail call i32 (i32, i8*, i32, i32, i32, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %3, i32 %15, i32 %16)
ret i8* undef
}