#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 member_1;
  int /*<<< orphan*/ member_2;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ SEM_UNDO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int semop(int, struct sembuf *, int);
int sem_p(int semid) {
  struct sembuf sb = {0, -1, SEM_UNDO};
  int ret = semop(semid, &sb, 1);
  if (ret == -1)
    do {
      perror("semop");
      exit(EXIT_FAILURE);
    } while (0);
  return ret;
}


x86 assembly (clang, -O0):
<sem_p>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0xffffffff,-0xc(%rbp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1192 <sem_p+0x62>
jmp    1178 <sem_p+0x48>
lea    0xe81(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sem_p>:
sub    $0x18,%rsp
movabs $0xffffffff00000000,%rax
ff ff ff
mov    %rax,0x8(%rsp)
mov    0x2ea6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
je     1169 <sem_p+0x39>
add    $0x18,%rsp
ret
lea    0xe90(%rip),%rdi
call   1030 <perror@plt>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

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

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