#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  unsigned long s_addr;
};
struct sockaddr_in {
  unsigned short sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef int /*<<< orphan*/ sockaddr;
typedef int /*<<< orphan*/ service;
typedef int /*<<< orphan*/ node;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ assert(int);
int getnameinfo(struct sockaddr *, int, char *, int, char *, int, int);
int /*<<< orphan*/ memsetl(char *, int, int);
scalar_t__ strcmp(char const *, char *);
int /*<<< orphan*/ test_getnameinfo_err(int, unsigned long, unsigned short, int,
                                        int, int, char const *, char *);
int /*<<< orphan*/ test_getnameinfo_err_nr(int, unsigned long, unsigned short,
                                           int, int, int, int, int);
void test_getnameinfo(unsigned long ipaddr, unsigned short port,
                      const char *exp_node, socklen_t nodelen,
                      const char *exp_service, socklen_t servicelen, int flags,
                      int exp_results) {
  struct sockaddr_in sockaddr;
  char node[256], service[256];
  int r;
  assert(nodelen <= sizeof(node));
  assert(servicelen <= sizeof(service));
  sockaddr.sin_family = AF_INET;
  sockaddr.sin_addr.s_addr = ipaddr;
  sockaddr.sin_port = port;
  memsetl(node, 0xDEADBEEF, nodelen);
  memsetl(service, 0xDEADBEEF, servicelen);
  r = getnameinfo((struct sockaddr *)&sockaddr, sizeof(sockaddr), node, nodelen,
                  service, servicelen, flags);
  if (r < 0 || r >= 32 || !((1 << r) & exp_results))
    test_getnameinfo_err_nr(1, ipaddr, port, nodelen, servicelen, flags,
                            exp_results, r);
  if (r)
    return;
  if (nodelen && strcmp(exp_node, node) != 0)
    test_getnameinfo_err(2, ipaddr, port, nodelen, servicelen, flags, exp_node,
                         node);
  if (servicelen && strcmp(exp_service, service) != 0)
    test_getnameinfo_err(2, ipaddr, port, nodelen, servicelen, flags,
                         exp_service, service);
}


x86 assembly (clang, -O0):
<test_getnameinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x270,%rsp
mov    %si,%ax
mov    0x18(%rbp),%esi
mov    0x10(%rbp),%esi
mov    %rdi,-0x8(%rbp)
mov    %ax,-0xa(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    $0x100,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
movslq -0x2c(%rbp),%rax
cmp    $0x100,%rax
setbe  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    0x2e28(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x38(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0xa(%rbp),%ax
mov    %ax,-0x48(%rbp)
lea    -0x150(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    $0xdeadbeef,%esi
call   1080 <memsetl@plt>
lea    -0x250(%rbp),%rdi
mov    -0x2c(%rbp),%edx
mov    $0xdeadbeef,%esi
call   1080 <memsetl@plt>
lea    -0x48(%rbp),%rdi
lea    -0x150(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    -0x250(%rbp),%r8
mov    -0x2c(%rbp),%r9d
mov    0x10(%rbp),%eax
mov    $0x18,%esi
mov    %eax,(%rsp)
call   1050 <getnameinfo@plt>
mov    %eax,-0x254(%rbp)
cmpl   $0x0,-0x254(%rbp)
jl     125f <test_getnameinfo+0xff>
cmpl   $0x20,-0x254(%rbp)
jge    125f <test_getnameinfo+0xff>
mov    -0x254(%rbp),%ecx
mov    $0x1,%eax
shl    %cl,%eax
and    0x18(%rbp),%eax
cmp    $0x0,%eax
jne    1291 <test_getnameinfo+0x131>
mov    -0x8(%rbp),%rsi
mov    -0xa(%rbp),%dx
mov    -0x1c(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    0x10(%rbp),%r9d
mov    0x18(%rbp),%r10d
mov    -0x254(%rbp),%eax
mov    $0x1,%edi
movzwl %dx,%edx
mov    %r10d,(%rsp)
mov    %eax,0x8(%rsp)
call   1030 <test_getnameinfo_err_nr@plt>
cmpl   $0x0,-0x254(%rbp)
je     12a3 <test_getnameinfo+0x143>
jmp    1353 <test_getnameinfo+0x1f3>
cmpl   $0x0,-0x1c(%rbp)
je     12fb <test_getnameinfo+0x19b>
mov    -0x18(%rbp),%rdi
lea    -0x150(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12fb <test_getnameinfo+0x19b>
mov    -0x8(%rbp),%rsi
mov    -0xa(%rbp),%dx
mov    -0x1c(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    0x10(%rbp),%r9d
mov    -0x18(%rbp),%r10
lea    -0x150(%rbp),%rax
mov    $0x2,%edi
movzwl %dx,%edx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <test_getnameinfo_err@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1353 <test_getnameinfo+0x1f3>
mov    -0x28(%rbp),%rdi
lea    -0x250(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1353 <test_getnameinfo+0x1f3>
mov    -0x8(%rbp),%rsi
mov    -0xa(%rbp),%dx
mov    -0x1c(%rbp),%ecx
mov    -0x2c(%rbp),%r8d
mov    0x10(%rbp),%r9d
mov    -0x28(%rbp),%r10
lea    -0x250(%rbp),%rax
mov    $0x2,%edi
movzwl %dx,%edx
mov    %r10,(%rsp)
mov    %rax,0x8(%rsp)
call   1040 <test_getnameinfo_err@plt>
add    $0x270,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getnameinfo>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x238,%rsp
mov    %r9d,%r14d
mov    %r8,0x10(%rsp)
mov    %ecx,%r12d
mov    %rdx,0x8(%rsp)
mov    %esi,%r13d
mov    %rdi,%rbx
mov    0x270(%rsp),%r15d
xor    %edi,%edi
cmp    $0x101,%ecx
setb   %dil
call   1070 <assert@plt>
xor    %edi,%edi
cmp    $0x101,%r14d
setb   %dil
call   1070 <assert@plt>
mov    0x2e2f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x28(%rsp)
mov    %rbx,(%rsp)
mov    %rbx,0x20(%rsp)
mov    %r13w,0x18(%rsp)
lea    0x130(%rsp),%rbp
mov    %rbp,%rdi
mov    $0xdeadbeef,%esi
mov    %r12d,%edx
call   1080 <memsetl@plt>
lea    0x30(%rsp),%rbx
mov    %rbx,%rdi
mov    $0xdeadbeef,%esi
mov    %r14d,%edx
call   1080 <memsetl@plt>
sub    $0x8,%rsp
lea    0x20(%rsp),%rdi
mov    $0x18,%esi
mov    %rbp,%rdx
mov    %r12d,%ecx
mov    %rbx,%r8
mov    %r15,%rbx
mov    %r14d,%r9d
push   %r15
call   1050 <getnameinfo@plt>
add    $0x10,%rsp
mov    %eax,%r15d
mov    0x278(%rsp),%eax
cmp    $0x1f,%r15d
ja     1239 <test_getnameinfo+0xd9>
bt     %r15d,%eax
jb     125b <test_getnameinfo+0xfb>
movzwl %r13w,%edx
mov    $0x1,%edi
mov    (%rsp),%rsi
mov    %r12d,%ecx
mov    %r14d,%r8d
mov    %ebx,%r9d
push   %r15
push   %rax
call   1030 <test_getnameinfo_err_nr@plt>
add    $0x10,%rsp
test   %r15d,%r15d
jne    12e8 <test_getnameinfo+0x188>
test   %r12d,%r12d
je     12a8 <test_getnameinfo+0x148>
lea    0x130(%rsp),%r15
mov    0x8(%rsp),%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12a8 <test_getnameinfo+0x148>
movzwl %r13w,%edx
mov    $0x2,%edi
mov    (%rsp),%rsi
mov    %r12d,%ecx
mov    %r14d,%r8d
mov    %ebx,%r9d
push   %r15
push   0x10(%rsp)
call   1040 <test_getnameinfo_err@plt>
add    $0x10,%rsp
test   %r14d,%r14d
je     12e8 <test_getnameinfo+0x188>
lea    0x30(%rsp),%rbp
mov    0x10(%rsp),%rdi
mov    %rbp,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
je     12e8 <test_getnameinfo+0x188>
movzwl %r13w,%edx
mov    $0x2,%edi
mov    (%rsp),%rsi
mov    %r12d,%ecx
mov    %r14d,%r8d
mov    %ebx,%r9d
push   %rbp
push   0x18(%rsp)
call   1040 <test_getnameinfo_err@plt>
add    $0x10,%rsp
add    $0x238,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define void @test_getnameinfo(i64 %0, i16 zeroext %1, i8* %2, i32 %3, i8* %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i64
%10 = alloca i16
%11 = alloca i8*
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.sockaddr_in
%18 = alloca [256 x i8]
%19 = alloca [256 x i8]
%20 = alloca i32
store i64 %0, i64* %9
store i16 %1, i16* %10
store i8* %2, i8** %11
store i32 %3, i32* %12
store i8* %4, i8** %13
store i32 %5, i32* %14
store i32 %6, i32* %15
store i32 %7, i32* %16
%21 = load i32, i32* %12
%22 = sext i32 %21 to i64
%23 = icmp ule i64 %22, 256
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32, i32* %14
%27 = sext i32 %26 to i64
%28 = icmp ule i64 %27, 256
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* @AF_INET
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %31, i32* %32
%33 = load i64, i64* %9
%34 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
%35 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %34, i32 0, i32 0
store i64 %33, i64* %35
%36 = load i16, i16* %10
%37 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
store i16 %36, i16* %37
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%39 = load i32, i32* %12
%40 = call i32 @memsetl(i8* %38, i32 -559038737, i32 %39)
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%42 = load i32, i32* %14
%43 = call i32 @memsetl(i8* %41, i32 -559038737, i32 %42)
%44 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%45 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%46 = load i32, i32* %12
%47 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%48 = load i32, i32* %14
%49 = load i32, i32* %15
%50 = call i32 @getnameinfo(%struct.sockaddr* %44, i32 24, i8* %45, i32 %46, i8* %47, i32 %48, i32 %49)
store i32 %50, i32* %20
%51 = load i32, i32* %20
%52 = icmp slt i32 %51, 0
br i1 %52, label %62, label %53
53: ; preds = %8
%54 = load i32, i32* %20
%55 = icmp sge i32 %54, 32
br i1 %55, label %62, label %56
56: ; preds = %53
%57 = load i32, i32* %20
%58 = shl i32 1, %57
%59 = load i32, i32* %16
%60 = and i32 %58, %59
%61 = icmp ne i32 %60, 0
br i1 %61, label %71, label %62
62: ; preds = %56, %53, %8
%63 = load i64, i64* %9
%64 = load i16, i16* %10
%65 = load i32, i32* %12
%66 = load i32, i32* %14
%67 = load i32, i32* %15
%68 = load i32, i32* %16
%69 = load i32, i32* %20
%70 = call i32 @test_getnameinfo_err_nr(i32 1, i64 %63, i16 zeroext %64, i32 %65, i32 %66, i32 %67, i32 %68, i32 %69)
br label %71
71: ; preds = %62, %56
%72 = load i32, i32* %20
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %75
74: ; preds = %71
br label %109
75: ; preds = %71
%76 = load i32, i32* %12
%77 = icmp ne i32 %76, 0
br i1 %77, label %78, label %92
78: ; preds = %75
%79 = load i8*, i8** %11
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%81 = call i64 @strcmp(i8* %79, i8* %80)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %92
83: ; preds = %78
%84 = load i64, i64* %9
%85 = load i16, i16* %10
%86 = load i32, i32* %12
%87 = load i32, i32* %14
%88 = load i32, i32* %15
%89 = load i8*, i8** %11
%90 = getelementptr inbounds [256 x i8], [256 x i8]* %18, i64 0, i64 0
%91 = call i32 @test_getnameinfo_err(i32 2, i64 %84, i16 zeroext %85, i32 %86, i32 %87, i32 %88, i8* %89, i8* %90)
br label %92
92: ; preds = %83, %78, %75
%93 = load i32, i32* %14
%94 = icmp ne i32 %93, 0
br i1 %94, label %95, label %109
95: ; preds = %92
%96 = load i8*, i8** %13
%97 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%98 = call i64 @strcmp(i8* %96, i8* %97)
%99 = icmp ne i64 %98, 0
br i1 %99, label %100, label %109
100: ; preds = %95
%101 = load i64, i64* %9
%102 = load i16, i16* %10
%103 = load i32, i32* %12
%104 = load i32, i32* %14
%105 = load i32, i32* %15
%106 = load i8*, i8** %13
%107 = getelementptr inbounds [256 x i8], [256 x i8]* %19, i64 0, i64 0
%108 = call i32 @test_getnameinfo_err(i32 2, i64 %101, i16 zeroext %102, i32 %103, i32 %104, i32 %105, i8* %106, i8* %107)
br label %109
109: ; preds = %74, %100, %95, %92
ret void
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i16, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
define void @test_getnameinfo(i64 %0, i16 zeroext %1, i8* %2, i32 %3, i8* %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca %struct.sockaddr_in
%10 = alloca [256 x i8]
%11 = alloca [256 x i8]
%12 = bitcast %struct.sockaddr_in* %9 to i8*
%13 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%14 = getelementptr inbounds [256 x i8], [256 x i8]* %11, i64 0, i64 0
%15 = icmp ult i32 %3, 257
%16 = zext i1 %15 to i32
%17 = tail call i32 @assert(i32 %16)
%18 = icmp ult i32 %5, 257
%19 = zext i1 %18 to i32
%20 = tail call i32 @assert(i32 %19)
%21 = load i32, i32* @AF_INET
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 2
store i32 %21, i32* %22
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 1, i32 0
store i64 %0, i64* %23
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i64 0, i32 0
store i16 %1, i16* %24
%25 = call i32 @memsetl(i8* %13, i32 -559038737, i32 %3)
%26 = call i32 @memsetl(i8* %14, i32 -559038737, i32 %5)
%27 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%28 = call i32 @getnameinfo(%struct.sockaddr* %27, i32 24, i8* %13, i32 %3, i8* %14, i32 %5, i32 %6)
%29 = icmp ugt i32 %28, 31
br i1 %29, label %34, label %30
30: ; preds = %8
%31 = shl nuw i32 1, %28
%32 = and i32 %31, %7
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %30, %8
%35 = call i32 @test_getnameinfo_err_nr(i32 1, i64 %0, i16 zeroext %1, i32 %3, i32 %5, i32 %6, i32 %7, i32 %28)
br label %36
36: ; preds = %34, %30
%37 = icmp eq i32 %28, 0
br i1 %37, label %38, label %52
38: ; preds = %36
%39 = icmp eq i32 %3, 0
br i1 %39, label %45, label %40
40: ; preds = %38
%41 = call i64 @strcmp(i8* %2, i8* %13)
%42 = icmp eq i64 %41, 0
br i1 %42, label %45, label %43
43: ; preds = %40
%44 = call i32 @test_getnameinfo_err(i32 2, i64 %0, i16 zeroext %1, i32 %3, i32 %5, i32 %6, i8* %2, i8* %13)
br label %45
45: ; preds = %43, %40, %38
%46 = icmp eq i32 %5, 0
br i1 %46, label %52, label %47
47: ; preds = %45
%48 = call i64 @strcmp(i8* %4, i8* %14)
%49 = icmp eq i64 %48, 0
br i1 %49, label %52, label %50
50: ; preds = %47
%51 = call i32 @test_getnameinfo_err(i32 2, i64 %0, i16 zeroext %1, i32 %3, i32 %5, i32 %6, i8* %4, i8* %14)
br label %52
52: ; preds = %45, %47, %50, %36
ret void
}