#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 /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int write(int, char *, int);
void psemSignal(int *s) {
  char ch = 'Z';
  errno = 0;
  if (write(s[1], &ch, sizeof(char)) != 1) {
    fprintf(stderr, "Error writing to semaphore: %s.\n", strerror(errno));
    exit(EXIT_FAILURE);
  }
}


x86 assembly (clang, -O0):
<psemSignal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x5a,-0x9(%rbp)
mov    0x2e81(%rip),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
lea    -0x9(%rbp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
je     11b7 <psemSignal+0x77>
mov    0x2e5d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e49(%rip),%rax
mov    (%rax),%rdi
call   1060 <strerror@plt>
mov    -0x10(%rbp),%edi
mov    %rax,%rdx
lea    0xe5c(%rip),%rsi
call   1040 <fprintf@plt>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<psemSignal>:
push   %rbp
push   %rbx
push   %rax
movb   $0x5a,0x7(%rsp)
mov    0x2e89(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x4(%rdi),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1174 <psemSignal+0x34>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2e65(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rdi
call   1060 <strerror@plt>
lea    0xe74(%rip),%rsi
mov    %ebp,%edi
mov    %rax,%rdx
call   1040 <fprintf@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
@errno = global i64 0
@stderr = global i32 0
@.str = [33 x i8] c"Error writing to semaphore: %s.\0A\00"
@EXIT_FAILURE = global i32 0
define void @psemSignal(i32* %0) {
%2 = alloca i32*
%3 = alloca i8
store i32* %0, i32** %2
store i8 90, i8* %3
store i64 0, i64* @errno
%4 = load i32*, i32** %2
%5 = getelementptr inbounds i32, i32* %4, i64 1
%6 = load i32, i32* %5
%7 = call i32 @write(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 ([33 x i8], [33 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 = [33 x i8] c"Error writing to semaphore: %s.\0A\00"
@EXIT_FAILURE = global i32 0
define void @psemSignal(i32* nocapture %0) {
%2 = alloca i8
store i8 90, i8* %2
store i64 0, i64* @errno
%3 = getelementptr inbounds i32, i32* %0, i64 1
%4 = load i32, i32* %3
%5 = call i32 @write(i32 %4, i8* %2, i32 1)
%6 = icmp eq i32 %5, 1
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = load i64, i64* @errno
%10 = tail call i8* @strerror(i64 %9)
%11 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = tail call i32 @exit(i32 %12)
unreachable
14: ; preds = %1
ret void
}