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

/* Variables and functions */
int /*<<< orphan*/ IPC_NOWAIT;
int /*<<< orphan*/ SEM_UNDO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int, char *);
int semop(int, struct sembuf *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int add_to_member(int semid, int member, int blocking, int undo, int delta) {
  int r;
  struct sembuf sem_op = {member, delta, 0};
  if (!blocking)
    sem_op.sem_flg |= IPC_NOWAIT;
  if (undo)
    sem_op.sem_flg |= SEM_UNDO;
  r = semop(semid, &sem_op, 1);
  if (r)
    fprintf(stderr, "add_to_member(%d)::semop: %s\n", semid, strerror(errno));
  return r;
}


x86 assembly (clang, -O0):
<add_to_member>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
mov    %ecx,-0x10(%rbp)
mov    %r8d,-0x14(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    117b <add_to_member+0x4b>
mov    0x2e75(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
cmpl   $0x0,-0x10(%rbp)
je     1194 <add_to_member+0x64>
mov    0x2e64(%rip),%rax
mov    (%rax),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x28(%rbp),%rsi
mov    $0x1,%edx
call   1040 <semop@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11e7 <add_to_member+0xb7>
mov    0x2e17(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x4(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
mov    -0x30(%rbp),%edi
mov    -0x2c(%rbp),%edx
mov    %rax,%rcx
lea    0xe1e(%rip),%rsi
call   1030 <fprintf@plt>
mov    -0x18(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_member>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%r14d
mov    %esi,(%rsp)
mov    %r8d,0x4(%rsp)
movq   $0x0,0x8(%rsp)
xor    %eax,%eax
test   %edx,%edx
je     11af <add_to_member+0x7f>
test   %ecx,%ecx
je     1163 <add_to_member+0x33>
mov    0x2e93(%rip),%rcx
or     (%rcx),%eax
mov    %eax,0x8(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x1,%edx
call   1040 <semop@plt>
mov    %eax,%ebp
test   %eax,%eax
je     11a4 <add_to_member+0x74>
mov    0x2e50(%rip),%rax
mov    (%rax),%ebx
mov    0x2e3f(%rip),%rax
mov    (%rax),%edi
call   1050 <strerror@plt>
lea    0xe69(%rip),%rsi
mov    %ebx,%edi
mov    %r14d,%edx
mov    %rax,%rcx
call   1030 <fprintf@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e32(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rsp)
test   %ecx,%ecx
jne    1156 <add_to_member+0x26>
jmp    1163 <add_to_member+0x33>

LLVM IR (-O0):
%struct.sembuf = type { i32, i32, i32, i32 }
@IPC_NOWAIT = global i32 0
@SEM_UNDO = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"add_to_member(%d)::semop: %s\0A\00"
@errno = global i32 0
define i32 @add_to_member(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca %struct.sembuf
store i32 %0, i32* %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%13 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %12, i32 0, i32 0
%14 = load i32, i32* %7
store i32 %14, i32* %13
%15 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %12, i32 0, i32 1
%16 = load i32, i32* %10
store i32 %16, i32* %15
%17 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %12, i32 0, i32 2
store i32 0, i32* %17
%18 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %12, i32 0, i32 3
store i32 0, i32* %18
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
br i1 %20, label %26, label %21
21: ; preds = %5
%22 = load i32, i32* @IPC_NOWAIT
%23 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %12, i32 0, i32 2
%24 = load i32, i32* %23
%25 = or i32 %24, %22
store i32 %25, i32* %23
br label %26
26: ; preds = %21, %5
%27 = load i32, i32* %9
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %26
%30 = load i32, i32* @SEM_UNDO
%31 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %12, i32 0, i32 2
%32 = load i32, i32* %31
%33 = or i32 %32, %30
store i32 %33, i32* %31
br label %34
34: ; preds = %29, %26
%35 = load i32, i32* %6
%36 = call i32 @semop(i32 %35, %struct.sembuf* %12, i32 1)
store i32 %36, i32* %11
%37 = load i32, i32* %11
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %45
39: ; preds = %34
%40 = load i32, i32* @stderr
%41 = load i32, i32* %6
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 @fprintf(i32 %40, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %41, i8* %43)
br label %45
45: ; preds = %39, %34
%46 = load i32, i32* %11
ret i32 %46
}

LLVM IR (-O2):
%struct.sembuf = type { i32, i32, i32, i32 }
@IPC_NOWAIT = global i32 0
@SEM_UNDO = global i32 0
@stderr = global i32 0
@.str = [30 x i8] c"add_to_member(%d)::semop: %s\0A\00"
@errno = global i32 0
define i32 @add_to_member(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca %struct.sembuf
%7 = bitcast %struct.sembuf* %6 to i8*
%8 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i64 0, i32 0
store i32 %1, i32* %8
%9 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i64 0, i32 1
store i32 %4, i32* %9
%10 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i64 0, i32 2
store i32 0, i32* %10
%11 = getelementptr inbounds %struct.sembuf, %struct.sembuf* %6, i64 0, i32 3
store i32 0, i32* %11
%12 = icmp eq i32 %2, 0
br i1 %12, label %13, label %15
13: ; preds = %5
%14 = load i32, i32* @IPC_NOWAIT
store i32 %14, i32* %10
br label %15
15: ; preds = %13, %5
%16 = phi i32 [ %14, %13 ], [ 0, %5 ]
%17 = icmp eq i32 %3, 0
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* @SEM_UNDO
%20 = or i32 %16, %19
store i32 %20, i32* %10
br label %21
21: ; preds = %18, %15
%22 = call i32 @semop(i32 %0, %struct.sembuf* %6, i32 1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %29, label %24
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i32 %0, i8* %27)
br label %29
29: ; preds = %24, %21
ret i32 %22
}