#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
void psemWait(int *s) {
  char ch;
  errno = 0;
  if (read(s[0], &ch, sizeof(char)) != 1) {
    fprintf(stderr, "Error reading from semaphore: %s.\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<psemWait>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
je     11b2 <psemWait+0x72>
mov    0x2e62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e4e(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe61(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e25(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psemWait>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e8e(%rip),%rbx
movq   $0x0,(%rbx)
mov    (%rdi),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
cmp    $0x1,%eax
jne    116e <psemWait+0x2e>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e6b(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rdi
call   1060 <strerror@plt>
lea    0xe7a(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"Error reading from semaphore: %s.\0A\00"
@EXIT_FAILURE = global i32 0
define void @psemWait(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
store i64 0, i64* @errno
%4 = load i32*, i32** %2
%5 = getelementptr inbounds i32, i32* %4, i64 0
%6 = load i32, i32* %5
%7 = call i32 @read(i32 %6, i8* %3, i32 1)
%8 = icmp ne i32 %7, 1
br i1 %8, label %9, label %16
9: ; preds = %1
%10 = load i32, i32* @stderr
%11 = load i64, i64* @errno
%12 = call i8* @strerror(i64 %11)
%13 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = call i32 @exit(i32 %14)
unreachable
16: ; preds = %1
ret void
}

LLVM IR (-O2):
@errno = global i64 0
@stderr = global i32 0
@.str = [35 x i8] c"Error reading from semaphore: %s.\0A\00"
@EXIT_FAILURE = global i32 0
define void @psemWait(i32* nocapture %0) {
%2 = alloca i8
store i64 0, i64* @errno
%3 = load i32, i32* %0
%4 = call i32 @read(i32 %3, i8* %2, i32 1)
%5 = icmp eq i32 %4, 1
br i1 %5, label %13, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = load i64, i64* @errno
%9 = tail call i8* @strerror(i64 %8)
%10 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = load i32, i32* @EXIT_FAILURE
%12 = tail call i32 @exit(i32 %11)
unreachable
13: ; preds = %1
ret void
}