#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*/ err();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printstr(char const *);
void test_getaddrinfo_err(int n, const char *nodename, const char *servname,
                          int passhints, int flags, int family, int socktype,
                          const char *exp_result, const char *result) {
  printf("error %d: getaddrinfo(", n);
  printstr(nodename);
  printf(", ");
  printstr(servname);
  printf(", ");
  if (passhints)
    printf("{ 0x%x, %d, %d }", flags, family, socktype);
  else
    printf("NULL");
  printf("); result: ");
  printstr(result);
  printf("; expected: ");
  printstr(exp_result);
  printf("\n");
  err();
}


x86 assembly (clang, -O0):
<test_getaddrinfo_err>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%eax
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x4(%rbp),%esi
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <printstr@plt>
lea    0xe9d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <printstr@plt>
lea    0xe86(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
je     11be <test_getaddrinfo_err+0x8e>
mov    -0x20(%rbp),%esi
mov    -0x24(%rbp),%edx
mov    0x10(%rbp),%ecx
lea    0xe68(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11cc <test_getaddrinfo_err+0x9c>
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x20(%rbp),%rdi
call   1040 <printstr@plt>
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    0x18(%rbp),%rdi
call   1040 <printstr@plt>
lea    0xe48(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1050 <err@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getaddrinfo_err>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0x4(%rsp)
mov    %r8d,%r13d
mov    %ecx,%ebx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %edi,%esi
mov    0x60(%rsp),%rax
mov    %rax,0x8(%rsp)
mov    0x58(%rsp),%rax
mov    %rax,0x10(%rsp)
mov    0x50(%rsp),%r12d
lea    0xe80(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r15,%rdi
call   1050 <printstr@plt>
lea    0xe81(%rip),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r14,%rdi
call   1050 <printstr@plt>
mov    %rbp,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
test   %ebx,%ebx
je     11d0 <test_getaddrinfo_err+0x90>
lea    0xe5d(%rip),%rdi
mov    %r13d,%esi
mov    0x4(%rsp),%edx
mov    %r12d,%ecx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11de <test_getaddrinfo_err+0x9e>
lea    0xe54(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4b(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x8(%rsp),%rdi
call   1050 <printstr@plt>
lea    0xe3f(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x10(%rsp),%rdi
call   1050 <printstr@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <err@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"error %d: getaddrinfo(\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [17 x i8] c"{ 0x%x, %d, %d }\00"
@.str.3 = [5 x i8] c"NULL\00"
@.str.4 = [12 x i8] c"); result: \00"
@.str.5 = [13 x i8] c"; expected: \00"
@.str.6 = [2 x i8] c"\0A\00"
define void @test_getaddrinfo_err(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i8* %7, i8* %8) {
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca i8*
%18 = alloca i8*
store i32 %0, i32* %10
store i8* %1, i8** %11
store i8* %2, i8** %12
store i32 %3, i32* %13
store i32 %4, i32* %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i8* %7, i8** %17
store i8* %8, i8** %18
%19 = load i32, i32* %10
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %11
%22 = call i32 @printstr(i8* %21)
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%24 = load i8*, i8** %12
%25 = call i32 @printstr(i8* %24)
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* %13
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %9
%30 = load i32, i32* %14
%31 = load i32, i32* %15
%32 = load i32, i32* %16
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %30, i32 %31, i32 %32)
br label %36
34: ; preds = %9
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %29
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%38 = load i8*, i8** %18
%39 = call i32 @printstr(i8* %38)
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%41 = load i8*, i8** %17
%42 = call i32 @printstr(i8* %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%44 = call i32 (...) @err()
ret void
}

LLVM IR (-O2):
@.str = [23 x i8] c"error %d: getaddrinfo(\00"
@.str.1 = [3 x i8] c", \00"
@.str.2 = [17 x i8] c"{ 0x%x, %d, %d }\00"
@.str.3 = [5 x i8] c"NULL\00"
@.str.4 = [12 x i8] c"); result: \00"
@.str.5 = [13 x i8] c"; expected: \00"
define void @test_getaddrinfo_err(i32 %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5, i32 %6, i8* %7, i8* %8) {
%10 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i32 %0)
%11 = tail call i32 @printstr(i8* %1)
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%13 = tail call i32 @printstr(i8* %2)
%14 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%15 = icmp eq i32 %3, 0
br i1 %15, label %18, label %16
16: ; preds = %9
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %4, i32 %5, i32 %6)
br label %20
18: ; preds = %9
%19 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18, %16
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
%22 = tail call i32 @printstr(i8* %8)
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0))
%24 = tail call i32 @printstr(i8* %7)
%25 = tail call i32 @putchar(i32 10)
%26 = tail call i32 (...) @err()
ret void
}