#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_down2(int semid, int id1, int id2) {
  struct sembuf sops[2];
  sops[0].sem_num = id1;
  sops[1].sem_num = id2;
  sops[0].sem_op = sops[1].sem_op = 1;
  sops[0].sem_flg = sops[1].sem_flg = 0;
  if (semop(semid, (struct sembuf *)&sops, 2) == -1) {
    perror("semop error");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<jd_sem_down2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x1,-0x2c(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0x2,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
jne    119b <jd_sem_down2+0x6b>
lea    0xe74(%rip),%rdi
call   1030 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<jd_sem_down2>:
sub    $0x28,%rsp
mov    %esi,(%rsp)
mov    %edx,0x10(%rsp)
movl   $0x1,0x14(%rsp)
movl   $0x1,0x4(%rsp)
movq   $0x0,0x18(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rsp,%rsi
mov    $0x2,%edx
call   1040 <semop@plt>
cmp    $0xffffffff,%eax
je     1174 <jd_sem_down2+0x44>
add    $0x28,%rsp
ret
lea    0xe85(%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_down2(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x %struct.sembuf]
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%8 = load i32, i32* %5
%9 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %7, i64 0, i64 0
%10 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %9, i32 0, i32 0
store i32 %8, i32* %10
%11 = load i32, i32* %6
%12 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %7, i64 0, i64 1
%13 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %12, i32 0, i32 0
store i32 %11, i32* %13
%14 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %7, i64 0, i64 1
%15 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %14, i32 0, i32 1
store i32 1, i32* %15
%16 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %7, i64 0, i64 0
%17 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %16, i32 0, i32 1
store i32 1, i32* %17
%18 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %7, i64 0, i64 1
%19 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %18, i32 0, i32 2
store i64 0, i64* %19
%20 = getelementptr inbounds [2 x %struct.sembuf], [2 x %struct.sembuf]* %7, i64 0, i64 0
%21 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %20, i32 0, i32 2
store i64 0, i64* %21
%22 = load i32, i32* %4
%23 = bitcast [2 x %struct.sembuf]* %7 to %struct.sembuf*
%24 = call i32 @semop(i32 %22, %struct.sembuf* %23, i32 2)
%25 = icmp eq i32 %24, -1
br i1 %25, label %26, label %29
26: ; preds = %3
%27 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%28 = call i32 @exit(i32 1)
unreachable
29: ; preds = %3
ret void
}

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