#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_num;
  int sem_op;
  scalar_t__ sem_flg;
};

/* Variables and functions */
int /*<<< orphan*/ SIGINT;
int /*<<< orphan*/ kill(int /*<<< orphan*/, int /*<<< orphan*/);
int semop(int, struct sembuf *, int);
int semap_post(int sem_id, int nsem, int cnt) {
  struct sembuf op[1];
  op[0].sem_num = nsem;
  op[0].sem_op = cnt;
  op[0].sem_flg = 0;
  int ret;
  ret = semop(sem_id, op, 1);
  if (ret == -1) {
    kill(0, SIGINT);
  }
  return ret;
}


x86 assembly (clang, -O0):
<semap_post>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0xffffffff,-0x24(%rbp)
jne    1173 <semap_post+0x53>
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1030 <kill@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<semap_post>:
push   %rbx
sub    $0x10,%rsp
mov    %esi,(%rsp)
mov    %edx,0x4(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1159 <semap_post+0x39>
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
call   1030 <kill@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@SIGINT = global i32 0
define i32 @semap_post(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [1 x %struct.sembuf]
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%9 = load i32, i32* %5
%10 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %7, i64 0, i64 0
%11 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %10, i32 0, i32 0
store i32 %9, i32* %11
%12 = load i32, i32* %6
%13 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %7, i64 0, i64 0
%14 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %13, i32 0, i32 1
store i32 %12, i32* %14
%15 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %7, i64 0, i64 0
%16 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %15, i32 0, i32 2
store i64 0, i64* %16
%17 = load i32, i32* %4
%18 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %7, i64 0, i64 0
%19 = call i32 @semop(i32 %17, %struct.sembuf* %18, i32 1)
store i32 %19, i32* %8
%20 = load i32, i32* %8
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %25
22: ; preds = %3
%23 = load i32, i32* @SIGINT
%24 = call i32 @kill(i32 0, i32 %23)
br label %25
25: ; preds = %22, %3
%26 = load i32, i32* %8
ret i32 %26
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@SIGINT = global i32 0
define i32 @semap_post(i32 %0, i32 %1, i32 %2) {
%4 = alloca [1 x %struct.sembuf]
%5 = bitcast [1 x %struct.sembuf]* %4 to i8*
%6 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0
%7 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0, i32 0
store i32 %1, i32* %7
%8 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0, i32 1
store i32 %2, i32* %8
%9 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %4, i64 0, i64 0, i32 2
store i64 0, i64* %9
%10 = call i32 @semop(i32 %0, %struct.sembuf* %6, i32 1)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %3
%13 = load i32, i32* @SIGINT
%14 = call i32 @kill(i32 0, i32 %13)
br label %15
15: ; preds = %12, %3
ret i32 %10
}