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

/* Variables and functions */
int IPC_CREAT;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ ftok(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int semget(int /*<<< orphan*/, int, int);
scalar_t__ semop(int, struct sembuf *, int);
int main() {
  int semid;
  char pathname[] = "04_1a.c";
  key_t key;
  struct sembuf mybuf;
  if ((key = ftok(pathname, 0)) < 0) {
    printf("Can\'t generate key\n");
    exit(-1);
  }
  if ((semid = semget(key, 1, 0666 | IPC_CREAT)) < 0) {
    printf("Can\'t get semid\n");
    exit(-1);
  }
  mybuf.sem_op = 1;
  mybuf.sem_flg = 0;
  mybuf.sem_num = 0;
  if (semop(semid, &mybuf, 1) < 0) {
    printf("Can\'t wait for condition\n");
    exit(-1);
  }
  printf("Sem +1\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe9a(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1070 <ftok@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1197 <main+0x47>
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
or     $0x1b6,%edx
mov    $0x1,%esi
call   1030 <semget@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jge    11d5 <main+0x85>
lea    0xe56(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
movl   $0x1,-0x30(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x1,%edx
call   1050 <semop@plt>
cmp    $0x0,%rax
jge    121d <main+0xcd>
lea    0xe1f(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>
lea    0xe23(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
movabs $0x632e61315f3430,%rax
mov    %rax,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1070 <ftok@plt>
test   %eax,%eax
js     11ca <main+0x7a>
mov    0x2e66(%rip),%rcx
mov    $0x1b6,%edx
or     (%rcx),%edx
mov    %eax,%edi
mov    $0x1,%esi
call   1030 <semget@plt>
test   %eax,%eax
js     11d3 <main+0x83>
movl   $0x1,0x10(%rsp)
xorps  %xmm0,%xmm0
movups %xmm0,0x18(%rsp)
lea    0x10(%rsp),%rsi
mov    %eax,%edi
mov    $0x1,%edx
call   1050 <semop@plt>
test   %rax,%rax
js     11dc <main+0x8c>
lea    0xe42(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x28,%rsp
ret
lea    0xe5f(%rip),%rdi
jmp    11e3 <main+0x93>
lea    0xe46(%rip),%rdi
jmp    11e3 <main+0x93>
lea    0xe24(%rip),%rdi
call   1040 <puts@plt>
mov    $0xffffffff,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i64, i64 }
@__const.main.pathname = [8 x i8] c"04_1a.c\00"
@.str = [20 x i8] c"Can't generate key\0A\00"
@IPC_CREAT = global i32 0
@.str.1 = [17 x i8] c"Can't get semid\0A\00"
@.str.2 = [26 x i8] c"Can't wait for condition\0A\00"
@.str.3 = [8 x i8] c"Sem +1\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [8 x i8]
%4 = alloca i32
%5 = alloca %struct.sembuf
store i32 0, i32* %1
%6 = bitcast [8 x i8]* %3 to i8*
%7 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%8 = call i32 @ftok(i8* %7, i32 0)
store i32 %8, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; preds = %0
%14 = load i32, i32* %4
%15 = load i32, i32* @IPC_CREAT
%16 = or i32 438, %15
%17 = call i32 @semget(i32 %14, i32 1, i32 %16)
store i32 %17, i32* %2
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 -1)
unreachable
22: ; preds = %13
%23 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 0
store i32 1, i32* %23
%24 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 2
store i64 0, i64* %24
%25 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %5, i32 0, i32 1
store i64 0, i64* %25
%26 = load i32, i32* %2
%27 = call i64 @semop(i32 %26, %struct.sembuf* %5, i32 1)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %22
%30 = call i32 @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%31 = call i32 @exit(i32 -1)
unreachable
32: ; preds = %22
%33 = call i32 @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i64, i64 }
@IPC_CREAT = global i32 0
@str = [7 x i8] c"Sem +1\00"
@str.4 = [25 x i8] c"Can't wait for condition\00"
@str.5 = [16 x i8] c"Can't get semid\00"
@str.6 = [19 x i8] c"Can't generate key\00"
define i32 @main() {
%1 = alloca i64
%2 = alloca %struct.sembuf
%3 = bitcast i64* %1 to i8*
store i64 27917017669383216, i64* %1
%4 = bitcast %struct.sembuf* %2 to i8*
%5 = call i32 @ftok(i8* %3, i32 0)
%6 = icmp slt i32 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.6, i64 0, i64 0))
%9 = call i32 @exit(i32 -1)
unreachable
10: ; preds = %0
%11 = load i32, i32* @IPC_CREAT
%12 = or i32 %11, 438
%13 = call i32 @semget(i32 %5, i32 1, i32 %12)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %10
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.5, i64 0, i64 0))
%17 = call i32 @exit(i32 -1)
unreachable
18: ; preds = %10
%19 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 0
store i32 1, i32* %19
%20 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 1
%21 = bitcast i64* %20 to i8*
%22 = call i64 @semop(i32 %13, %struct.sembuf* %2, i32 1)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %18
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([25 x i8], [25 x i8]* @str.4, i64 0, i64 0))
%26 = call i32 @exit(i32 -1)
unreachable
27: ; preds = %18
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
ret i32 0
}