#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*/ log_d(char *, char const *, ...);
char *strerror(int);
void lerror(const char *s) {
  int saved_errno;
  char *errmsg;
  saved_errno = errno;
  errmsg = strerror(errno);
  if (s && *s)
    log_d("%s: %s", s, errmsg ? errmsg : "???");
  else
    log_d("%s", errmsg ? errmsg : "???");
  errno = saved_errno;
}


x86 assembly (clang, -O0):
<lerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ead(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     11b0 <lerror+0x90>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11b0 <lerror+0x90>
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1185 <lerror+0x65>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
jmp    1195 <lerror+0x75>
lea    0xe7b(%rip),%rax
mov    %rax,-0x28(%rbp)
jmp    1195 <lerror+0x75>
mov    -0x20(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1030 <log_d@plt>
jmp    11ea <lerror+0xca>
cmpq   $0x0,-0x18(%rbp)
je     11c8 <lerror+0xa8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11d8 <lerror+0xb8>
lea    0xe38(%rip),%rax
mov    %rax,-0x30(%rbp)
jmp    11d8 <lerror+0xb8>
mov    -0x30(%rbp),%rsi
lea    0xe21(%rip),%rdi
mov    $0x0,%al
call   1030 <log_d@plt>
mov    -0xc(%rbp),%ecx
mov    0x2dec(%rip),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lerror>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eb2(%rip),%r14
mov    (%r14),%ebp
mov    %ebp,%edi
call   1040 <strerror@plt>
test   %rbx,%rbx
je     1163 <lerror+0x43>
cmpb   $0x0,(%rbx)
je     1163 <lerror+0x43>
test   %rax,%rax
lea    0xebb(%rip),%rdx
cmovne %rax,%rdx
lea    0xea9(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <log_d@plt>
jmp    117f <lerror+0x5f>
test   %rax,%rax
lea    0xe9a(%rip),%rsi
cmovne %rax,%rsi
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1030 <log_d@plt>
mov    %ebp,(%r14)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i32 0
@.str = [7 x i8] c"%s: %s\00"
@.str.1 = [4 x i8] c"???\00"
@.str.2 = [3 x i8] c"%s\00"
define void @lerror(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i32, i32* @errno
store i32 %5, i32* %3
%6 = load i32, i32* @errno
%7 = call i8* @strerror(i32 %6)
store i8* %7, i8** %4
%8 = load i8*, i8** %2
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %25
10: ; preds = %1
%11 = load i8*, i8** %2
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %25
15: ; preds = %10
%16 = load i8*, i8** %2
%17 = load i8*, i8** %4
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = load i8*, i8** %4
br label %22
21: ; preds = %15
br label %22
22: ; preds = %21, %19
%23 = phi i8* [ %20, %19 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %21 ]
%24 = call i32 (i8*, i8*, ...) @log_d(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %23)
br label %34
25: ; preds = %10, %1
%26 = load i8*, i8** %4
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %30
28: ; preds = %25
%29 = load i8*, i8** %4
br label %31
30: ; preds = %25
br label %31
31: ; preds = %30, %28
%32 = phi i8* [ %29, %28 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %30 ]
%33 = call i32 (i8*, i8*, ...) @log_d(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %31, %22
%35 = load i32, i32* %3
store i32 %35, i32* @errno
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [7 x i8] c"%s: %s\00"
@.str.1 = [4 x i8] c"???\00"
@.str.2 = [3 x i8] c"%s\00"
define void @lerror(i8* %0) {
%2 = load i32, i32* @errno
%3 = tail call i8* @strerror(i32 %2)
%4 = icmp eq i8* %0, null
br i1 %4, label %12, label %5
5: ; preds = %1
%6 = load i8, i8* %0
%7 = icmp eq i8 %6, 0
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = icmp eq i8* %3, null
%10 = select i1 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3
%11 = tail call i32 (i8*, i8*, ...) @log_d(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %10)
br label %16
12: ; preds = %5, %1
%13 = icmp eq i8* %3, null
%14 = select i1 %13, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %3
%15 = tail call i32 (i8*, i8*, ...) @log_d(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %12, %8
store i32 %2, i32* @errno
ret void
}