#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*/ Error(char *);
int errno;
int /*<<< orphan*/ hextochar(int, char *);
int /*<<< orphan*/ mystrlen(char *);
int /*<<< orphan*/ write(int, char *, int /*<<< orphan*/);
void CheckErrno(int expected) {
  char buffer[16];
  write(1, "\nerrno\n", mystrlen("\nerrno\n"));
  hextochar(errno, buffer);
  write(1, buffer, mystrlen(buffer));
  write(1, "\n", mystrlen("\n"));
  if (expected != errno)
    Error("bad errno value\n");
}


x86 assembly (clang, -O0):
<CheckErrno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0xeae(%rip),%rdi
call   1050 <mystrlen@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe9b(%rip),%rsi
call   1030 <write@plt>
mov    0x2e6f(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1060 <hextochar@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x20(%rbp),%rdi
call   1050 <mystrlen@plt>
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
mov    $0x1,%edi
call   1030 <write@plt>
lea    0xe73(%rip),%rdi
call   1050 <mystrlen@plt>
mov    %eax,%edx
mov    $0x1,%edi
lea    0xe60(%rip),%rsi
call   1030 <write@plt>
mov    -0x4(%rbp),%eax
mov    0x2e1a(%rip),%rcx
cmp    (%rcx),%eax
je     11da <CheckErrno+0x9a>
lea    0xe33(%rip),%rdi
call   1040 <Error@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CheckErrno>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebp
lea    0xeaf(%rip),%rbx
mov    %rbx,%rdi
call   1050 <mystrlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2e71(%rip),%r14
mov    (%r14),%edi
mov    %rsp,%rbx
mov    %rbx,%rsi
call   1060 <hextochar@plt>
mov    %rbx,%rdi
call   1050 <mystrlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe7c(%rip),%rbx
mov    %rbx,%rdi
call   1050 <mystrlen@plt>
mov    $0x1,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
cmp    %ebp,(%r14)
je     11c3 <CheckErrno+0x83>
lea    0xe4a(%rip),%rdi
call   1040 <Error@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"\0Aerrno\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [17 x i8] c"bad errno value\0A\00"
define void @CheckErrno(i32 %0) {
%2 = alloca i32
%3 = alloca [16 x i8]
store i32 %0, i32* %2
%4 = call i32 @mystrlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @errno
%7 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%8 = call i32 @hextochar(i32 %6, i8* %7)
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%11 = call i32 @mystrlen(i8* %10)
%12 = call i32 @write(i32 1, i8* %9, i32 %11)
%13 = call i32 @mystrlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %13)
%15 = load i32, i32* %2
%16 = load i32, i32* @errno
%17 = icmp ne i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = call i32 @Error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %20
20: ; preds = %18, %1
ret void
}

LLVM IR (-O2):
@.str = [8 x i8] c"\0Aerrno\0A\00"
@errno = global i32 0
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [17 x i8] c"bad errno value\0A\00"
define void @CheckErrno(i32 %0) {
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%4 = tail call i32 @mystrlen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @write(i32 1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %4)
%6 = load i32, i32* @errno
%7 = call i32 @hextochar(i32 %6, i8* %3)
%8 = call i32 @mystrlen(i8* %3)
%9 = call i32 @write(i32 1, i8* %3, i32 %8)
%10 = call i32 @mystrlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* @errno
%13 = icmp eq i32 %12, %0
br i1 %13, label %16, label %14
14: ; preds = %1
%15 = call i32 @Error(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %1
ret void
}