const char *s_gai_strerror(int err) {
  switch (err) {
  case 2:
    return "Neither nodename nor servname known (EAI_NONAME)";
  case 8:
    return "servname is not supported for ai_socktype (EAI_SERVICE)";
  case 1:
    return "Memory allocation failure (EAI_MEMORY)";
  default:
    return "Unknown error";
  }
}


x86 assembly (clang, -O0):
<s_gai_strerror>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
sub    $0x1,%eax
je     115d <s_gai_strerror+0x5d>
jmp    111b <s_gai_strerror+0x1b>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
je     113d <s_gai_strerror+0x3d>
jmp    112c <s_gai_strerror+0x2c>
mov    -0x10(%rbp),%eax
sub    $0x8,%eax
je     114d <s_gai_strerror+0x4d>
jmp    116d <s_gai_strerror+0x6d>
lea    0xebc(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <s_gai_strerror+0x78>
lea    0xedd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <s_gai_strerror+0x78>
lea    0xf05(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    1178 <s_gai_strerror+0x78>
lea    0xf1c(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
pop    %rbp
ret

x86 assembly (clang, -O2):
<s_gai_strerror>:
cmp    $0x1,%edi
je     1117 <s_gai_strerror+0x17>
cmp    $0x2,%edi
je     111f <s_gai_strerror+0x1f>
cmp    $0x8,%edi
jne    1127 <s_gai_strerror+0x27>
lea    0xf1b(%rip),%rax
ret
lea    0xf4b(%rip),%rax
ret
lea    0xeda(%rip),%rax
ret
lea    0xf62(%rip),%rax
ret

LLVM IR (-O0):
@.str = [49 x i8] c"Neither nodename nor servname known (EAI_NONAME)\00"
@.str.1 = [56 x i8] c"servname is not supported for ai_socktype (EAI_SERVICE)\00"
@.str.2 = [39 x i8] c"Memory allocation failure (EAI_MEMORY)\00"
@.str.3 = [14 x i8] c"Unknown error\00"
define i8* @s_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 2, label %5
i32 8, label %6
i32 1, label %7
]
5: ; preds = %1
store i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i8** %2
br label %9
6: ; preds = %1
store i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %9
7: ; preds = %1
store i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i8** %2
br label %9
8: ; preds = %1
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), i8** %2
br label %9
9: ; preds = %8, %7, %6, %5
%10 = load i8*, i8** %2
ret i8* %10
}

LLVM IR (-O2):
@.str = [49 x i8] c"Neither nodename nor servname known (EAI_NONAME)\00"
@.str.1 = [56 x i8] c"servname is not supported for ai_socktype (EAI_SERVICE)\00"
@.str.2 = [39 x i8] c"Memory allocation failure (EAI_MEMORY)\00"
@.str.3 = [14 x i8] c"Unknown error\00"
define i8* @s_gai_strerror(i32 %0) {
switch i32 %0, label %4 [
i32 2, label %5
i32 8, label %2
i32 1, label %3
]
2: ; preds = %1
br label %5
3: ; preds = %1
br label %5
4: ; preds = %1
br label %5
5: ; preds = %1, %4, %3, %2
%6 = phi i8* [ getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0), %4 ], [ getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), %3 ], [ getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0), %2 ], [ getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), %1 ]
ret i8* %6
}