#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*/ errno;
int /*<<< orphan*/ pcap_snprintf(char *, int, char *, char const *, char *,
                                 ...);
char *strerror(int /*<<< orphan*/);
void sock_geterror(const char *caller, char *errbuf, int errbuflen) {
  char *message;
  if (errbuf == NULL)
    return;
  message = strerror(errno);
  if ((caller) && (*caller))
    pcap_snprintf(errbuf, errbuflen, "%s%s (code %d)", caller, message, errno);
  else
    pcap_snprintf(errbuf, errbuflen, "%s (code %d)", message, errno);
}


x86 assembly (clang, -O0):
<sock_geterror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1143 <sock_geterror+0x23>
jmp    11bf <sock_geterror+0x9f>
mov    0x2e96(%rip),%rax
mov    (%rax),%edi
call   1040 <strerror@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     119c <sock_geterror+0x7c>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     119c <sock_geterror+0x7c>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    0x2e5a(%rip),%rax
mov    (%rax),%r9d
lea    0xe70(%rip),%rdx
mov    $0x0,%al
call   1030 <pcap_snprintf@plt>
jmp    11bf <sock_geterror+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    0x2e32(%rip),%rax
movslq (%rax),%r8
lea    0xe4a(%rip),%rdx
mov    $0x0,%al
call   1030 <pcap_snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sock_geterror>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %rsi,%rsi
je     1176 <sock_geterror+0x56>
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    0x2ea4(%rip),%r15
mov    (%r15),%edi
call   1040 <strerror@plt>
test   %rbp,%rbp
je     1181 <sock_geterror+0x61>
cmpb   $0x0,0x0(%rbp)
je     1181 <sock_geterror+0x61>
mov    (%r15),%r9d
lea    0xea7(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rbp,%rcx
mov    %rax,%r8
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <pcap_snprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movslq (%r15),%r8
lea    0xe77(%rip),%rdx
mov    %rbx,%rdi
mov    %r14d,%esi
mov    %rax,%rcx
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <pcap_snprintf@plt>

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

LLVM IR (-O2):
@errno = global i32 0
@.str = [15 x i8] c"%s%s (code %d)\00"
@.str.1 = [13 x i8] c"%s (code %d)\00"
define void @sock_geterror(i8* %0, i8* %1, i32 %2) {
%4 = icmp eq i8* %1, null
br i1 %4, label %20, label %5
5: ; preds = %3
%6 = load i32, i32* @errno
%7 = tail call i8* @strerror(i32 %6)
%8 = icmp eq i8* %0, null
br i1 %8, label %15, label %9
9: ; preds = %5
%10 = load i8, i8* %0
%11 = icmp eq i8 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %9
%13 = load i32, i32* @errno
%14 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @pcap_snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %7, i32 %13)
br label %20
15: ; preds = %9, %5
%16 = load i32, i32* @errno
%17 = sext i32 %16 to i64
%18 = inttoptr i64 %17 to i8*
%19 = tail call i32 (i8*, i32, i8*, i8*, i8*, ...) @pcap_snprintf(i8* %1, i32 %2, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %18)
br label %20
20: ; preds = %12, %15, %3
ret void
}