#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*/ SEM_UNDO;
int /*<<< orphan*/ fatalsys(char *);
int semop(int, struct sembuf *, int);
void v(int semid) {
  struct sembuf semoparg = {0, 1, SEM_UNDO};
  if (semop(semid, &semoparg, 1) == -1)
    fatalsys("failed to increment semaphore");
}


x86 assembly (clang, -O0):
<v>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
movl   $0x0,-0x10(%rbp)
movl   $0x1,-0xc(%rbp)
mov    0x2eb0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x1,%edx
call   1030 <semop@plt>
cmp    $0xffffffff,%eax
jne    116b <v+0x4b>
lea    0xe9a(%rip),%rdi
call   1040 <fatalsys@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v>:
sub    $0x18,%rsp
movabs $0x100000000,%rax
mov    %rax,0x8(%rsp)
mov    0x2eb6(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x10(%rsp)
lea    0x8(%rsp),%rsi
mov    $0x1,%edx
call   1030 <semop@plt>
cmp    $0xffffffff,%eax
je     1159 <v+0x39>
add    $0x18,%rsp
ret
lea    0xea0(%rip),%rdi
call   1040 <fatalsys@plt>
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
@.str = [30 x i8] c"failed to increment semaphore\00"
define void @v(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 0
store i32 0, i32* %4
%5 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 1
store i32 1, i32* %5
%6 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %3, i32 0, i32 2
%7 = load i32, i32* @SEM_UNDO
store i32 %7, i32* %6
%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 %13
11: ; preds = %1
%12 = call i32 @fatalsys(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %1
ret void
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i32 }
@SEM_UNDO = global i32 0
@.str = [30 x i8] c"failed to increment semaphore\00"
define void @v(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 %12
10: ; preds = %1
%11 = call i32 @fatalsys(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %1
ret void
}