#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 tv_nsec;
  scalar_t__ tv_sec;
};
typedef int /*<<< orphan*/ sem_t;

/* Variables and functions */
int sem_destroy(int /*<<< orphan*/ *);
int sem_init(int /*<<< orphan*/ *, int, int);
int sem_post(int /*<<< orphan*/ *);
int sem_timedwait(int /*<<< orphan*/ *, struct timespec *);
int sem_trywait(int /*<<< orphan*/ *);
int sem_wait(int /*<<< orphan*/ *);
int main(void) {
  sem_t sem;
  int ret;
  struct timespec timeout;
  timeout.tv_sec = 0;
  timeout.tv_nsec = 1000000;
  ret = sem_init(&sem, 1, 1);
  (void)ret;
  ret = sem_wait(&sem);
  (void)ret;
  ret = sem_post(&sem);
  (void)ret;
  ret = sem_trywait(&sem);
  (void)ret;
  ret = sem_timedwait(&sem, &timeout);
  (void)ret;
  ret = sem_destroy(&sem);
  (void)ret;
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x0,-0x18(%rbp)
movl   $0xf4240,-0x20(%rbp)
lea    -0x8(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1070 <sem_init@plt>
mov    %eax,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1030 <sem_wait@plt>
mov    %eax,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1060 <sem_post@plt>
mov    %eax,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1050 <sem_trywait@plt>
mov    %eax,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1040 <sem_timedwait@plt>
mov    %eax,-0xc(%rbp)
lea    -0x8(%rbp),%rdi
call   1080 <sem_destroy@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
movq   $0x0,0x18(%rsp)
movl   $0xf4240,0x10(%rsp)
lea    0xc(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
call   1070 <sem_init@plt>
mov    %rbx,%rdi
call   1030 <sem_wait@plt>
mov    %rbx,%rdi
call   1060 <sem_post@plt>
mov    %rbx,%rdi
call   1050 <sem_trywait@plt>
lea    0x10(%rsp),%rsi
mov    %rbx,%rdi
call   1040 <sem_timedwait@plt>
mov    %rbx,%rdi
call   1080 <sem_destroy@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
store i32 0, i32* %1
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 1000000, i32* %6
%7 = call i32 @sem_init(i32* %2, i32 1, i32 1)
store i32 %7, i32* %3
%8 = load i32, i32* %3
%9 = call i32 @sem_wait(i32* %2)
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = call i32 @sem_post(i32* %2)
store i32 %11, i32* %3
%12 = load i32, i32* %3
%13 = call i32 @sem_trywait(i32* %2)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 @sem_timedwait(i32* %2, %struct.timespec* %4)
store i32 %15, i32* %3
%16 = load i32, i32* %3
%17 = call i32 @sem_destroy(i32* %2)
store i32 %17, i32* %3
%18 = load i32, i32* %3
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.timespec
%3 = bitcast i32* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 0, i64* %5
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i32 1000000, i32* %6
%7 = call i32 @sem_init(i32* %1, i32 1, i32 1)
%8 = call i32 @sem_wait(i32* %1)
%9 = call i32 @sem_post(i32* %1)
%10 = call i32 @sem_trywait(i32* %1)
%11 = call i32 @sem_timedwait(i32* %1, %struct.timespec* %2)
%12 = call i32 @sem_destroy(i32* %1)
ret i32 0
}