#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 */
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ service;
typedef int /*<<< orphan*/ host;

/* Variables and functions */
int /*<<< orphan*/ err_quit(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ gai_strerror(int);
int getnameinfo(struct sockaddr *, int, char *, int, char *, int,
                int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *, char *);
void test_getnameinfo(struct sockaddr *addr, int addrlen) {
  char host[128];
  char service[128];
  int err = getnameinfo(addr, addrlen, host, sizeof(host), service,
                        sizeof(service), 0);
  if (err != 0)
    err_quit("\n\tgetnameinfo error %d: %s", err, gai_strerror(err));
  printf("\n\tgetnameinfo back: %s, %s\n", host, service);
}


x86 assembly (clang, -O0):
<test_getnameinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
lea    -0x90(%rbp),%rdx
lea    -0x110(%rbp),%r8
mov    $0x80,%r9d
xor    %eax,%eax
mov    %r9d,%ecx
movl   $0x0,(%rsp)
call   1050 <getnameinfo@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
je     11bc <test_getnameinfo+0x7c>
mov    -0x114(%rbp),%eax
mov    %eax,-0x118(%rbp)
mov    -0x114(%rbp),%edi
call   1040 <gai_strerror@plt>
mov    -0x118(%rbp),%esi
mov    %eax,%edx
lea    0xe49(%rip),%rdi
call   1060 <err_quit@plt>
lea    -0x90(%rbp),%rsi
lea    -0x110(%rbp),%rdx
lea    0xe4a(%rip),%rdi
call   1030 <printf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getnameinfo>:
push   %rbx
sub    $0x110,%rsp
movl   $0x0,(%rsp)
lea    0x90(%rsp),%rdx
lea    0x10(%rsp),%r8
mov    $0x80,%ecx
mov    $0x80,%r9d
call   1050 <getnameinfo@plt>
test   %eax,%eax
je     1189 <test_getnameinfo+0x49>
mov    %eax,%ebx
mov    %eax,%edi
call   1040 <gai_strerror@plt>
lea    0xe80(%rip),%rdi
mov    %ebx,%esi
mov    %eax,%edx
call   1060 <err_quit@plt>
lea    0xe8b(%rip),%rdi
lea    0x90(%rsp),%rsi
lea    0x10(%rsp),%rdx
call   1030 <printf@plt>
add    $0x110,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"\0A\09getnameinfo error %d: %s\00"
@.str.1 = [28 x i8] c"\0A\09getnameinfo back: %s, %s\0A\00"
define void @test_getnameinfo(%struct.sockaddr* %0, i32 %1) {
%3 = alloca %struct.sockaddr*
%4 = alloca i32
%5 = alloca [128 x i8]
%6 = alloca [128 x i8]
%7 = alloca i32
store %struct.sockaddr* %0, %struct.sockaddr** %3
store i32 %1, i32* %4
%8 = load %struct.sockaddr*, %struct.sockaddr** %3
%9 = load i32, i32* %4
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%12 = call i32 @getnameinfo(%struct.sockaddr* %8, i32 %9, i8* %10, i32 128, i8* %11, i32 128, i32 0)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = load i32, i32* %7
%17 = load i32, i32* %7
%18 = call i32 @gai_strerror(i32 %17)
%19 = call i32 @err_quit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %16, i32 %18)
br label %20
20: ; preds = %15, %2
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%23 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8* %22)
ret void
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@.str = [27 x i8] c"\0A\09getnameinfo error %d: %s\00"
@.str.1 = [28 x i8] c"\0A\09getnameinfo back: %s, %s\0A\00"
define void @test_getnameinfo(%struct.sockaddr* %0, i32 %1) {
%3 = alloca [128 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%7 = call i32 @getnameinfo(%struct.sockaddr* %0, i32 %1, i8* %5, i32 128, i8* %6, i32 128, i32 0)
%8 = icmp eq i32 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %2
%10 = call i32 @gai_strerror(i32 %7)
%11 = call i32 @err_quit(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i32 %7, i32 %10)
br label %12
12: ; preds = %9, %2
%13 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0), i8* %5, i8* %6)
ret void
}