#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 */
struct timespec {
  int member_0;
  int member_1;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, void *);
int /*<<< orphan*/ nanosleep(struct timespec *, int /*<<< orphan*/ *);
int /*<<< orphan*/ pthread_exit(void *);
scalar_t__ pthread_self();
int /*<<< orphan*/ stderr;
void *waiting(void *arg) {
  int *patternp = arg;
  struct timespec yawn = {21, 42};
  fprintf(stderr, "thread tid %p waits\n", (void *)pthread_self());
  *patternp = 43690;
  nanosleep(&yawn, NULL);
  pthread_exit(arg);
}


x86 assembly (clang, -O0):
<waiting>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    0xea5(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xe89(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%rax
movl   $0xaaaa,(%rax)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <nanosleep@plt>
mov    -0x10(%rbp),%rdi
call   1050 <pthread_exit@plt>
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<waiting>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
movabs $0x2a00000015,%rax
mov    %rax,(%rsp)
mov    0x2e85(%rip),%rax
mov    (%rax),%ebp
xor    %eax,%eax
call   1060 <pthread_self@plt>
lea    0xe95(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
movl   $0xaaaa,(%rbx)
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <nanosleep@plt>
mov    %rbx,%rdi
call   1050 <pthread_exit@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@__const.waiting.yawn = %struct.timespec { i32 21, i32 42 }
@stderr = global i32 0
@.str = [21 x i8] c"thread tid %p waits\0A\00"
define i8* @waiting(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca %struct.timespec
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = bitcast i8* %6 to i32*
store i32* %7, i32** %4
%8 = bitcast %struct.timespec* %5 to i8*
%9 = load i32, i32* @stderr
%10 = call i64 (...) @pthread_self()
%11 = inttoptr i64 %10 to i8*
%12 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = load i32*, i32** %4
store i32 43690, i32* %13
%14 = call i32 @nanosleep(%struct.timespec* %5, i32* null)
%15 = load i8*, i8** %3
%16 = call i32 @pthread_exit(i8* %15)
%17 = load i8*, i8** %2
ret i8* %17
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@stderr = global i32 0
@.str = [21 x i8] c"thread tid %p waits\0A\00"
define noalias i8* @waiting(i8* %0) {
%2 = alloca i64
%3 = bitcast i64* %2 to %struct.timespec*
%4 = bitcast i8* %0 to i32*
%5 = bitcast i64* %2 to i8*
store i64 180388626453, i64* %2
%6 = load i32, i32* @stderr
%7 = tail call i64 (...) @pthread_self()
%8 = inttoptr i64 %7 to i8*
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %8)
store i32 43690, i32* %4
%10 = call i32 @nanosleep(%struct.timespec* %3, i32* null)
%11 = call i32 @pthread_exit(i8* %0)
ret i8* undef
}