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

/* Variables and functions */
int /*<<< orphan*/ SEM_UNDO;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ perror(char *);
int semop(int, struct sembuf *, int);
void sem_up(int semid) {
  struct sembuf sops;
  sops.sem_num = 0;
  sops.sem_op = 1;
  sops.sem_flg = SEM_UNDO;
  if (semop(semid, &sops, 1) == -1) {
    perror("semop failed");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<sem_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x1,-0x18(%rbp)
mov    0x2e9f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
jne    1186 <sem_up+0x56>
lea    0xe89(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sem_up>:
sub    $0x18,%rsp
movq   $0x0,0x10(%rsp)
movl   $0x1,0x8(%rsp)
mov    0x2ea4(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
je     116b <sem_up+0x3b>
add    $0x18,%rsp
ret
lea    0xe8e(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@SEM_UNDO = global i32 0
@.str = [13 x i8] c"semop failed\00"
define void @sem_up(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.sembuf
store i32 %0, i32* %2
%4 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 2
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 0
store i32 1, i32* %5
%6 = load i32, i32* @SEM_UNDO
%7 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 %6, i32* %7
%8 = load i32, i32* %2
%9 = call i32 @semop(i32 %8, %struct.sembuf* %3, i32 1)
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 1)
unreachable
14: ; preds = %1
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@SEM_UNDO = global i32 0
@.str = [13 x i8] c"semop failed\00"
define void @sem_up(i32 %0) {
%2 = alloca %struct.sembuf
%3 = bitcast %struct.sembuf* %2 to i8*
%4 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 2
store i64 0, i64* %4
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 0
store i32 1, i32* %5
%6 = load i32, i32* @SEM_UNDO
%7 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %2, i64 0, i32 1
store i32 %6, i32* %7
%8 = call i32 @semop(i32 %0, %struct.sembuf* %2, i32 1)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %1
%11 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %1
ret void
}