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

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, int);
const char *gai_strerror(int errcode) {
  static char customerr[64];
  switch (errcode) {
  case 5:
    return "ai_family not supported";
  case 7:
    return "no address associated with hostname";
  case 8:
    return "hostname nor servname provided, or not known";
  default:
    snprintf(customerr, sizeof(customerr), "unknown error (%d)", errcode);
    return "unknown error.";
  }
  return NULL;
}


x86 assembly (clang, -O0):
<gai_strerror>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x5,%eax
je     1151 <gai_strerror+0x41>
jmp    112f <gai_strerror+0x1f>
mov    -0x10(%rbp),%eax
sub    $0x7,%eax
je     1161 <gai_strerror+0x51>
jmp    1140 <gai_strerror+0x30>
mov    -0x10(%rbp),%eax
sub    $0x8,%eax
je     1171 <gai_strerror+0x61>
jmp    1181 <gai_strerror+0x71>
lea    0xea8(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a7 <gai_strerror+0x97>
lea    0xeb0(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a7 <gai_strerror+0x97>
lea    0xec4(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11a7 <gai_strerror+0x97>
mov    -0xc(%rbp),%ecx
lea    0x2eb5(%rip),%rdi
mov    $0x40,%esi
lea    0xed2(%rip),%rdx
call   1030 <snprintf@plt>
lea    0xed9(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gai_strerror>:
cmp    $0x5,%edi
je     1129 <gai_strerror+0x19>
mov    %edi,%ecx
cmp    $0x8,%edi
je     1131 <gai_strerror+0x21>
cmp    $0x7,%ecx
jne    1139 <gai_strerror+0x29>
lea    0xef0(%rip),%rax
ret
lea    0xed0(%rip),%rax
ret
lea    0xf04(%rip),%rax
ret
push   %rax
lea    0x2eff(%rip),%rdi
lea    0xf21(%rip),%rdx
mov    $0x40,%esi
call   1030 <snprintf@plt>
lea    0xf23(%rip),%rax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@gai_strerror.customerr = internal global [64 x i8] zeroinitializer
@.str = [24 x i8] c"ai_family not supported\00"
@.str.1 = [36 x i8] c"no address associated with hostname\00"
@.str.2 = [45 x i8] c"hostname nor servname provided, or not known\00"
@.str.3 = [19 x i8] c"unknown error (%d)\00"
@.str.4 = [15 x i8] c"unknown error.\00"
define i8* @gai_strerror(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
store i32 %0, i32* %3
%4 = load i32, i32* %3
switch i32 %4, label %8 [
i32 5, label %5
i32 7, label %6
i32 8, label %7
]
5: ; preds = %1
store i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), i8** %2
br label %11
6: ; preds = %1
store i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %11
7: ; preds = %1
store i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %11
8: ; preds = %1
%9 = load i32, i32* %3
%10 = call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @gai_strerror.customerr, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %9)
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), i8** %2
br label %11
11: ; preds = %8, %7, %6, %5
%12 = load i8*, i8** %2
ret i8* %12
}

LLVM IR (-O2):
@gai_strerror.customerr = internal global [64 x i8] zeroinitializer
@.str = [24 x i8] c"ai_family not supported\00"
@.str.1 = [36 x i8] c"no address associated with hostname\00"
@.str.2 = [45 x i8] c"hostname nor servname provided, or not known\00"
@.str.3 = [19 x i8] c"unknown error (%d)\00"
@.str.4 = [15 x i8] c"unknown error.\00"
define i8* @gai_strerror(i32 %0) {
switch i32 %0, label %4 [
i32 5, label %6
i32 7, label %2
i32 8, label %3
]
2: ; preds = %1
br label %6
3: ; preds = %1
br label %6
4: ; preds = %1
%5 = tail call i32 @snprintf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @gai_strerror.customerr, i64 0, i64 0), i32 64, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i32 %0)
br label %6
6: ; preds = %1, %4, %3, %2
%7 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), %4 ], [ getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %7
}