#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 *, unsigned int, ...);
scalar_t__ pthread_self();
int /*<<< orphan*/ sleep(int);
void critical_section(int nap_time) {
  printf("THREAD %u: Entering my critical section.\n",
         (unsigned int)pthread_self());
  printf("THREAD %u: Napping for %d seconds.\n", (unsigned int)pthread_self(),
         nap_time);
  sleep(nap_time);
  printf("THREAD %u: Leaving my critical section.\n",
         (unsigned int)pthread_self());
}


x86 assembly (clang, -O0):
<critical_section>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
mov    -0x4(%rbp),%edx
lea    0xec5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <sleep@plt>
mov    $0x0,%al
call   1040 <pthread_self@plt>
mov    %eax,%esi
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<critical_section>:
push   %rbx
mov    %edi,%ebx
xor    %eax,%eax
call   1040 <pthread_self@plt>
lea    0xebf(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
call   1040 <pthread_self@plt>
lea    0xed2(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
xor    %eax,%eax
call   1030 <printf@plt>
mov    %ebx,%edi
call   1050 <sleep@plt>
xor    %eax,%eax
call   1040 <pthread_self@plt>
lea    0xed6(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
pop    %rbx
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [42 x i8] c"THREAD %u: Entering my critical section.\0A\00"
@.str.1 = [36 x i8] c"THREAD %u: Napping for %d seconds.\0A\00"
@.str.2 = [41 x i8] c"THREAD %u: Leaving my critical section.\0A\00"
define void @critical_section(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = call i64 (...) @pthread_self()
%4 = trunc i64 %3 to i32
%5 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = call i64 (...) @pthread_self()
%7 = trunc i64 %6 to i32
%8 = load i32, i32* %2
%9 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %7, i32 %8)
%10 = load i32, i32* %2
%11 = call i32 @sleep(i32 %10)
%12 = call i64 (...) @pthread_self()
%13 = trunc i64 %12 to i32
%14 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %13)
ret void
}

LLVM IR (-O2):
@.str = [42 x i8] c"THREAD %u: Entering my critical section.\0A\00"
@.str.1 = [36 x i8] c"THREAD %u: Napping for %d seconds.\0A\00"
@.str.2 = [41 x i8] c"THREAD %u: Leaving my critical section.\0A\00"
define void @critical_section(i32 %0) {
%2 = tail call i64 (...) @pthread_self()
%3 = trunc i64 %2 to i32
%4 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = tail call i64 (...) @pthread_self()
%6 = trunc i64 %5 to i32
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i32 %6, i32 %0)
%8 = tail call i32 @sleep(i32 %0)
%9 = tail call i64 (...) @pthread_self()
%10 = trunc i64 %9 to i32
%11 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.2, i64 0, i64 0), i32 %10)
ret void
}