#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 shmid_ds {
  int dummy;
};
typedef int key_t;

/* Variables and functions */
int IPC_CREAT;
int IPC_EXCL;
int IPC_RMID;
int IPC_STAT;
int ftok(char *, int /*<<< orphan*/);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
int /*<<< orphan*/ shmctl(int, int, struct shmid_ds *);
int shmget(int, int, int);
int main() {
  char *curdir;
  struct timeval tv;
  key_t ipc_key;
  int shmid;
  curdir = getcwd(NULL, 0);
  gettimeofday(&tv, NULL);
  ipc_key = ftok(curdir, tv.tv_usec);
  shmid = shmget(ipc_key, 65535, (IPC_CREAT | IPC_EXCL | 0600));
  shmget(ipc_key, -1, (IPC_CREAT | IPC_EXCL | 0600));
  shmget(ipc_key, 65535, -1);
  shmctl(shmid, IPC_RMID, NULL);
  shmid = shmget(-1, 65535, (IPC_CREAT | IPC_EXCL | 0600));
  shmctl(-1, IPC_RMID, NULL);
  shmctl(shmid, -1, NULL);
  shmctl(shmid, IPC_STAT, (struct shmid_ds *)-1);
  shmctl(shmid, IPC_RMID, NULL);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1040 <getcwd@plt>
mov    %rax,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%esi
call   1070 <ftok@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e34(%rip),%rax
mov    (%rax),%edx
mov    0x2e53(%rip),%rax
or     (%rax),%edx
or     $0x180,%edx
mov    $0xffff,%esi
call   1060 <shmget@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e0c(%rip),%rax
mov    (%rax),%edx
mov    0x2e2b(%rip),%rax
or     (%rax),%edx
or     $0x180,%edx
mov    $0xffffffff,%esi
call   1060 <shmget@plt>
mov    -0x1c(%rbp),%edi
mov    $0xffff,%esi
mov    $0xffffffff,%edx
call   1060 <shmget@plt>
mov    -0x20(%rbp),%edi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <shmctl@plt>
mov    0x2dc3(%rip),%rax
mov    (%rax),%edx
mov    0x2de2(%rip),%rax
or     (%rax),%edx
or     $0x180,%edx
mov    $0xffffffff,%edi
mov    $0xffff,%esi
call   1060 <shmget@plt>
mov    %eax,-0x20(%rbp)
mov    0x2da1(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <shmctl@plt>
mov    -0x20(%rbp),%edi
mov    $0xffffffff,%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <shmctl@plt>
mov    -0x20(%rbp),%edi
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    $0xffffffffffffffff,%rdx
call   1050 <shmctl@plt>
mov    -0x20(%rbp),%edi
mov    0x2d5e(%rip),%rax
mov    (%rax),%esi
xor    %eax,%eax
mov    %eax,%edx
call   1050 <shmctl@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
xor    %edi,%edi
xor    %esi,%esi
call   1040 <getcwd@plt>
mov    %rax,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%esi
mov    %rbx,%rdi
call   1070 <ftok@plt>
mov    %eax,%ebx
mov    0x2e3f(%rip),%r15
mov    (%r15),%edx
mov    0x2e5d(%rip),%r12
or     (%r12),%edx
or     $0x180,%edx
mov    %eax,%edi
mov    $0xffff,%esi
call   1060 <shmget@plt>
mov    %eax,%ebp
mov    (%r15),%edx
or     (%r12),%edx
or     $0x180,%edx
mov    %ebx,%edi
mov    $0xffffffff,%esi
call   1060 <shmget@plt>
mov    %ebx,%edi
mov    $0xffff,%esi
mov    $0xffffffff,%edx
call   1060 <shmget@plt>
mov    0x2df4(%rip),%r14
mov    (%r14),%esi
mov    %ebp,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
mov    (%r15),%edx
or     (%r12),%edx
or     $0x180,%edx
mov    $0xffffffff,%edi
mov    $0xffff,%esi
call   1060 <shmget@plt>
mov    %eax,%ebx
mov    (%r14),%esi
mov    $0xffffffff,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
mov    %ebx,%edi
mov    $0xffffffff,%esi
xor    %edx,%edx
call   1050 <shmctl@plt>
mov    0x2dae(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    $0xffffffffffffffff,%rdx
call   1050 <shmctl@plt>
mov    (%r14),%esi
mov    %ebx,%edi
xor    %edx,%edx
call   1050 <shmctl@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.timeval = type { i32 }
%struct.shmid_ds = type { i32 }
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@IPC_RMID = global i32 0
@IPC_STAT = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca %struct.timeval
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = call i8* @getcwd(i32* null, i32 0)
store i8* %6, i8** %2
%7 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%8 = load i8*, i8** %2
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%10 = load i32, i32* %9
%11 = call i32 @ftok(i8* %8, i32 %10)
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = load i32, i32* @IPC_CREAT
%14 = load i32, i32* @IPC_EXCL
%15 = or i32 %13, %14
%16 = or i32 %15, 384
%17 = call i32 @shmget(i32 %12, i32 65535, i32 %16)
store i32 %17, i32* %5
%18 = load i32, i32* %4
%19 = load i32, i32* @IPC_CREAT
%20 = load i32, i32* @IPC_EXCL
%21 = or i32 %19, %20
%22 = or i32 %21, 384
%23 = call i32 @shmget(i32 %18, i32 -1, i32 %22)
%24 = load i32, i32* %4
%25 = call i32 @shmget(i32 %24, i32 65535, i32 -1)
%26 = load i32, i32* %5
%27 = load i32, i32* @IPC_RMID
%28 = call i32 @shmctl(i32 %26, i32 %27, %struct.shmid_ds* null)
%29 = load i32, i32* @IPC_CREAT
%30 = load i32, i32* @IPC_EXCL
%31 = or i32 %29, %30
%32 = or i32 %31, 384
%33 = call i32 @shmget(i32 -1, i32 65535, i32 %32)
store i32 %33, i32* %5
%34 = load i32, i32* @IPC_RMID
%35 = call i32 @shmctl(i32 -1, i32 %34, %struct.shmid_ds* null)
%36 = load i32, i32* %5
%37 = call i32 @shmctl(i32 %36, i32 -1, %struct.shmid_ds* null)
%38 = load i32, i32* %5
%39 = load i32, i32* @IPC_STAT
%40 = call i32 @shmctl(i32 %38, i32 %39, %struct.shmid_ds* inttoptr (i64 -1 to %struct.shmid_ds*))
%41 = load i32, i32* %5
%42 = load i32, i32* @IPC_RMID
%43 = call i32 @shmctl(i32 %41, i32 %42, %struct.shmid_ds* null)
ret i32 0
}

LLVM IR (-O2):
%struct.timeval = type { i32 }
%struct.shmid_ds = type { i32 }
@IPC_CREAT = global i32 0
@IPC_EXCL = global i32 0
@IPC_RMID = global i32 0
@IPC_STAT = global i32 0
define i32 @main() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = tail call i8* @getcwd(i32* null, i32 0)
%4 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%5 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = tail call i32 @ftok(i8* %3, i32 %6)
%8 = load i32, i32* @IPC_CREAT
%9 = load i32, i32* @IPC_EXCL
%10 = or i32 %8, %9
%11 = or i32 %10, 384
%12 = tail call i32 @shmget(i32 %7, i32 65535, i32 %11)
%13 = load i32, i32* @IPC_CREAT
%14 = load i32, i32* @IPC_EXCL
%15 = or i32 %13, %14
%16 = or i32 %15, 384
%17 = tail call i32 @shmget(i32 %7, i32 -1, i32 %16)
%18 = tail call i32 @shmget(i32 %7, i32 65535, i32 -1)
%19 = load i32, i32* @IPC_RMID
%20 = tail call i32 @shmctl(i32 %12, i32 %19, %struct.shmid_ds* null)
%21 = load i32, i32* @IPC_CREAT
%22 = load i32, i32* @IPC_EXCL
%23 = or i32 %21, %22
%24 = or i32 %23, 384
%25 = tail call i32 @shmget(i32 -1, i32 65535, i32 %24)
%26 = load i32, i32* @IPC_RMID
%27 = tail call i32 @shmctl(i32 -1, i32 %26, %struct.shmid_ds* null)
%28 = tail call i32 @shmctl(i32 %25, i32 -1, %struct.shmid_ds* null)
%29 = load i32, i32* @IPC_STAT
%30 = tail call i32 @shmctl(i32 %25, i32 %29, %struct.shmid_ds* inttoptr (i64 -1 to %struct.shmid_ds*))
%31 = load i32, i32* @IPC_RMID
%32 = tail call i32 @shmctl(i32 %25, i32 %31, %struct.shmid_ds* null)
ret i32 0
}