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

/* Variables and functions */
int /*<<< orphan*/ IPC_CREAT;
void *SEM_UNDO;
int /*<<< orphan*/ ftok(char *, int);
int semget(int /*<<< orphan*/, int, int /*<<< orphan*/);
int /*<<< orphan*/ semop(int, struct sembuf *, int);
int /*<<< orphan*/ system(char *);
void main() {
  int sd_product;
  key_t key_product;
  struct sembuf sembuf_product;
  key_product = ftok("/arm", 1);
  sd_product = semget(key_product, 1, IPC_CREAT);
  sembuf_product.sem_num = 0;
  sembuf_product.sem_op = -1;
  sembuf_product.sem_flg = SEM_UNDO;
  semop(sd_product, &sembuf_product, 1);
  system("cp ./product.txt ./ship/product.txt");
  sembuf_product.sem_num = 0;
  sembuf_product.sem_op = 1;
  sembuf_product.sem_flg = SEM_UNDO;
  semop(sd_product, &sembuf_product, 1);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rdi
mov    $0x1,%esi
call   1060 <ftok@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e72(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0x20(%rbp)
mov    0x2e65(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1050 <semop@plt>
lea    0xe5b(%rip),%rdi
call   1040 <system@plt>
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x20(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1050 <semop@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xeb0(%rip),%rdi
mov    $0x1,%esi
call   1060 <ftok@plt>
mov    0x2e77(%rip),%rcx
mov    (%rcx),%edx
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,%ebx
movq   $0x0,0x18(%rsp)
movl   $0xffffffff,0x8(%rsp)
ff
mov    0x2e67(%rip),%r15
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <semop@plt>
lea    0xe59(%rip),%rdi
call   1040 <system@plt>
movq   $0x0,0x18(%rsp)
movl   $0x1,0x8(%rsp)
mov    (%r15),%rax
mov    %rax,0x10(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1050 <semop@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i8*, i64 }
@.str = [5 x i8] c"/arm\00"
@IPC_CREAT = global i32 0
@SEM_UNDO = global i8* null
@.str.1 = [36 x i8] c"cp ./product.txt ./ship/product.txt\00"
define void @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca %struct.sembuf
%4 = call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = load i32, i32* @IPC_CREAT
%7 = call i32 @semget(i32 %5, i32 1, i32 %6)
store i32 %7, i32* %1
%8 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 2
store i64 0, i64* %8
%9 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 -1, i32* %9
%10 = load i8*, i8** @SEM_UNDO
%11 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i8* %10, i8** %11
%12 = load i32, i32* %1
%13 = call i32 @semop(i32 %12, %struct.sembuf* %3, i32 1)
%14 = call i32 @system(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
%15 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 2
store i64 0, i64* %15
%16 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 1, i32* %16
%17 = load i8*, i8** @SEM_UNDO
%18 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i8* %17, i8** %18
%19 = load i32, i32* %1
%20 = call i32 @semop(i32 %19, %struct.sembuf* %3, i32 1)
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i8*, i64 }
@.str = [5 x i8] c"/arm\00"
@IPC_CREAT = global i32 0
@SEM_UNDO = global i8* null
@.str.1 = [36 x i8] c"cp ./product.txt ./ship/product.txt\00"
define void @main() {
%1 = alloca %struct.sembuf
%2 = bitcast %struct.sembuf* %1 to i8*
%3 = tail call i32 @ftok(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 1)
%4 = load i32, i32* @IPC_CREAT
%5 = tail call i32 @semget(i32 %3, i32 1, i32 %4)
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 2
store i64 0, i64* %6
%7 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 0
store i32 -1, i32* %7
%8 = load i8*, i8** @SEM_UNDO
%9 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %1, i64 0, i32 1
store i8* %8, i8** %9
%10 = call i32 @semop(i32 %5, %struct.sembuf* %1, i32 1)
%11 = call i32 @system(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i64 0, i64* %6
store i32 1, i32* %7
%12 = load i8*, i8** @SEM_UNDO
store i8* %12, i8** %9
%13 = call i32 @semop(i32 %5, %struct.sembuf* %1, i32 1)
ret void
}