#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 errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *,
                           unsigned int, int, char const *);
char *lace_compat_file_basename(char const *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
int lace_compat_errno_trace_(const char *file, const char *func,
                             unsigned line) {
  int e = errno;
  if (e != 0) {
    file = lace_compat_file_basename(file);
    fprintf(stderr, "TRACE %s(%u): Errno %d in %s.\n", file, line, e, func);
    errno = e;
    perror("TRACE perror");
  }
  errno = 0;
  return e;
}


x86 assembly (clang, -O0):
<lace_compat_errno_trace_>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    0x2e8e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     11a2 <lace_compat_errno_trace_+0x72>
mov    -0x8(%rbp),%rdi
call   1030 <lace_compat_file_basename@plt>
mov    %rax,-0x8(%rbp)
mov    0x2e73(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    -0x18(%rbp),%r8d
mov    -0x10(%rbp),%r9
lea    0xe7b(%rip),%rsi
call   1040 <fprintf@plt>
mov    -0x18(%rbp),%ecx
mov    0x2e44(%rip),%rax
mov    %ecx,(%rax)
lea    0xe82(%rip),%rdi
call   1050 <perror@plt>
mov    0x2e2f(%rip),%rax
movl   $0x0,(%rax)
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lace_compat_errno_trace_>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    0x2e9a(%rip),%rbp
mov    0x0(%rbp),%ebx
test   %ebx,%ebx
jne    1159 <lace_compat_errno_trace_+0x29>
movl   $0x0,0x0(%rbp)
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edx,%r15d
mov    %rsi,%r14
call   1030 <lace_compat_file_basename@plt>
mov    0x2e75(%rip),%rcx
mov    (%rcx),%edi
lea    0xe8c(%rip),%rsi
mov    %rax,%rdx
mov    %r15d,%ecx
mov    %ebx,%r8d
mov    %r14,%r9
call   1040 <fprintf@plt>
mov    %ebx,0x0(%rbp)
lea    0xe90(%rip),%rdi
call   1050 <perror@plt>
jmp    1145 <lace_compat_errno_trace_+0x15>

LLVM IR (-O0):
@errno = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"TRACE %s(%u): Errno %d in %s.\0A\00"
@.str.1 = [13 x i8] c"TRACE perror\00"
define i32 @lace_compat_errno_trace_(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* @errno
store i32 %8, i32* %7
%9 = load i32, i32* %7
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %3
%12 = load i8*, i8** %4
%13 = call i8* @lace_compat_file_basename(i8* %12)
store i8* %13, i8** %4
%14 = load i32, i32* @stderr
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = load i8*, i8** %5
%19 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %16, i32 %17, i8* %18)
%20 = load i32, i32* %7
store i32 %20, i32* @errno
%21 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %22
22: ; preds = %11, %3
store i32 0, i32* @errno
%23 = load i32, i32* %7
ret i32 %23
}

LLVM IR (-O2):
@errno = global i32 0
@stderr = global i32 0
@.str = [31 x i8] c"TRACE %s(%u): Errno %d in %s.\0A\00"
@.str.1 = [13 x i8] c"TRACE perror\00"
define i32 @lace_compat_errno_trace_(i8* %0, i8* %1, i32 %2) {
%4 = load i32, i32* @errno
%5 = icmp eq i32 %4, 0
br i1 %5, label %11, label %6
6: ; preds = %3
%7 = tail call i8* @lace_compat_file_basename(i8* %0)
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %7, i32 %2, i32 %4, i8* %1)
store i32 %4, i32* @errno
%10 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %6, %3
store i32 0, i32* @errno
ret i32 %4
}