#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*/ LOG_DEBUG;
int LOG_PERROR;
int LOG_PID;
int /*<<< orphan*/ LOG_USER;
int /*<<< orphan*/ closelog();
int /*<<< orphan*/ openlog(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, int, int);
void *log_func(void *arg) {
  int i;
  int thrid = (int)arg;
  openlog(NULL, LOG_PERROR | LOG_PID, LOG_USER);
  for (i = 0; i < 10; i++) {
    syslog(LOG_DEBUG, "thread %i iter %i\n", thrid, i);
    sleep(thrid);
  }
  closelog();
  return NULL;
}


x86 assembly (clang, -O0):
<log_func>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %eax,-0x10(%rbp)
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
mov    0x2e6d(%rip),%rax
or     (%rax),%esi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%edi
call   1050 <openlog@plt>
movl   $0x0,-0xc(%rbp)
cmpl   $0xa,-0xc(%rbp)
jge    11b9 <log_func+0x79>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe62(%rip),%rsi
call   1040 <syslog@plt>
mov    -0x10(%rbp),%edi
call   1060 <sleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    117e <log_func+0x3e>
mov    $0x0,%al
call   1030 <closelog@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<log_func>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2e91(%rip),%rax
mov    0x2e7a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %edi,%edi
call   1050 <openlog@plt>
mov    0x2e57(%rip),%r15
mov    (%r15),%edi
lea    0xe85(%rip),%r14
mov    %r14,%rsi
mov    %ebx,%edx
xor    %ecx,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x1,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x2,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x3,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x4,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x5,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x6,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x7,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x8,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
mov    (%r15),%edi
mov    %r14,%rsi
mov    %ebx,%edx
mov    $0x9,%ecx
call   1040 <syslog@plt>
mov    %ebx,%edi
call   1060 <sleep@plt>
xor    %eax,%eax
call   1030 <closelog@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@LOG_PERROR = global i32 0
@LOG_PID = global i32 0
@LOG_USER = global i32 0
@LOG_DEBUG = global i32 0
@.str = [19 x i8] c"thread %i iter %i\0A\00"
define i8* @log_func(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = ptrtoint i8* %5 to i32
store i32 %6, i32* %4
%7 = load i32, i32* @LOG_PERROR
%8 = load i32, i32* @LOG_PID
%9 = or i32 %7, %8
%10 = load i32, i32* @LOG_USER
%11 = call i32 @openlog(i32* null, i32 %9, i32 %10)
store i32 0, i32* %3
br label %12
12: ; preds = %22, %1
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 10
br i1 %14, label %15, label %25
15: ; preds = %12
%16 = load i32, i32* @LOG_DEBUG
%17 = load i32, i32* %4
%18 = load i32, i32* %3
%19 = call i32 @syslog(i32 %16, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %17, i32 %18)
%20 = load i32, i32* %4
%21 = call i32 @sleep(i32 %20)
br label %22
22: ; preds = %15
%23 = load i32, i32* %3
%24 = add nsw i32 %23, 1
store i32 %24, i32* %3
br label %12
25: ; preds = %12
%26 = call i32 (...) @closelog()
ret i8* null
}

LLVM IR (-O2):
@LOG_PERROR = global i32 0
@LOG_PID = global i32 0
@LOG_USER = global i32 0
@LOG_DEBUG = global i32 0
@.str = [19 x i8] c"thread %i iter %i\0A\00"
define noalias i8* @log_func(i8* %0) {
%2 = ptrtoint i8* %0 to i64
%3 = trunc i64 %2 to i32
%4 = load i32, i32* @LOG_PERROR
%5 = load i32, i32* @LOG_PID
%6 = or i32 %5, %4
%7 = load i32, i32* @LOG_USER
%8 = tail call i32 @openlog(i32* null, i32 %6, i32 %7)
%9 = load i32, i32* @LOG_DEBUG
%10 = tail call i32 @syslog(i32 %9, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 0)
%11 = tail call i32 @sleep(i32 %3)
%12 = load i32, i32* @LOG_DEBUG
%13 = tail call i32 @syslog(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 1)
%14 = tail call i32 @sleep(i32 %3)
%15 = load i32, i32* @LOG_DEBUG
%16 = tail call i32 @syslog(i32 %15, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 2)
%17 = tail call i32 @sleep(i32 %3)
%18 = load i32, i32* @LOG_DEBUG
%19 = tail call i32 @syslog(i32 %18, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 3)
%20 = tail call i32 @sleep(i32 %3)
%21 = load i32, i32* @LOG_DEBUG
%22 = tail call i32 @syslog(i32 %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 4)
%23 = tail call i32 @sleep(i32 %3)
%24 = load i32, i32* @LOG_DEBUG
%25 = tail call i32 @syslog(i32 %24, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 5)
%26 = tail call i32 @sleep(i32 %3)
%27 = load i32, i32* @LOG_DEBUG
%28 = tail call i32 @syslog(i32 %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 6)
%29 = tail call i32 @sleep(i32 %3)
%30 = load i32, i32* @LOG_DEBUG
%31 = tail call i32 @syslog(i32 %30, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 7)
%32 = tail call i32 @sleep(i32 %3)
%33 = load i32, i32* @LOG_DEBUG
%34 = tail call i32 @syslog(i32 %33, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 8)
%35 = tail call i32 @sleep(i32 %3)
%36 = load i32, i32* @LOG_DEBUG
%37 = tail call i32 @syslog(i32 %36, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %3, i32 9)
%38 = tail call i32 @sleep(i32 %3)
%39 = tail call i32 (...) @closelog()
ret i8* null
}