#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 timeval {
  int /*<<< orphan*/ tv_usec;
};
struct timespec {
  int tv_sec;
  scalar_t__ tv_nsec;
};
struct sembuf {
  int sem_num;
  int sem_op;
  void *sem_flg;
};
typedef int /*<<< orphan*/ key_t;

/* Variables and functions */
int IPC_CREAT;
void *IPC_NOWAIT;
int /*<<< orphan*/ IPC_PRIVATE;
int /*<<< orphan*/ IPC_RMID;
int /*<<< orphan*/ ftok(char *, int /*<<< orphan*/);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ semctl(int, int /*<<< orphan*/, int /*<<< orphan*/);
int semget(int /*<<< orphan*/, int, int);
int /*<<< orphan*/ semop(int, struct sembuf *, int);
int /*<<< orphan*/ semtimedop(int, struct sembuf *, int, struct timespec *);
int main() {
  char *curdir;
  struct timeval tv;
  key_t ipc_key;
  int semid;
  struct sembuf sops[10];
  struct timespec ts;
  curdir = getcwd(NULL, 0);
  gettimeofday(&tv, NULL);
  ipc_key = ftok(curdir, tv.tv_usec);
  semid = semget(ipc_key, 10, 0666 | IPC_CREAT);
  sops[0].sem_num = 0;
  sops[0].sem_op = 1;
  sops[0].sem_flg = IPC_NOWAIT;
  sops[1].sem_num = 1;
  sops[1].sem_op = 1;
  sops[1].sem_flg = 0;
  semop(semid, sops, 2);
  sops[0].sem_num = 2;
  sops[0].sem_op = 1;
  sops[0].sem_flg = IPC_NOWAIT;
  sops[1].sem_num = 3;
  sops[1].sem_op = 1;
  sops[1].sem_flg = 0;
  semtimedop(semid, sops, 2, NULL);
  sops[0].sem_num = 5;
  sops[0].sem_op = 1;
  sops[0].sem_flg = IPC_NOWAIT;
  ts.tv_sec = 5;
  ts.tv_nsec = 0;
  semtimedop(semid, sops, 1, &ts);
  semctl(semid, 0, IPC_RMID);
  semid = semget(IPC_PRIVATE, 10, 0666 | IPC_CREAT);
  semop(-1, sops, 1);
  semop(semid, (struct sembuf *)-1, 1);
  semop(semid, NULL, -1);
  semtimedop(-1, sops, 1, &ts);
  semtimedop(semid, (struct sembuf *)-1, 1, &ts);
  semtimedop(semid, NULL, -1, &ts);
  semtimedop(semid, sops, 1, (struct timespec *)-1);
  semctl(semid, 0, IPC_RMID);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xd0,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1090 <ftok@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e11(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0xa,%esi
call   1030 <semget@plt>
mov    %eax,-0x20(%rbp)
movl   $0x0,-0xc0(%rbp)
movl   $0x1,-0xbc(%rbp)
mov    0x2e09(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xb8(%rbp)
movl   $0x1,-0xb0(%rbp)
movl   $0x1,-0xac(%rbp)
movq   $0x0,-0xa8(%rbp)
mov    -0x20(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x2,%edx
call   1080 <semop@plt>
movl   $0x2,-0xc0(%rbp)
movl   $0x1,-0xbc(%rbp)
mov    0x2db1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xb8(%rbp)
movl   $0x3,-0xb0(%rbp)
movl   $0x1,-0xac(%rbp)
movq   $0x0,-0xa8(%rbp)
mov    -0x20(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x2,%edx
xor    %eax,%eax
mov    %eax,%ecx
call   1050 <semtimedop@plt>
movl   $0x5,-0xc0(%rbp)
movl   $0x1,-0xbc(%rbp)
mov    0x2d55(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0xb8(%rbp)
movl   $0x5,-0xd0(%rbp)
movq   $0x0,-0xc8(%rbp)
mov    -0x20(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x1,%edx
lea    -0xd0(%rbp),%rcx
call   1050 <semtimedop@plt>
mov    -0x20(%rbp),%edi
mov    0x2cf1(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <semctl@plt>
mov    0x2cf1(%rip),%rax
mov    (%rax),%edi
mov    0x2cd0(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0xa,%esi
call   1030 <semget@plt>
mov    %eax,-0x20(%rbp)
lea    -0xc0(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x1,%edx
call   1080 <semop@plt>
mov    -0x20(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
mov    -0x20(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xffffffff,%edx
call   1080 <semop@plt>
lea    -0xc0(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x1,%edx
lea    -0xd0(%rbp),%rcx
call   1050 <semtimedop@plt>
mov    -0x20(%rbp),%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x1,%edx
lea    -0xd0(%rbp),%rcx
call   1050 <semtimedop@plt>
mov    -0x20(%rbp),%edi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xffffffff,%edx
lea    -0xd0(%rbp),%rcx
call   1050 <semtimedop@plt>
mov    -0x20(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x1,%edx
mov    $0xffffffffffffffff,%rcx
call   1050 <semtimedop@plt>
mov    -0x20(%rbp),%edi
mov    0x2c13(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <semctl@plt>
xor    %eax,%eax
add    $0xd0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc8,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1040 <gettimeofday@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1090 <ftok@plt>
mov    0x2e1c(%rip),%r12
mov    $0x1b6,%ebp
mov    (%r12),%edx
or     %ebp,%edx
mov    %eax,%edi
mov    $0xa,%esi
call   1030 <semget@plt>
mov    %eax,%ebx
movabs $0x100000000,%rax
mov    %rax,0x20(%rsp)
mov    0x2e15(%rip),%r14
mov    (%r14),%rax
mov    %rax,0x28(%rsp)
movabs $0x100000001,%rax
mov    %rax,0x30(%rsp)
movq   $0x0,0x38(%rsp)
lea    0x20(%rsp),%r15
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x2,%edx
call   1080 <semop@plt>
movabs $0x100000002,%rax
mov    %rax,0x20(%rsp)
mov    (%r14),%rax
mov    %rax,0x28(%rsp)
movabs $0x100000003,%rax
mov    %rax,0x30(%rsp)
movq   $0x0,0x38(%rsp)
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x2,%edx
xor    %ecx,%ecx
call   1050 <semtimedop@plt>
movabs $0x100000005,%rax
mov    %rax,0x20(%rsp)
mov    (%r14),%rax
mov    %rax,0x28(%rsp)
movl   $0x5,0x10(%rsp)
movq   $0x0,0x18(%rsp)
lea    0x10(%rsp),%r14
mov    %ebx,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <semtimedop@plt>
mov    0x2d3b(%rip),%r13
mov    0x0(%r13),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <semctl@plt>
mov    0x2d37(%rip),%rax
mov    (%rax),%edi
or     (%r12),%ebp
mov    $0xa,%esi
mov    %ebp,%edx
call   1030 <semget@plt>
mov    %eax,%ebp
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
mov    %ebp,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x1,%edx
call   1080 <semop@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
call   1080 <semop@plt>
mov    $0xffffffff,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <semtimedop@plt>
mov    %ebp,%edi
mov    $0xffffffffffffffff,%rsi
mov    $0x1,%edx
mov    %r14,%rcx
call   1050 <semtimedop@plt>
mov    %ebp,%edi
xor    %esi,%esi
mov    $0xffffffff,%edx
mov    %r14,%rcx
call   1050 <semtimedop@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    $0x1,%edx
mov    $0xffffffffffffffff,%rcx
call   1050 <semtimedop@plt>
mov    0x0(%r13),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1070 <semctl@plt>
xor    %eax,%eax
add    $0xc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.sembuf = type { i32, i32, i8* }
%struct.timespec = type { i32, i64 }
@IPC_CREAT = global i32 0
@IPC_NOWAIT = global i8* null
@IPC_RMID = global i32 0
@IPC_PRIVATE = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i32
%6 = alloca [10 x %struct.sembuf]
%7 = alloca %struct.timespec
store i32 0, i32* %1
%8 = call i8* @getcwd(i32* null, i32 0)
store i8* %8, i8** %2
%9 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%10 = load i8*, i8** %2
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%12 = load i32, i32* %11
%13 = call i32 @ftok(i8* %10, i32 %12)
store i32 %13, i32* %4
%14 = load i32, i32* %4
%15 = load i32, i32* @IPC_CREAT
%16 = or i32 438, %15
%17 = call i32 @semget(i32 %14, i32 10, i32 %16)
store i32 %17, i32* %5
%18 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%19 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %18, i32 0, i32 0
store i32 0, i32* %19
%20 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%21 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %20, i32 0, i32 1
store i32 1, i32* %21
%22 = load i8*, i8** @IPC_NOWAIT
%23 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%24 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %23, i32 0, i32 2
store i8* %22, i8** %24
%25 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 1
%26 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %25, i32 0, i32 0
store i32 1, i32* %26
%27 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 1
%28 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %27, i32 0, i32 1
store i32 1, i32* %28
%29 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 1
%30 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %29, i32 0, i32 2
store i8* null, i8** %30
%31 = load i32, i32* %5
%32 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%33 = call i32 @semop(i32 %31, %struct.sembuf* %32, i32 2)
%34 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%35 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %34, i32 0, i32 0
store i32 2, i32* %35
%36 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%37 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %36, i32 0, i32 1
store i32 1, i32* %37
%38 = load i8*, i8** @IPC_NOWAIT
%39 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%40 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %39, i32 0, i32 2
store i8* %38, i8** %40
%41 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 1
%42 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %41, i32 0, i32 0
store i32 3, i32* %42
%43 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 1
%44 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %43, i32 0, i32 1
store i32 1, i32* %44
%45 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 1
%46 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %45, i32 0, i32 2
store i8* null, i8** %46
%47 = load i32, i32* %5
%48 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%49 = call i32 @semtimedop(i32 %47, %struct.sembuf* %48, i32 2, %struct.timespec* null)
%50 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%51 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %50, i32 0, i32 0
store i32 5, i32* %51
%52 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%53 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %52, i32 0, i32 1
store i32 1, i32* %53
%54 = load i8*, i8** @IPC_NOWAIT
%55 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%56 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %55, i32 0, i32 2
store i8* %54, i8** %56
%57 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
store i32 5, i32* %57
%58 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 1
store i64 0, i64* %58
%59 = load i32, i32* %5
%60 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%61 = call i32 @semtimedop(i32 %59, %struct.sembuf* %60, i32 1, %struct.timespec* %7)
%62 = load i32, i32* %5
%63 = load i32, i32* @IPC_RMID
%64 = call i32 @semctl(i32 %62, i32 0, i32 %63)
%65 = load i32, i32* @IPC_PRIVATE
%66 = load i32, i32* @IPC_CREAT
%67 = or i32 438, %66
%68 = call i32 @semget(i32 %65, i32 10, i32 %67)
store i32 %68, i32* %5
%69 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%70 = call i32 @semop(i32 -1, %struct.sembuf* %69, i32 1)
%71 = load i32, i32* %5
%72 = call i32 @semop(i32 %71, %struct.sembuf* inttoptr (i64 -1 to %struct.sembuf*), i32 1)
%73 = load i32, i32* %5
%74 = call i32 @semop(i32 %73, %struct.sembuf* null, i32 -1)
%75 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%76 = call i32 @semtimedop(i32 -1, %struct.sembuf* %75, i32 1, %struct.timespec* %7)
%77 = load i32, i32* %5
%78 = call i32 @semtimedop(i32 %77, %struct.sembuf* inttoptr (i64 -1 to %struct.sembuf*), i32 1, %struct.timespec* %7)
%79 = load i32, i32* %5
%80 = call i32 @semtimedop(i32 %79, %struct.sembuf* null, i32 -1, %struct.timespec* %7)
%81 = load i32, i32* %5
%82 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %6, i64 0, i64 0
%83 = call i32 @semtimedop(i32 %81, %struct.sembuf* %82, i32 1, %struct.timespec* inttoptr (i64 -1 to %struct.timespec*))
%84 = load i32, i32* %5
%85 = load i32, i32* @IPC_RMID
%86 = call i32 @semctl(i32 %84, i32 0, i32 %85)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.sembuf = type { i32, i32, i8* }
%struct.timespec = type { i32, i64 }
@IPC_CREAT = global i32 0
@IPC_NOWAIT = global i8* null
@IPC_RMID = global i32 0
@IPC_PRIVATE = global i32 0
define i32 @main() {
%1 = alloca %struct.timeval
%2 = alloca [10 x %struct.sembuf]
%3 = alloca %struct.timespec
%4 = bitcast %struct.timeval* %1 to i8*
%5 = bitcast [10 x %struct.sembuf]* %2 to i8*
%6 = bitcast %struct.timespec* %3 to i8*
%7 = tail call i8* @getcwd(i32* null, i32 0)
%8 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i32 @ftok(i8* %7, i32 %10)
%12 = load i32, i32* @IPC_CREAT
%13 = or i32 %12, 438
%14 = tail call i32 @semget(i32 %11, i32 10, i32 %13)
%15 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %2, i64 0, i64 0
%16 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %2, i64 0, i64 0, i32 0
store i32 0, i32* %16
%17 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %2, i64 0, i64 0, i32 1
store i32 1, i32* %17
%18 = load i8*, i8** @IPC_NOWAIT
%19 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %2, i64 0, i64 0, i32 2
store i8* %18, i8** %19
%20 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %2, i64 0, i64 1, i32 0
store i32 1, i32* %20
%21 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %2, i64 0, i64 1, i32 1
store i32 1, i32* %21
%22 = getelementptr inbounds [10 x %struct.sembuf], [10 x %struct.sembuf]* %2, i64 0, i64 1, i32 2
store i8* null, i8** %22
%23 = call i32 @semop(i32 %14, %struct.sembuf* %15, i32 2)
store i32 2, i32* %16
store i32 1, i32* %17
%24 = load i8*, i8** @IPC_NOWAIT
store i8* %24, i8** %19
store i32 3, i32* %20
store i32 1, i32* %21
store i8* null, i8** %22
%25 = call i32 @semtimedop(i32 %14, %struct.sembuf* %15, i32 2, %struct.timespec* null)
store i32 5, i32* %16
store i32 1, i32* %17
%26 = load i8*, i8** @IPC_NOWAIT
store i8* %26, i8** %19
%27 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
store i32 5, i32* %27
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
store i64 0, i64* %28
%29 = call i32 @semtimedop(i32 %14, %struct.sembuf* %15, i32 1, %struct.timespec* %3)
%30 = load i32, i32* @IPC_RMID
%31 = call i32 @semctl(i32 %14, i32 0, i32 %30)
%32 = load i32, i32* @IPC_PRIVATE
%33 = load i32, i32* @IPC_CREAT
%34 = or i32 %33, 438
%35 = call i32 @semget(i32 %32, i32 10, i32 %34)
%36 = call i32 @semop(i32 -1, %struct.sembuf* %15, i32 1)
%37 = call i32 @semop(i32 %35, %struct.sembuf* inttoptr (i64 -1 to %struct.sembuf*), i32 1)
%38 = call i32 @semop(i32 %35, %struct.sembuf* null, i32 -1)
%39 = call i32 @semtimedop(i32 -1, %struct.sembuf* %15, i32 1, %struct.timespec* %3)
%40 = call i32 @semtimedop(i32 %35, %struct.sembuf* inttoptr (i64 -1 to %struct.sembuf*), i32 1, %struct.timespec* %3)
%41 = call i32 @semtimedop(i32 %35, %struct.sembuf* null, i32 -1, %struct.timespec* %3)
%42 = call i32 @semtimedop(i32 %35, %struct.sembuf* %15, i32 1, %struct.timespec* inttoptr (i64 -1 to %struct.timespec*))
%43 = load i32, i32* @IPC_RMID
%44 = call i32 @semctl(i32 %35, i32 0, i32 %43)
ret i32 0
}