#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*/ exit(int);
int /*<<< orphan*/ perror(char *);
int semop(int, struct sembuf *, int);
void jd_sem_lidl2(int semid, int down1, int down2, int up) {
  struct sembuf sops[3];
  sops[0].sem_num = down1;
  sops[0].sem_op = 1;
  sops[0].sem_flg = 0;
  sops[1].sem_num = down2;
  sops[1].sem_op = 1;
  sops[1].sem_flg = 0;
  sops[2].sem_num = up;
  sops[2].sem_op = -1;
  sops[2].sem_flg = 0;
  if (semop(semid, (struct sembuf *)&sops, 3) == -1) {
    perror("semop error");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<jd_sem_lidl2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x40(%rbp)
movl   $0x1,-0x3c(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x30(%rbp)
movl   $0x1,-0x2c(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0xffffffff,-0x1c(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
jne    11b3 <jd_sem_lidl2+0x83>
lea    0xe5c(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jd_sem_lidl2>:
sub    $0x38,%rsp
mov    %esi,(%rsp)
movl   $0x1,0x4(%rsp)
movq   $0x0,0x8(%rsp)
mov    %edx,0x10(%rsp)
movl   $0x1,0x14(%rsp)
movq   $0x0,0x18(%rsp)
mov    %ecx,0x20(%rsp)
movl   $0xffffffff,0x24(%rsp)
ff
movq   $0x0,0x28(%rsp)
mov    %rsp,%rsi
mov    $0x3,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
je     1189 <jd_sem_lidl2+0x59>
add    $0x38,%rsp
ret
lea    0xe70(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i64 }
@.str = [12 x i8] c"semop error\00"
define void @jd_sem_lidl2(i32 %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca [3 x %struct.sembuf]
store i32 %0, i32* %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%10 = load i32, i32* %6
%11 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 0
%12 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %11, i32 0, i32 0
store i32 %10, i32* %12
%13 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 0
%14 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %13, i32 0, i32 1
store i32 1, i32* %14
%15 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, 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* %7
%18 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 1
%19 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %18, i32 0, i32 0
store i32 %17, i32* %19
%20 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 1
%21 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %20, i32 0, i32 1
store i32 1, i32* %21
%22 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 1
%23 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %22, i32 0, i32 2
store i64 0, i64* %23
%24 = load i32, i32* %8
%25 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 2
%26 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %25, i32 0, i32 0
store i32 %24, i32* %26
%27 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 2
%28 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %27, i32 0, i32 1
store i32 -1, i32* %28
%29 = getelementptr inbounds [3 x %struct.sembuf], [3 x %struct.sembuf]* %9, i64 0, i64 2
%30 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %29, i32 0, i32 2
store i64 0, i64* %30
%31 = load i32, i32* %5
%32 = bitcast [3 x %struct.sembuf]* %9 to %struct.sembuf*
%33 = call i32 @semop(i32 %31, %struct.sembuf* %32, i32 3)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %38
35: ; preds = %4
%36 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %4
ret void
}

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