#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  scalar_t__ sa_family;
};

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
int INET6_ADDRSTRLEN;
int INET_ADDRSTRLEN;
int /*<<< orphan*/ debug(char *, int /*<<< orphan*/);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ *inet_ntop(scalar_t__, int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strerror(int /*<<< orphan*/);
void print_in_addr(struct sockaddr *sa) {
  char ip[INET6_ADDRSTRLEN];
  memset(ip, 0, INET6_ADDRSTRLEN);
  if (sa->sa_family == AF_INET) {
    struct sockaddr_in *sa_in = (struct sockaddr_in *)sa;
    if (inet_ntop(AF_INET, &(sa_in->sin_addr), ip, INET_ADDRSTRLEN) == NULL)
      debug("inet_ntop error: %s", strerror(errno));
    (void)fprintf(stderr, "%s", ip);
    return;
  }
  struct sockaddr_in6 *sa_in6 = (struct sockaddr_in6 *)sa;
  if (inet_ntop(AF_INET6, &(sa_in6->sin6_addr), ip, INET6_ADDRSTRLEN) == NULL)
    debug("inet_ntop error: %s", strerror(errno));
  (void)fprintf(stderr, "%s", ip);
}


x86 assembly (clang, -O0):
<print_in_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x38(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <memset@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%rax
jne    1222 <print_in_addr+0xd2>
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    0x2e1e(%rip),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    0x2de8(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    11fd <print_in_addr+0xad>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xe08(%rip),%rdi
call   1040 <debug@plt>
mov    -0x38(%rbp),%rdx
mov    0x2dc0(%rip),%rax
mov    (%rax),%edi
lea    0xe00(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x24(%rbp)
jmp    1290 <print_in_addr+0x140>
mov    -0x38(%rbp),%rdx
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    0x2da3(%rip),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rsi
mov    0x2da5(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
cmp    $0x0,%rax
jne    1270 <print_in_addr+0x120>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    %eax,%esi
lea    0xd95(%rip),%rdi
call   1040 <debug@plt>
mov    -0x38(%rbp),%rdx
mov    0x2d4d(%rip),%rax
mov    (%rax),%edi
lea    0xd8d(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<print_in_addr>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
mov    0x2e84(%rip),%r15
mov    (%r15),%edx
mov    %rsp,%rbx
mov    %rdx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
xor    %esi,%esi
call   1050 <memset@plt>
mov    (%r14),%rdi
mov    0x2e51(%rip),%rax
cmp    (%rax),%rdi
jne    119f <print_in_addr+0x4f>
mov    0x2e1d(%rip),%rax
mov    (%rax),%ecx
jmp    11ac <print_in_addr+0x5c>
mov    0x2e32(%rip),%rax
mov    (%rax),%rdi
mov    (%r15),%ecx
mov    %r14,%rsi
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
test   %rax,%rax
jne    11d8 <print_in_addr+0x88>
mov    0x2dfd(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe2f(%rip),%rdi
mov    %eax,%esi
call   1040 <debug@plt>
mov    0x2de9(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
mov    %rbx,%rdx
call   1060 <fprintf@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i64 0
@INET_ADDRSTRLEN = global i32 0
@.str = [20 x i8] c"inet_ntop error: %s\00"
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@AF_INET6 = global i64 0
define void @print_in_addr(%struct.sockaddr* %0) {
%2 = alloca %struct.sockaddr*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca %struct.sockaddr_in*
%6 = alloca i32
%7 = alloca %struct.sockaddr_in6*
store %struct.sockaddr* %0, %struct.sockaddr** %2
%8 = load i32, i32* @INET6_ADDRSTRLEN
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %3
%11 = alloca i8, i64 %9
store i64 %9, i64* %4
%12 = load i32, i32* @INET6_ADDRSTRLEN
%13 = call i32 @memset(i8* %11, i32 0, i32 %12)
%14 = load %struct.sockaddr*, %struct.sockaddr** %2
%15 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = load i64, i64* @AF_INET
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %35
19: ; preds = %1
%20 = load %struct.sockaddr*, %struct.sockaddr** %2
%21 = bitcast %struct.sockaddr* %20 to %struct.sockaddr_in*
store %struct.sockaddr_in* %21, %struct.sockaddr_in** %5
%22 = load i64, i64* @AF_INET
%23 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %23, i32 0, i32 0
%25 = load i32, i32* @INET_ADDRSTRLEN
%26 = call i32* @inet_ntop(i64 %22, i32* %24, i8* %11, i32 %25)
%27 = icmp eq i32* %26, null
br i1 %27, label %28, label %32
28: ; preds = %19
%29 = load i32, i32* @errno
%30 = call i32 @strerror(i32 %29)
%31 = call i32 @debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %30)
br label %32
32: ; preds = %28, %19
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 1, i32* %6
br label %51
35: ; preds = %1
%36 = load %struct.sockaddr*, %struct.sockaddr** %2
%37 = bitcast %struct.sockaddr* %36 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %37, %struct.sockaddr_in6** %7
%38 = load i64, i64* @AF_INET6
%39 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%40 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %39, i32 0, i32 0
%41 = load i32, i32* @INET6_ADDRSTRLEN
%42 = call i32* @inet_ntop(i64 %38, i32* %40, i8* %11, i32 %41)
%43 = icmp eq i32* %42, null
br i1 %43, label %44, label %48
44: ; preds = %35
%45 = load i32, i32* @errno
%46 = call i32 @strerror(i32 %45)
%47 = call i32 @debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %46)
br label %48
48: ; preds = %44, %35
%49 = load i32, i32* @stderr
%50 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %11)
store i32 0, i32* %6
br label %51
51: ; preds = %48, %32
%52 = load i8*, i8** %3
%53 = load i32, i32* %6
switch i32 %53, label %55 [
i32 0, label %54
i32 1, label %54
]
54: ; preds = %51, %51
ret void
55: ; preds = %51
unreachable
}

LLVM IR (-O2):
%struct.sockaddr = type { i64 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET = global i64 0
@INET_ADDRSTRLEN = global i32 0
@.str = [20 x i8] c"inet_ntop error: %s\00"
@errno = global i32 0
@stderr = global i32 0
@.str.1 = [3 x i8] c"%s\00"
@AF_INET6 = global i64 0
define void @print_in_addr(%struct.sockaddr* %0) {
%2 = load i32, i32* @INET6_ADDRSTRLEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @memset(i8* %4, i32 0, i32 %2)
%6 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%7 = load i64, i64* %6
%8 = load i64, i64* @AF_INET
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %15
10: ; preds = %1
%11 = bitcast %struct.sockaddr* %0 to i32*
%12 = load i32, i32* @INET_ADDRSTRLEN
%13 = call i32* @inet_ntop(i64 %7, i32* %11, i8* %4, i32 %12)
%14 = icmp eq i32* %13, null
br i1 %14, label %21, label %25
15: ; preds = %1
%16 = load i64, i64* @AF_INET6
%17 = bitcast %struct.sockaddr* %0 to i32*
%18 = load i32, i32* @INET6_ADDRSTRLEN
%19 = call i32* @inet_ntop(i64 %16, i32* %17, i8* %4, i32 %18)
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %25
21: ; preds = %15, %10
%22 = load i32, i32* @errno
%23 = call i32 @strerror(i32 %22)
%24 = call i32 @debug(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %21, %15, %10
%26 = load i32, i32* @stderr
%27 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %4)
ret void
}