#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*/ va_list;
struct sockaddr_in6 {
  int /*<<< orphan*/ sin6_port;
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_addr;
};
struct addrinfo {
  scalar_t__ ai_family;
  scalar_t__ ai_socktype;
  struct addrinfo *ai_next;
  scalar_t__ ai_addr;
};

/* Variables and functions */
scalar_t__ AF_INET;
int INET6_ADDRSTRLEN;
scalar_t__ SOCK_DGRAM;
scalar_t__ SOCK_STREAM;
int errno;
int /*<<< orphan*/ *inet_ntop(scalar_t__, void *, char *, int);
unsigned short ntohs(int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, char *, unsigned short);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int /*<<< orphan*/ syslog(int, char *, char *);
int /*<<< orphan*/ vsprintf(char *, char const *, int /*<<< orphan*/);
int _pr_addrinfo(int level, struct addrinfo *info, const char *fmt,
                 va_list ap) {
  unsigned short port;
  int offset;
  char log[1024];
  char addr[INET6_ADDRSTRLEN];
  struct addrinfo *ai = info;
  void *addrptr;
  vsprintf(log, fmt, ap);
  strcat(log, ":");
  offset = strlen(log);
  while (ai) {
    if (ai->ai_family == AF_INET) {
      addrptr = &((struct sockaddr_in *)ai->ai_addr)->sin_addr;
      port = ntohs(((struct sockaddr_in *)ai->ai_addr)->sin_port);
    } else {
      addrptr = &((struct sockaddr_in6 *)ai->ai_addr)->sin6_addr;
      port = ntohs(((struct sockaddr_in6 *)ai->ai_addr)->sin6_port);
    }
    if (inet_ntop(ai->ai_family, addrptr, addr, INET6_ADDRSTRLEN) == NULL) {
      return errno;
    }
    if (ai->ai_socktype == SOCK_STREAM)
      sprintf(log + offset, " %s:%d(tcp)", addr, port);
    else if (ai->ai_socktype == SOCK_DGRAM)
      sprintf(log + offset, " %s:%d(udp)", addr, port);
    ai = ai->ai_next;
  }
  strcat(log, "\n");
  syslog(level, "%s", log);
  return 0;
}


x86 assembly (clang, -O0):
<_pr_addrinfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x460,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x438(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x460(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x440(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x448(%rbp)
lea    -0x430(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x1c(%rbp),%edx
call   1070 <vsprintf@plt>
lea    -0x430(%rbp),%rdi
lea    0xe16(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x430(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
cmpq   $0x0,-0x448(%rbp)
je     136f <_pr_addrinfo+0x1ff>
mov    -0x448(%rbp),%rax
mov    (%rax),%rax
mov    0x2dc3(%rip),%rcx
cmp    (%rcx),%rax
jne    1257 <_pr_addrinfo+0xe7>
mov    -0x448(%rbp),%rax
mov    0x18(%rax),%rax
add    $0x4,%rax
mov    %rax,-0x450(%rbp)
mov    -0x448(%rbp),%rax
mov    0x18(%rax),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    %ax,-0x1e(%rbp)
jmp    1283 <_pr_addrinfo+0x113>
mov    -0x448(%rbp),%rax
mov    0x18(%rax),%rax
add    $0x4,%rax
mov    %rax,-0x450(%rbp)
mov    -0x448(%rbp),%rax
mov    0x18(%rax),%rax
mov    (%rax),%edi
call   1060 <ntohs@plt>
mov    %ax,-0x1e(%rbp)
mov    -0x460(%rbp),%rdx
mov    -0x448(%rbp),%rax
mov    (%rax),%rdi
mov    -0x450(%rbp),%rsi
mov    0x2d46(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    12ce <_pr_addrinfo+0x15e>
mov    0x2d06(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x454(%rbp)
jmp    13a9 <_pr_addrinfo+0x239>
mov    -0x448(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2ce8(%rip),%rcx
cmp    (%rcx),%rax
jne    1313 <_pr_addrinfo+0x1a3>
mov    -0x460(%rbp),%rdx
lea    -0x430(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
lea    0xcfd(%rip),%rsi
movzwl -0x1e(%rbp),%ecx
call   1090 <sprintf@plt>
jmp    1358 <_pr_addrinfo+0x1e8>
mov    -0x448(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x2cb3(%rip),%rcx
cmp    (%rcx),%rax
jne    1353 <_pr_addrinfo+0x1e3>
mov    -0x460(%rbp),%rdx
lea    -0x430(%rbp),%rdi
movslq -0x24(%rbp),%rax
add    %rax,%rdi
lea    0xcc4(%rip),%rsi
movzwl -0x1e(%rbp),%ecx
call   1090 <sprintf@plt>
jmp    1358 <_pr_addrinfo+0x1e8>
mov    -0x448(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x448(%rbp)
jmp    11fe <_pr_addrinfo+0x8e>
lea    -0x430(%rbp),%rdi
lea    0xc9d(%rip),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%edi
lea    -0x430(%rbp),%rdx
lea    0xc89(%rip),%rsi
call   1050 <syslog@plt>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x454(%rbp)
mov    -0x438(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_pr_addrinfo>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    %edi,-0x2c(%rbp)
mov    %rsp,-0x38(%rbp)
mov    0x2e53(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r15
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    -0x440(%rbp),%r12
mov    %r12,%rdi
mov    %rdx,%rsi
mov    %ecx,%edx
call   1070 <vsprintf@plt>
lea    0xe3d(%rip),%rsi
mov    %r12,%rdi
call   1080 <strcat@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
test   %rbx,%rbx
je     1263 <_pr_addrinfo+0xf3>
cltq
lea    (%rax,%rbp,1),%r12
add    $0xfffffffffffffbc0,%r12
jmp    1208 <_pr_addrinfo+0x98>
nopl   0x0(%rax,%rax,1)
movzwl %r13w,%ecx
mov    %r12,%rdi
mov    %r15,%rdx
call   1090 <sprintf@plt>
mov    0x10(%rbx),%rbx
test   %rbx,%rbx
je     1263 <_pr_addrinfo+0xf3>
mov    0x18(%rbx),%r14
mov    (%r14),%edi
add    $0x4,%r14
call   1060 <ntohs@plt>
mov    %eax,%r13d
mov    (%rbx),%rdi
mov    0x2dc3(%rip),%rax
mov    (%rax),%ecx
mov    %r14,%rsi
mov    %r15,%rdx
call   1030 <inet_ntop@plt>
test   %rax,%rax
je     128f <_pr_addrinfo+0x11f>
mov    0x8(%rbx),%rax
lea    0xdc0(%rip),%rsi
mov    0x2d87(%rip),%rcx
cmp    (%rcx),%rax
je     11f0 <_pr_addrinfo+0x80>
lea    0xdb9(%rip),%rsi
mov    0x2d84(%rip),%rcx
cmp    (%rcx),%rax
je     11f0 <_pr_addrinfo+0x80>
jmp    11ff <_pr_addrinfo+0x8f>
lea    0xdb0(%rip),%rsi
lea    -0x440(%rbp),%rbx
mov    %rbx,%rdi
call   1080 <strcat@plt>
lea    0xd9c(%rip),%rsi
mov    -0x2c(%rbp),%edi
mov    %rbx,%rdx
call   1050 <syslog@plt>
xor    %eax,%eax
jmp    1298 <_pr_addrinfo+0x128>
mov    0x2d32(%rip),%rax
mov    (%rax),%eax
mov    -0x38(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.addrinfo = type { i64, i64, %struct.addrinfo*, i64 }
%struct.sockaddr_in = type { i32, i32 }
%struct.sockaddr_in6 = type { i32, i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [2 x i8] c":\00"
@AF_INET = global i64 0
@errno = global i32 0
@SOCK_STREAM = global i64 0
@.str.1 = [12 x i8] c" %s:%d(tcp)\00"
@SOCK_DGRAM = global i64 0
@.str.2 = [12 x i8] c" %s:%d(udp)\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @_pr_addrinfo(i32 %0, %struct.addrinfo* %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca %struct.addrinfo*
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i16
%11 = alloca i32
%12 = alloca [1024 x i8]
%13 = alloca i8*
%14 = alloca i64
%15 = alloca %struct.addrinfo*
%16 = alloca i8*
%17 = alloca i32
store i32 %0, i32* %6
store %struct.addrinfo* %1, %struct.addrinfo** %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%18 = load i32, i32* @INET6_ADDRSTRLEN
%19 = zext i32 %18 to i64
%20 = call i8* @llvm.stacksave()
store i8* %20, i8** %13
%21 = alloca i8, i64 %19
store i64 %19, i64* %14
%22 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %22, %struct.addrinfo** %15
%23 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%24 = load i8*, i8** %8
%25 = load i32, i32* %9
%26 = call i32 @vsprintf(i8* %23, i8* %24, i32 %25)
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%30 = call i32 @strlen(i8* %29)
store i32 %30, i32* %11
br label %31
31: ; preds = %105, %4
%32 = load %struct.addrinfo*, %struct.addrinfo** %15
%33 = icmp ne %struct.addrinfo* %32, null
br i1 %33, label %34, label %109
34: ; preds = %31
%35 = load %struct.addrinfo*, %struct.addrinfo** %15
%36 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %35, i32 0, i32 0
%37 = load i64, i64* %36
%38 = load i64, i64* @AF_INET
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %54
40: ; preds = %34
%41 = load %struct.addrinfo*, %struct.addrinfo** %15
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %41, i32 0, i32 3
%43 = load i64, i64* %42
%44 = inttoptr i64 %43 to %struct.sockaddr_in*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %44, i32 0, i32 1
%46 = bitcast i32* %45 to i8*
store i8* %46, i8** %16
%47 = load %struct.addrinfo*, %struct.addrinfo** %15
%48 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %47, i32 0, i32 3
%49 = load i64, i64* %48
%50 = inttoptr i64 %49 to %struct.sockaddr_in*
%51 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call zeroext i16 @ntohs(i32 %52)
store i16 %53, i16* %10
br label %68
54: ; preds = %34
%55 = load %struct.addrinfo*, %struct.addrinfo** %15
%56 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %55, i32 0, i32 3
%57 = load i64, i64* %56
%58 = inttoptr i64 %57 to %struct.sockaddr_in6*
%59 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %58, i32 0, i32 1
%60 = bitcast i32* %59 to i8*
store i8* %60, i8** %16
%61 = load %struct.addrinfo*, %struct.addrinfo** %15
%62 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %61, i32 0, i32 3
%63 = load i64, i64* %62
%64 = inttoptr i64 %63 to %struct.sockaddr_in6*
%65 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %64, i32 0, i32 0
%66 = load i32, i32* %65
%67 = call zeroext i16 @ntohs(i32 %66)
store i16 %67, i16* %10
br label %68
68: ; preds = %54, %40
%69 = load %struct.addrinfo*, %struct.addrinfo** %15
%70 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %69, i32 0, i32 0
%71 = load i64, i64* %70
%72 = load i8*, i8** %16
%73 = load i32, i32* @INET6_ADDRSTRLEN
%74 = call i32* @inet_ntop(i64 %71, i8* %72, i8* %21, i32 %73)
%75 = icmp eq i32* %74, null
br i1 %75, label %76, label %78
76: ; preds = %68
%77 = load i32, i32* @errno
store i32 %77, i32* %5
store i32 1, i32* %17
br label %115
78: ; preds = %68
%79 = load %struct.addrinfo*, %struct.addrinfo** %15
%80 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %79, i32 0, i32 1
%81 = load i64, i64* %80
%82 = load i64, i64* @SOCK_STREAM
%83 = icmp eq i64 %81, %82
br i1 %83, label %84, label %91
84: ; preds = %78
%85 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%86 = load i32, i32* %11
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds i8, i8* %85, i64 %87
%89 = load i16, i16* %10
%90 = call i32 @sprintf(i8* %88, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %21, i16 zeroext %89)
br label %105
91: ; preds = %78
%92 = load %struct.addrinfo*, %struct.addrinfo** %15
%93 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %92, i32 0, i32 1
%94 = load i64, i64* %93
%95 = load i64, i64* @SOCK_DGRAM
%96 = icmp eq i64 %94, %95
br i1 %96, label %97, label %104
97: ; preds = %91
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%99 = load i32, i32* %11
%100 = sext i32 %99 to i64
%101 = getelementptr inbounds i8, i8* %98, i64 %100
%102 = load i16, i16* %10
%103 = call i32 @sprintf(i8* %101, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %21, i16 zeroext %102)
br label %104
104: ; preds = %97, %91
br label %105
105: ; preds = %104, %84
%106 = load %struct.addrinfo*, %struct.addrinfo** %15
%107 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %106, i32 0, i32 2
%108 = load %struct.addrinfo*, %struct.addrinfo** %107
store %struct.addrinfo* %108, %struct.addrinfo** %15
br label %31
109: ; preds = %31
%110 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%111 = call i32 @strcat(i8* %110, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%112 = load i32, i32* %6
%113 = getelementptr inbounds [1024 x i8], [1024 x i8]* %12, i64 0, i64 0
%114 = call i32 @syslog(i32 %112, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %113)
store i32 0, i32* %5
store i32 1, i32* %17
br label %115
115: ; preds = %109, %76
%116 = load i8*, i8** %13
%117 = load i32, i32* %5
ret i32 %117
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i64, %struct.addrinfo*, i64 }
%struct.sockaddr_in6 = type { i32, i32 }
%struct.sockaddr_in = type { i32, i32 }
@INET6_ADDRSTRLEN = global i32 0
@.str = [2 x i8] c":\00"
@AF_INET = global i64 0
@errno = global i32 0
@SOCK_STREAM = global i64 0
@.str.1 = [12 x i8] c" %s:%d(tcp)\00"
@SOCK_DGRAM = global i64 0
@.str.2 = [12 x i8] c" %s:%d(udp)\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [3 x i8] c"%s\00"
define i32 @_pr_addrinfo(i32 %0, %struct.addrinfo* %1, i8* nocapture %2, i32 %3) {
%5 = alloca [1024 x i8]
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%7 = load i32, i32* @INET6_ADDRSTRLEN
%8 = zext i32 %7 to i64
%9 = tail call i8* @llvm.stacksave()
%10 = alloca i8, i64 %8
%11 = call i32 @vsprintf(i8* %6, i8* %2, i32 %3)
%12 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @strlen(i8* %6)
%14 = icmp eq %struct.addrinfo* %1, null
br i1 %14, label %58, label %15
15: ; preds = %4
%16 = sext i32 %13 to i64
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 %16
br label %18
18: ; preds = %15, %54
%19 = phi %struct.addrinfo* [ %1, %15 ], [ %56, %54 ]
%20 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 0
%21 = load i64, i64* %20
%22 = load i64, i64* @AF_INET
%23 = icmp eq i64 %21, %22
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 3
%25 = load i64, i64* %24
%26 = inttoptr i64 %25 to %struct.sockaddr_in6*
%27 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %26, i64 0, i32 1
%28 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %26, i64 0, i32 0
%29 = inttoptr i64 %25 to %struct.sockaddr_in*
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %29, i64 0, i32 1
%31 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %29, i64 0, i32 0
%32 = select i1 %23, i32* %31, i32* %28
%33 = select i1 %23, i32* %30, i32* %27
%34 = load i32, i32* %32
%35 = call zeroext i16 @ntohs(i32 %34)
%36 = bitcast i32* %33 to i8*
%37 = load i64, i64* %20
%38 = load i32, i32* @INET6_ADDRSTRLEN
%39 = call i32* @inet_ntop(i64 %37, i8* %36, i8* %10, i32 %38)
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %43
41: ; preds = %18
%42 = load i32, i32* @errno
br label %61
43: ; preds = %18
%44 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 1
%45 = load i64, i64* %44
%46 = load i64, i64* @SOCK_STREAM
%47 = icmp eq i64 %45, %46
br i1 %47, label %51, label %48
48: ; preds = %43
%49 = load i64, i64* @SOCK_DGRAM
%50 = icmp eq i64 %45, %49
br i1 %50, label %51, label %54
51: ; preds = %48, %43
%52 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), %43 ], [ getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), %48 ]
%53 = call i32 @sprintf(i8* %17, i8* dereferenceable(1) %52, i8* %10, i16 zeroext %35)
br label %54
54: ; preds = %51, %48
%55 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %19, i64 0, i32 2
%56 = load %struct.addrinfo*, %struct.addrinfo** %55
%57 = icmp eq %struct.addrinfo* %56, null
br i1 %57, label %58, label %18
58: ; preds = %54, %4
%59 = call i32 @strcat(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%60 = call i32 @syslog(i32 %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* %6)
br label %61
61: ; preds = %58, %41
%62 = phi i32 [ %42, %41 ], [ 0, %58 ]
ret i32 %62
}