#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*/ handle_fatal_error(char *);
scalar_t__ semop(int, struct sembuf *, int);
void sem_wait(int semid, int index) {
  struct sembuf sops[1];
  sops[0].sem_num = index;
  sops[0].sem_op = -1;
  sops[0].sem_flg = 0;
  if (semop(semid, sops, 1) < 0) {
    handle_fatal_error("Error using P().\n");
  }
}


x86 assembly (clang, -O0):
<sem_wait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
cmp    $0x0,%rax
jge    116a <sem_wait+0x4a>
lea    0xe9b(%rip),%rdi
call   1030 <handle_fatal_error@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sem_wait>:
sub    $0x18,%rsp
mov    %esi,(%rsp)
movl   $0xffffffff,0x4(%rsp)
ff
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
test   %rax,%rax
js     114f <sem_wait+0x2f>
add    $0x18,%rsp
ret
lea    0xeaa(%rip),%rdi
call   1030 <handle_fatal_error@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@.str = [18 x i8] c"Error using P().\0A\00"
define void @sem_wait(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1 x %struct.sembuf]
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %4
%7 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %5, i64 0, i64 0
%8 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %7, i32 0, i32 0
store i32 %6, i32* %8
%9 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %5, i64 0, i64 0
%10 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %9, i32 0, i32 1
store i32 -1, i32* %10
%11 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %5, i64 0, i64 0
%12 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %11, i32 0, i32 2
store i64 0, i64* %12
%13 = load i32, i32* %3
%14 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %5, i64 0, i64 0
%15 = call i64 @semop(i32 %13, %struct.sembuf* %14, i32 1)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i64 }
@.str = [18 x i8] c"Error using P().\0A\00"
define void @sem_wait(i32 %0, i32 %1) {
%3 = alloca [1 x %struct.sembuf]
%4 = bitcast [1 x %struct.sembuf]* %3 to i8*
%5 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0
%6 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0, i32 0
store i32 %1, i32* %6
%7 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0, i32 1
store i32 -1, i32* %7
%8 = getelementptr inbounds [1 x %struct.sembuf], [1 x %struct.sembuf]* %3, i64 0, i64 0, i32 2
store i64 0, i64* %8
%9 = call i64 @semop(i32 %0, %struct.sembuf* %5, i32 1)
%10 = icmp slt i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @handle_fatal_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
ret void
}