#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 {
  scalar_t__ sa_family;
  scalar_t__ *sa_data;
};
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
scalar_t__ AF_INET;
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
char const *_inet_str(struct sockaddr *addr) {
  static char buf[16];
  if (addr->sa_family != AF_INET)
    snprintf(buf, sizeof(buf), "%s", "UNKNOWN");
  else
    snprintf(buf, sizeof(buf), "%u.%u.%u.%u", (unsigned char)addr->sa_data[2],
             (unsigned char)addr->sa_data[3], (unsigned char)addr->sa_data[4],
             (unsigned char)addr->sa_data[5]);
  return buf;
}


x86 assembly (clang, -O0):
<_inet_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    0x2ebe(%rip),%rcx
cmp    (%rcx),%rax
je     1159 <_inet_str+0x49>
lea    0x2f06(%rip),%rdi
mov    $0x10,%esi
lea    0xeba(%rip),%rdx
lea    0xeb6(%rip),%rcx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11b4 <_inet_str+0xa4>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x10(%rax),%rax
movzbl %al,%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x18(%rax),%rax
movzbl %al,%r8d
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x20(%rax),%rax
movzbl %al,%r9d
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    0x28(%rax),%rax
movzbl %al,%eax
lea    0x2ea2(%rip),%rdi
mov    $0x10,%esi
lea    0xe61(%rip),%rdx
mov    %eax,(%rsp)
mov    $0x0,%al
call   1030 <snprintf@plt>
lea    0x2e85(%rip),%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_inet_str>:
push   %rax
mov    (%rdi),%rax
mov    0x2ecd(%rip),%rcx
cmp    (%rcx),%rax
jne    1155 <_inet_str+0x45>
mov    0x8(%rdi),%rax
movzbl 0x10(%rax),%ecx
movzbl 0x18(%rax),%r8d
movzbl 0x20(%rax),%r9d
movzbl 0x28(%rax),%eax
mov    %eax,(%rsp)
lea    0x2f00(%rip),%rdi
lea    0xec4(%rip),%rdx
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1176 <_inet_str+0x66>
lea    0x2ee4(%rip),%rdi
lea    0xe9d(%rip),%rdx
lea    0xe99(%rip),%rcx
mov    $0x10,%esi
xor    %eax,%eax
call   1030 <snprintf@plt>
lea    0x2ec3(%rip),%rax
pop    %rcx
ret

LLVM IR (-O0):
%struct.sockaddr = type { i64, i64* }
@_inet_str.buf = internal global [16 x i8] zeroinitializer
@AF_INET = global i64 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"UNKNOWN\00"
@.str.2 = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @_inet_str(%struct.sockaddr* %0) {
%2 = alloca %struct.sockaddr*
store %struct.sockaddr* %0, %struct.sockaddr** %2
%3 = load %struct.sockaddr*, %struct.sockaddr** %2
%4 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %3, i32 0, i32 0
%5 = load i64, i64* %4
%6 = load i64, i64* @AF_INET
%7 = icmp ne i64 %5, %6
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_inet_str.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %40
10: ; preds = %1
%11 = load %struct.sockaddr*, %struct.sockaddr** %2
%12 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %11, i32 0, i32 1
%13 = load i64*, i64** %12
%14 = getelementptr inbounds i64, i64* %13, i64 2
%15 = load i64, i64* %14
%16 = trunc i64 %15 to i8
%17 = zext i8 %16 to i32
%18 = load %struct.sockaddr*, %struct.sockaddr** %2
%19 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %18, i32 0, i32 1
%20 = load i64*, i64** %19
%21 = getelementptr inbounds i64, i64* %20, i64 3
%22 = load i64, i64* %21
%23 = trunc i64 %22 to i8
%24 = zext i8 %23 to i32
%25 = load %struct.sockaddr*, %struct.sockaddr** %2
%26 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %25, i32 0, i32 1
%27 = load i64*, i64** %26
%28 = getelementptr inbounds i64, i64* %27, i64 4
%29 = load i64, i64* %28
%30 = trunc i64 %29 to i8
%31 = zext i8 %30 to i32
%32 = load %struct.sockaddr*, %struct.sockaddr** %2
%33 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %32, i32 0, i32 1
%34 = load i64*, i64** %33
%35 = getelementptr inbounds i64, i64* %34, i64 5
%36 = load i64, i64* %35
%37 = trunc i64 %36 to i8
%38 = zext i8 %37 to i32
%39 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_inet_str.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %17, i32 %24, i32 %31, i32 %38)
br label %40
40: ; preds = %10, %8
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_inet_str.buf, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.sockaddr = type { i64, i64* }
@_inet_str.buf = internal global [16 x i8] zeroinitializer
@AF_INET = global i64 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [8 x i8] c"UNKNOWN\00"
@.str.2 = [12 x i8] c"%u.%u.%u.%u\00"
define i8* @_inet_str(%struct.sockaddr* nocapture %0) {
%2 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 0
%3 = load i64, i64* %2
%4 = load i64, i64* @AF_INET
%5 = icmp eq i64 %3, %4
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_inet_str.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0))
br label %28
8: ; preds = %1
%9 = getelementptr inbounds %struct.sockaddr, %struct.sockaddr* %0, i64 0, i32 1
%10 = load i64*, i64** %9
%11 = getelementptr inbounds i64, i64* %10, i64 2
%12 = load i64, i64* %11
%13 = trunc i64 %12 to i32
%14 = and i32 %13, 255
%15 = getelementptr inbounds i64, i64* %10, i64 3
%16 = load i64, i64* %15
%17 = trunc i64 %16 to i32
%18 = and i32 %17, 255
%19 = getelementptr inbounds i64, i64* %10, i64 4
%20 = load i64, i64* %19
%21 = trunc i64 %20 to i32
%22 = and i32 %21, 255
%23 = getelementptr inbounds i64, i64* %10, i64 5
%24 = load i64, i64* %23
%25 = trunc i64 %24 to i32
%26 = and i32 %25, 255
%27 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_inet_str.buf, i64 0, i64 0), i32 16, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %14, i32 %18, i32 %22, i32 %26)
br label %28
28: ; preds = %8, %6
ret i8* getelementptr inbounds ([16 x i8], [16 x i8]* @_inet_str.buf, i64 0, i64 0)
}