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

/* Variables and functions */
char *gai_strerror(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *, char *);
char *strerror(int);
const char *net_error(int ret, int err) {
  const char *x;
  static char buffer[512];
  static const char *actions_errors[] = {
      "failed to resolve hostname", "no valid address",
      "failed to create socket",    "failed to bind socket",
      "failed to setup socket",     "failed to connect",
      "failed to receive",          "failed to send"};
  x = ((ret >= -8) && (ret < 0)) ? actions_errors[-ret - 1] : "???";
  snprintf(buffer, sizeof(buffer) - 1, "%s (%s)", x,
           (ret == -1 ? gai_strerror(err) : strerror(err)));
  return (const char *)buffer;
}


x86 assembly (clang, -O0):
<net_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
cmpl   $0xfffffff8,-0x4(%rbp)
jl     1171 <net_error+0x41>
cmpl   $0x0,-0x4(%rbp)
jge    1171 <net_error+0x41>
xor    %eax,%eax
sub    -0x4(%rbp),%eax
sub    $0x1,%eax
movslq %eax,%rcx
lea    0x2edc(%rip),%rax
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    1181 <net_error+0x51>
lea    0xf2c(%rip),%rax
mov    %rax,-0x18(%rbp)
jmp    1181 <net_error+0x51>
mov    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11ac <net_error+0x7c>
mov    -0x8(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    %rax,-0x28(%rbp)
jmp    11b8 <net_error+0x88>
mov    -0x8(%rbp),%edi
call   1050 <strerror@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0x2ec9(%rip),%rdi
mov    $0x1ff,%esi
lea    0xed5(%rip),%rdx
call   1030 <snprintf@plt>
lea    0x2eb1(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<net_error>:
push   %r14
push   %rbx
push   %rax
cmp    $0xfffffff8,%edi
jb     1154 <net_error+0x24>
cmp    $0xffffffff,%edi
not    %edi
lea    0x2c9b(%rip),%rax
mov    (%rax,%rdi,8),%r14
jne    115b <net_error+0x2b>
mov    %esi,%edi
call   1040 <gai_strerror@plt>
jmp    1162 <net_error+0x32>
lea    0xf49(%rip),%r14
mov    %esi,%edi
call   1050 <strerror@plt>
lea    0x2ee7(%rip),%rbx
lea    0xf38(%rip),%rdx
mov    %rbx,%rdi
mov    $0x1ff,%esi
mov    %r14,%rcx
mov    %rax,%r8
call   1030 <snprintf@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@net_error.buffer = internal global [512 x i8] zeroinitializer
@net_error.actions_errors = internal global [8 x i8*] [i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0)]
@.str = [27 x i8] c"failed to resolve hostname\00"
@.str.1 = [17 x i8] c"no valid address\00"
@.str.2 = [24 x i8] c"failed to create socket\00"
@.str.3 = [22 x i8] c"failed to bind socket\00"
@.str.4 = [23 x i8] c"failed to setup socket\00"
@.str.5 = [18 x i8] c"failed to connect\00"
@.str.6 = [18 x i8] c"failed to receive\00"
@.str.7 = [15 x i8] c"failed to send\00"
@.str.8 = [4 x i8] c"???\00"
@.str.9 = [8 x i8] c"%s (%s)\00"
define i8* @net_error(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = icmp sge i32 %6, -8
br i1 %7, label %8, label %18
8: ; preds = %2
%9 = load i32, i32* %3
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %8
%12 = load i32, i32* %3
%13 = sub nsw i32 0, %12
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [8 x i8*], [8 x i8*]* @net_error.actions_errors, i64 0, i64 %15
%17 = load i8*, i8** %16
br label %19
18: ; preds = %8, %2
br label %19
19: ; preds = %18, %11
%20 = phi i8* [ %17, %11 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), %18 ]
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = load i32, i32* %3
%23 = icmp eq i32 %22, -1
br i1 %23, label %24, label %27
24: ; preds = %19
%25 = load i32, i32* %4
%26 = call i8* @gai_strerror(i32 %25)
br label %30
27: ; preds = %19
%28 = load i32, i32* %4
%29 = call i8* @strerror(i32 %28)
br label %30
30: ; preds = %27, %24
%31 = phi i8* [ %26, %24 ], [ %29, %27 ]
%32 = call i32 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @net_error.buffer, i64 0, i64 0), i32 511, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %21, i8* %31)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @net_error.buffer, i64 0, i64 0)
}

LLVM IR (-O2):
@net_error.buffer = internal global [512 x i8] zeroinitializer
@net_error.actions_errors = internal unnamed_addr constant [8 x i8*] [i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.7, i32 0, i32 0)]
@.str = [27 x i8] c"failed to resolve hostname\00"
@.str.1 = [17 x i8] c"no valid address\00"
@.str.2 = [24 x i8] c"failed to create socket\00"
@.str.3 = [22 x i8] c"failed to bind socket\00"
@.str.4 = [23 x i8] c"failed to setup socket\00"
@.str.5 = [18 x i8] c"failed to connect\00"
@.str.6 = [18 x i8] c"failed to receive\00"
@.str.7 = [15 x i8] c"failed to send\00"
@.str.8 = [4 x i8] c"???\00"
@.str.9 = [8 x i8] c"%s (%s)\00"
define i8* @net_error(i32 %0, i32 %1) {
%3 = icmp ugt i32 %0, -9
br i1 %3, label %4, label %12
4: ; preds = %2
%5 = xor i32 %0, -1
%6 = zext i32 %5 to i64
%7 = getelementptr inbounds [8 x i8*], [8 x i8*]* @net_error.actions_errors, i64 0, i64 %6
%8 = load i8*, i8** %7
%9 = icmp eq i32 %0, -1
br i1 %9, label %10, label %12
10: ; preds = %4
%11 = tail call i8* @gai_strerror(i32 %1)
br label %15
12: ; preds = %2, %4
%13 = phi i8* [ %8, %4 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), %2 ]
%14 = tail call i8* @strerror(i32 %1)
br label %15
15: ; preds = %12, %10
%16 = phi i8* [ %8, %10 ], [ %13, %12 ]
%17 = phi i8* [ %11, %10 ], [ %14, %12 ]
%18 = tail call i32 @snprintf(i8* getelementptr inbounds ([512 x i8], [512 x i8]* @net_error.buffer, i64 0, i64 0), i32 511, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.9, i64 0, i64 0), i8* %16, i8* %17)
ret i8* getelementptr inbounds ([512 x i8], [512 x i8]* @net_error.buffer, i64 0, i64 0)
}