#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 {
  int dummy;
};

/* Variables and functions */
int AF_INET6;
int INET6_ADDRSTRLEN;
char *bc_strdup(char *);
int /*<<< orphan*/ inet_ntop(int, int /*<<< orphan*/ *, char *, int);
char *br_httpd_get_ip(int af, const struct sockaddr *addr) {
  char host[INET6_ADDRSTRLEN];
  if (af == AF_INET6) {
    struct sockaddr_in6 *a = (struct sockaddr_in6 *)addr;
    inet_ntop(af, &(a->sin6_addr), host, INET6_ADDRSTRLEN);
  } else {
    struct sockaddr_in *a = (struct sockaddr_in *)addr;
    inet_ntop(af, &(a->sin_addr), host, INET6_ADDRSTRLEN);
  }
  return bc_strdup(host);
}


x86 assembly (clang, -O0):
<br_httpd_get_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2eb2(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%eax
mov    0x2e7b(%rip),%rcx
cmp    (%rcx),%eax
jne    1193 <br_httpd_get_ip+0x73>
mov    -0x38(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    0x2e61(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
jmp    11b4 <br_httpd_get_ip+0x94>
mov    -0x38(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x30(%rbp),%rsi
mov    0x2e3b(%rip),%rax
mov    (%rax),%ecx
call   1030 <inet_ntop@plt>
mov    -0x38(%rbp),%rdi
call   1040 <bc_strdup@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<br_httpd_get_ip>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    0x2ebb(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rbx
mov    %rcx,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdx
call   1030 <inet_ntop@plt>
mov    %rbx,%rdi
call   1040 <bc_strdup@plt>
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr = type { i32 }
%struct.sockaddr_in6 = type { i32 }
%struct.sockaddr_in = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
define i8* @br_httpd_get_ip(i32 %0, %struct.sockaddr* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca %struct.sockaddr_in6*
%8 = alloca %struct.sockaddr_in*
store i32 %0, i32* %3
store %struct.sockaddr* %1, %struct.sockaddr** %4
%9 = load i32, i32* @INET6_ADDRSTRLEN
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %5
%12 = alloca i8, i64 %10
store i64 %10, i64* %6
%13 = load i32, i32* %3
%14 = load i32, i32* @AF_INET6
%15 = icmp eq i32 %13, %14
br i1 %15, label %16, label %24
16: ; preds = %2
%17 = load %struct.sockaddr*, %struct.sockaddr** %4
%18 = bitcast %struct.sockaddr* %17 to %struct.sockaddr_in6*
store %struct.sockaddr_in6* %18, %struct.sockaddr_in6** %7
%19 = load i32, i32* %3
%20 = load %struct.sockaddr_in6*, %struct.sockaddr_in6** %7
%21 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %20, i32 0, i32 0
%22 = load i32, i32* @INET6_ADDRSTRLEN
%23 = call i32 @inet_ntop(i32 %19, i32* %21, i8* %12, i32 %22)
br label %32
24: ; preds = %2
%25 = load %struct.sockaddr*, %struct.sockaddr** %4
%26 = bitcast %struct.sockaddr* %25 to %struct.sockaddr_in*
store %struct.sockaddr_in* %26, %struct.sockaddr_in** %8
%27 = load i32, i32* %3
%28 = load %struct.sockaddr_in*, %struct.sockaddr_in** %8
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %28, i32 0, i32 0
%30 = load i32, i32* @INET6_ADDRSTRLEN
%31 = call i32 @inet_ntop(i32 %27, i32* %29, i8* %12, i32 %30)
br label %32
32: ; preds = %24, %16
%33 = call i8* @bc_strdup(i8* %12)
%34 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
%struct.sockaddr = type { i32 }
@INET6_ADDRSTRLEN = global i32 0
@AF_INET6 = global i32 0
define i8* @br_httpd_get_ip(i32 %0, %struct.sockaddr* %1) {
%3 = load i32, i32* @INET6_ADDRSTRLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = getelementptr %struct.sockaddr, %struct.sockaddr* %1, i64 0, i32 0
%7 = call i32 @inet_ntop(i32 %0, i32* %6, i8* %5, i32 %3)
%8 = call i8* @bc_strdup(i8* %5)
ret i8* %8
}