#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 */
typedef int /*<<< orphan*/ sem_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ errno;
int sem_trywait(int /*<<< orphan*/ *);
int /*<<< orphan*/ terminal_error(char *);
int trywait_sem(sem_t *s) {
  int ret;
retry:
  if ((ret = sem_trywait(s)) == -1) {
    if (errno == EINTR)
      goto retry;
    if (errno != EAGAIN)
      terminal_error("sem_trywait");
  }
  return ret;
}


x86 assembly (clang, -O0):
<trywait_sem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <sem_trywait@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xffffffff,%eax
jne    118b <trywait_sem+0x6b>
mov    0x2e98(%rip),%rax
mov    (%rax),%rax
mov    0x2e86(%rip),%rcx
cmp    (%rcx),%rax
jne    1160 <trywait_sem+0x40>
jmp    112c <trywait_sem+0xc>
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e57(%rip),%rcx
cmp    (%rcx),%rax
je     1186 <trywait_sem+0x66>
lea    0xe7f(%rip),%rdi
call   1040 <terminal_error@plt>
jmp    118b <trywait_sem+0x6b>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<trywait_sem>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2eae(%rip),%r15
mov    0x2e9f(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
call   1030 <sem_trywait@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
jne    1170 <trywait_sem+0x50>
mov    (%r15),%rax
cmp    (%r12),%rax
je     1140 <trywait_sem+0x20>
mov    0x2e69(%rip),%rcx
cmp    (%rcx),%rax
je     1170 <trywait_sem+0x50>
lea    0xe95(%rip),%rdi
call   1040 <terminal_error@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str = [12 x i8] c"sem_trywait\00"
define i32 @trywait_sem(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
store i32* %0, i32** %2
br label %4
4: ; preds = %12, %1
%5 = load i32*, i32** %2
%6 = call i32 @sem_trywait(i32* %5)
store i32 %6, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = load i64, i64* @errno
%10 = load i64, i64* @EINTR
%11 = icmp eq i64 %9, %10
br i1 %11, label %12, label %13
12: ; preds = %8
br label %4
13: ; preds = %8
%14 = load i64, i64* @errno
%15 = load i64, i64* @EAGAIN
%16 = icmp ne i64 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = call i32 @terminal_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %19
19: ; preds = %17, %13
br label %20
20: ; preds = %19, %4
%21 = load i32, i32* %3
ret i32 %21
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@EAGAIN = global i64 0
@.str = [12 x i8] c"sem_trywait\00"
define i32 @trywait_sem(i32* %0) {
br label %2
2: ; preds = %5, %1
%3 = tail call i32 @sem_trywait(i32* %0)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %14
5: ; preds = %2
%6 = load i64, i64* @errno
%7 = load i64, i64* @EINTR
%8 = icmp eq i64 %6, %7
br i1 %8, label %2, label %9
9: ; preds = %5
%10 = load i64, i64* @EAGAIN
%11 = icmp eq i64 %6, %10
br i1 %11, label %14, label %12
12: ; preds = %9
%13 = tail call i32 @terminal_error(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %2, %9, %12
ret i32 %3
}