#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 /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ checked_write(int, char *, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, int, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ usleep(int);
void *thread1_func(void *arg) {
  int i;
  char buf[512];
  for (i = 0; i < 10; i++) {
    snprintf(buf, sizeof(buf), "thread1: %d %s\n", i, (char *)arg);
    checked_write(1, buf, strlen(buf));
    usleep(100 * 1000);
  }
  return NULL;
}


x86 assembly (clang, -O0):
<thread1_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11c4 <thread1_func+0x84>
lea    -0x210(%rbp),%rdi
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%r8
mov    $0x200,%esi
lea    0xe86(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x210(%rbp),%rax
mov    %rax,-0x218(%rbp)
lea    -0x210(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x218(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1050 <checked_write@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1156 <thread1_func+0x16>
xor    %eax,%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<thread1_func>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %rdi,%r15
xor    %ebp,%ebp
lea    0xea7(%rip),%r14
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r14,%rdx
mov    %ebp,%ecx
mov    %r15,%r8
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1050 <checked_write@plt>
mov    $0x186a0,%edi
call   1060 <usleep@plt>
add    $0x1,%ebp
cmp    $0xa,%ebp
jne    1160 <thread1_func+0x20>
xor    %eax,%eax
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [16 x i8] c"thread1: %d %s\0A\00"
define noalias i8* @thread1_func(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %10, %4 ]
%6 = call i32 @snprintf(i8* %3, i32 512, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %0)
%7 = call i32 @strlen(i8* %3)
%8 = call i32 @checked_write(i32 1, i8* %3, i32 %7)
%9 = call i32 @usleep(i32 100000)
%10 = add nuw nsw i32 %5, 1
%11 = icmp eq i32 %10, 10
br i1 %11, label %12, label %4
12: ; preds = %4
ret i8* null
}