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

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ asprintf(char **, char *, long, char *);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char const *, ...);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, long);
int /*<<< orphan*/ stdout;
char *strerror(long);
void _test_errno(const char *file, long line, const char *desc, long actual,
                 long expected) {
  char *actual_str;
  char *expected_str;
  asprintf(&actual_str, "%ld\t%s", actual, actual ? strerror(actual) : "");
  asprintf(&expected_str, "%ld\t%s", expected,
           expected ? strerror(expected) : "");
  do {
    const char *_exprstr = (actual == expected) ? "PASS" : "FAIL";
    char _linestr[BUFSIZ];
    if (!(actual == expected)) {
      snprintf(_linestr, sizeof(_linestr), " (%s:%ld)", file, line);
    } else {
      _linestr[0] = 0;
    }
    if ("%s" == 0) {
      printf("\tValue: "
             "%s"
             "\n"
             "[%s] %s%s\n",
             actual_str, _exprstr, desc, _linestr);
    } else {
      printf("\tActual: "
             "%s"
             "\n"
             "\tExpected: "
             "%s"
             "\n"
             "[%s] %s%s\n",
             actual_str, expected_str, _exprstr, desc, _linestr);
    }
    if (!(actual == expected)) {
      printf("\t%s:%ld\n", file, line);
    }
    fflush(stdout);
  } while (0);
  ;
  free(actual_str);
  free(expected_str);
}


x86 assembly (clang, -O0):
<_test_errno>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a4 <_test_errno+0x44>
mov    -0x20(%rbp),%rdi
call   1080 <strerror@plt>
mov    %rax,-0x60(%rbp)
jmp    11b4 <_test_errno+0x54>
lea    0xe9d(%rip),%rax
mov    %rax,-0x60(%rbp)
jmp    11b4 <_test_errno+0x54>
mov    -0x58(%rbp),%rdx
mov    -0x60(%rbp),%rcx
lea    -0x30(%rbp),%rdi
lea    0xe39(%rip),%rsi
call   1070 <asprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x68(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11f1 <_test_errno+0x91>
mov    -0x28(%rbp),%rdi
call   1080 <strerror@plt>
mov    %rax,-0x70(%rbp)
jmp    1201 <_test_errno+0xa1>
lea    0xe50(%rip),%rax
mov    %rax,-0x70(%rbp)
jmp    1201 <_test_errno+0xa1>
mov    -0x68(%rbp),%rdx
mov    -0x70(%rbp),%rcx
lea    -0x38(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1070 <asprintf@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    %rcx,%rax
lea    0xddc(%rip),%rcx
lea    0xdda(%rip),%rax
cmove  %rcx,%rax
mov    %rax,-0x40(%rbp)
mov    0x2d9f(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x80(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x48(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x78(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     129b <_test_errno+0x13b>
mov    -0x78(%rbp),%rdi
mov    -0x80(%rbp),%rax
mov    %eax,%esi
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
lea    0xd80(%rip),%rdx
call   1050 <snprintf@plt>
jmp    12a2 <_test_errno+0x142>
mov    -0x78(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x78(%rbp),%r9
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    -0x18(%rbp),%r8
lea    0xd5e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     12e8 <_test_errno+0x188>
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
lea    0xd5f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    -0x48(%rbp),%rax
mov    %rax,%rsp
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_test_errno>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r8,%r13
mov    %rcx,%r15
mov    %rdx,-0x40(%rbp)
mov    %rsi,-0x50(%rbp)
mov    %rdi,-0x48(%rbp)
lea    0xebe(%rip),%rbx
mov    %rbx,%rcx
test   %r15,%r15
je     119d <_test_errno+0x3d>
mov    %r15,%rdi
call   1080 <strerror@plt>
mov    %rax,%rcx
lea    0xe5c(%rip),%rsi
lea    -0x38(%rbp),%rdi
mov    %r15,%rdx
call   1070 <asprintf@plt>
test   %r13,%r13
je     11c0 <_test_errno+0x60>
mov    %r13,%rdi
call   1080 <strerror@plt>
mov    %rax,%rbx
lea    0xe39(%rip),%rsi
lea    -0x30(%rbp),%rdi
mov    %r13,%rdx
mov    %rbx,%rcx
call   1070 <asprintf@plt>
mov    %rsp,%r12
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%r14
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r14
mov    %r14,%rsp
lea    0xe0d(%rip),%rax
lea    0xe0b(%rip),%rbx
cmp    %r13,%r15
cmove  %rax,%rbx
jne    1230 <_test_errno+0xd0>
movb   $0x0,(%r14)
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdfe(%rip),%rdi
mov    %rbx,%rcx
mov    -0x40(%rbp),%r8
mov    %r14,%r9
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1281 <_test_errno+0x121>
lea    0xdda(%rip),%rdx
mov    %r14,%rdi
mov    -0x48(%rbp),%r13
mov    %r13,%rcx
mov    -0x50(%rbp),%r15
mov    %r15,%r8
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xdbf(%rip),%rdi
mov    %rbx,%rcx
mov    -0x40(%rbp),%r8
mov    %r14,%r9
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xdcc(%rip),%rdi
mov    %r13,%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    %r12,%rsp
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"%ld\09%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"PASS\00"
@.str.3 = [5 x i8] c"FAIL\00"
@BUFSIZ = global i32 0
@.str.4 = [10 x i8] c" (%s:%ld)\00"
@.str.5 = [37 x i8] c"\09Actual: %s\0A\09Expected: %s\0A[%s] %s%s\0A\00"
@.str.6 = [9 x i8] c"\09%s:%ld\0A\00"
@stdout = global i32 0
define void @_test_errno(i8* %0, i64 %1, i8* %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i64
store i8* %0, i8** %6
store i64 %1, i64* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i64 %4, i64* %10
%16 = load i64, i64* %9
%17 = load i64, i64* %9
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %22
19: ; preds = %5
%20 = load i64, i64* %9
%21 = call i8* @strerror(i64 %20)
br label %23
22: ; preds = %5
br label %23
23: ; preds = %22, %19
%24 = phi i8* [ %21, %19 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %22 ]
%25 = call i32 @asprintf(i8** %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %16, i8* %24)
%26 = load i64, i64* %10
%27 = load i64, i64* %10
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %32
29: ; preds = %23
%30 = load i64, i64* %10
%31 = call i8* @strerror(i64 %30)
br label %33
32: ; preds = %23
br label %33
33: ; preds = %32, %29
%34 = phi i8* [ %31, %29 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %32 ]
%35 = call i32 @asprintf(i8** %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %26, i8* %34)
br label %36
36: ; preds = %33
%37 = load i64, i64* %9
%38 = load i64, i64* %10
%39 = icmp eq i64 %37, %38
%40 = zext i1 %39 to i64
%41 = select i1 %39, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
store i8* %41, i8** %13
%42 = load i32, i32* @BUFSIZ
%43 = zext i32 %42 to i64
%44 = call i8* @llvm.stacksave()
store i8* %44, i8** %14
%45 = alloca i8, i64 %43
store i64 %43, i64* %15
%46 = load i64, i64* %9
%47 = load i64, i64* %10
%48 = icmp eq i64 %46, %47
br i1 %48, label %54, label %49
49: ; preds = %36
%50 = trunc i64 %43 to i32
%51 = load i8*, i8** %6
%52 = load i64, i64* %7
%53 = call i32 @snprintf(i8* %45, i32 %50, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %51, i64 %52)
br label %56
54: ; preds = %36
%55 = getelementptr inbounds i8, i8* %45, i64 0
store i8 0, i8* %55
br label %56
56: ; preds = %54, %49
%57 = load i8*, i8** %11
%58 = load i8*, i8** %12
%59 = load i8*, i8** %13
%60 = load i8*, i8** %8
%61 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %57, i8* %58, i8* %59, i8* %60, i8* %45)
%62 = load i64, i64* %9
%63 = load i64, i64* %10
%64 = icmp eq i64 %62, %63
br i1 %64, label %69, label %65
65: ; preds = %56
%66 = load i8*, i8** %6
%67 = load i64, i64* %7
%68 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %66, i64 %67)
br label %69
69: ; preds = %65, %56
%70 = load i32, i32* @stdout
%71 = call i32 @fflush(i32 %70)
%72 = load i8*, i8** %14
br label %73
73: ; preds = %69
%74 = load i8*, i8** %11
%75 = call i32 @free(i8* %74)
%76 = load i8*, i8** %12
%77 = call i32 @free(i8* %76)
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"%ld\09%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [5 x i8] c"PASS\00"
@.str.3 = [5 x i8] c"FAIL\00"
@BUFSIZ = global i32 0
@.str.4 = [10 x i8] c" (%s:%ld)\00"
@.str.5 = [37 x i8] c"\09Actual: %s\0A\09Expected: %s\0A[%s] %s%s\0A\00"
@.str.6 = [9 x i8] c"\09%s:%ld\0A\00"
@stdout = global i32 0
define void @_test_errno(i8* %0, i64 %1, i8* %2, i64 %3, i64 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = bitcast i8** %6 to i8*
%9 = bitcast i8** %7 to i8*
%10 = icmp eq i64 %3, 0
br i1 %10, label %13, label %11
11: ; preds = %5
%12 = tail call i8* @strerror(i64 %3)
br label %13
13: ; preds = %5, %11
%14 = phi i8* [ %12, %11 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %5 ]
%15 = call i32 @asprintf(i8** %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %3, i8* %14)
%16 = icmp eq i64 %4, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = call i8* @strerror(i64 %4)
br label %19
19: ; preds = %13, %17
%20 = phi i8* [ %18, %17 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %13 ]
%21 = call i32 @asprintf(i8** %7, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 %4, i8* %20)
%22 = icmp eq i64 %3, %4
%23 = select i1 %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0)
%24 = load i32, i32* @BUFSIZ
%25 = zext i32 %24 to i64
%26 = call i8* @llvm.stacksave()
%27 = alloca i8, i64 %25
br i1 %22, label %28, label %32
28: ; preds = %19
store i8 0, i8* %27
%29 = load i8*, i8** %6
%30 = load i8*, i8** %7
%31 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %29, i8* %30, i8* %23, i8* %2, i8* %27)
br label %38
32: ; preds = %19
%33 = call i32 @snprintf(i8* %27, i32 %24, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %0, i64 %1)
%34 = load i8*, i8** %6
%35 = load i8*, i8** %7
%36 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.5, i64 0, i64 0), i8* %34, i8* %35, i8* %23, i8* %2, i8* %27)
%37 = call i32 (i8*, i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i8* %0, i64 %1)
br label %38
38: ; preds = %28, %32
%39 = load i32, i32* @stdout
%40 = call i32 @fflush(i32 %39)
%41 = load i8*, i8** %6
%42 = call i32 @free(i8* %41)
%43 = load i8*, i8** %7
%44 = call i32 @free(i8* %43)
ret void
}