#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 hostent {
  char *h_name;
};
typedef int /*<<< orphan*/ address;
typedef int addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
int ntohl(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, int, int);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *resolve_address(int address) {
  static char addr_str[256];
  struct hostent *from;
  int addr;
  if ((from = gethostbyaddr((char *)&address, sizeof(address), AF_INET)) !=
      NULL) {
    strcpy(addr_str,
           strcmp(from->h_name, "localhost") ? from->h_name : "local-host");
  } else {
    addr = ntohl(address);
    snprintf(addr_str, 256, "%d.%d.%d.%d", (addr >> 24) & 0xFF,
             (addr >> 16) & 0xFF, (addr >> 8) & 0xFF, (addr)&0xFF);
  }
  return addr_str;
}


x86 assembly (clang, -O0):
<resolve_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x4(%rbp),%rdi
mov    0x2e82(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <gethostbyaddr@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     11d2 <resolve_address+0x82>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe72(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
je     11ad <resolve_address+0x5d>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    11bd <resolve_address+0x6d>
lea    0xe56(%rip),%rax
mov    %rax,-0x20(%rbp)
jmp    11bd <resolve_address+0x6d>
mov    -0x20(%rbp),%rsi
lea    0x2e98(%rip),%rdi
call   1030 <strcpy@plt>
jmp    122a <resolve_address+0xda>
mov    -0x4(%rbp),%edi
call   1070 <ntohl@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%ecx
sar    $0x18,%ecx
and    $0xff,%ecx
mov    -0x14(%rbp),%r8d
sar    $0x10,%r8d
and    $0xff,%r8d
mov    -0x14(%rbp),%r9d
sar    $0x8,%r9d
and    $0xff,%r9d
mov    -0x14(%rbp),%eax
and    $0xff,%eax
lea    0x2e4a(%rip),%rdi
mov    $0x100,%esi
lea    0xdf3(%rip),%rdx
mov    %eax,(%rsp)
call   1040 <snprintf@plt>
lea    0x2e2f(%rip),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<resolve_address>:
push   %rbx
sub    $0x10,%rsp
mov    %edi,0xc(%rsp)
mov    0x2e88(%rip),%rax
mov    (%rax),%edx
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1060 <gethostbyaddr@plt>
test   %rax,%rax
je     1192 <resolve_address+0x42>
mov    %rax,%rbx
mov    (%rax),%rdi
lea    0xe7d(%rip),%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11cf <resolve_address+0x7f>
mov    (%rbx),%rsi
jmp    11d6 <resolve_address+0x86>
mov    0xc(%rsp),%edi
call   1070 <ntohl@plt>
mov    %eax,%edx
movzbl %ah,%ebx
movzbl %al,%esi
mov    %eax,%ecx
shr    $0x18,%ecx
shr    $0x10,%edx
movzbl %dl,%r8d
mov    %esi,(%rsp)
lea    0x2ea7(%rip),%rdi
lea    0xe55(%rip),%rdx
mov    $0x100,%esi
mov    %ebx,%r9d
call   1040 <snprintf@plt>
jmp    11e2 <resolve_address+0x92>
lea    0xe34(%rip),%rsi
lea    0x2e83(%rip),%rdi
call   1030 <strcpy@plt>
lea    0x2e77(%rip),%rax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i8* }
@resolve_address.addr_str = internal global [256 x i8] zeroinitializer
@AF_INET = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [11 x i8] c"local-host\00"
@.str.2 = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @resolve_address(i32 %0) {
%2 = alloca i32
%3 = alloca %struct.hostent*
%4 = alloca i32
store i32 %0, i32* %2
%5 = bitcast i32* %2 to i8*
%6 = load i32, i32* @AF_INET
%7 = call %struct.hostent* @gethostbyaddr(i8* %5, i32 4, i32 %6)
store %struct.hostent* %7, %struct.hostent** %3
%8 = icmp ne %struct.hostent* %7, null
br i1 %8, label %9, label %23
9: ; preds = %1
%10 = load %struct.hostent*, %struct.hostent** %3
%11 = getelementptr inbounds %struct.hostent, %struct.hostent* %10, i32 0, i32 0
%12 = load i8*, i8** %11
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %9
%16 = load %struct.hostent*, %struct.hostent** %3
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 0
%18 = load i8*, i8** %17
br label %20
19: ; preds = %9
br label %20
20: ; preds = %19, %15
%21 = phi i8* [ %18, %15 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %19 ]
%22 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @resolve_address.addr_str, i64 0, i64 0), i8* %21)
br label %38
23: ; preds = %1
%24 = load i32, i32* %2
%25 = call i32 @ntohl(i32 %24)
store i32 %25, i32* %4
%26 = load i32, i32* %4
%27 = ashr i32 %26, 24
%28 = and i32 %27, 255
%29 = load i32, i32* %4
%30 = ashr i32 %29, 16
%31 = and i32 %30, 255
%32 = load i32, i32* %4
%33 = ashr i32 %32, 8
%34 = and i32 %33, 255
%35 = load i32, i32* %4
%36 = and i32 %35, 255
%37 = call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @resolve_address.addr_str, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %28, i32 %31, i32 %34, i32 %36)
br label %38
38: ; preds = %23, %20
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @resolve_address.addr_str, i64 0, i64 0)
}

LLVM IR (-O2):
%struct.hostent = type { i8* }
@resolve_address.addr_str = internal global [256 x i8] zeroinitializer
@AF_INET = global i32 0
@.str = [10 x i8] c"localhost\00"
@.str.1 = [11 x i8] c"local-host\00"
@.str.2 = [12 x i8] c"%d.%d.%d.%d\00"
define i8* @resolve_address(i32 %0) {
%2 = alloca i32
store i32 %0, i32* %2
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @AF_INET
%5 = call %struct.hostent* @gethostbyaddr(i8* %3, i32 4, i32 %4)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %17, label %7
7: ; preds = %1
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%9 = load i8*, i8** %8
%10 = call i64 @strcmp(i8* %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %7
%13 = load i8*, i8** %8
br label %14
14: ; preds = %7, %12
%15 = phi i8* [ %13, %12 ], [ getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), %7 ]
%16 = call i32 @strcpy(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @resolve_address.addr_str, i64 0, i64 0), i8* %15)
br label %27
17: ; preds = %1
%18 = load i32, i32* %2
%19 = call i32 @ntohl(i32 %18)
%20 = lshr i32 %19, 24
%21 = lshr i32 %19, 16
%22 = and i32 %21, 255
%23 = lshr i32 %19, 8
%24 = and i32 %23, 255
%25 = and i32 %19, 255
%26 = call i32 @snprintf(i8* getelementptr inbounds ([256 x i8], [256 x i8]* @resolve_address.addr_str, i64 0, i64 0), i32 256, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i32 %20, i32 %22, i32 %24, i32 %25)
br label %27
27: ; preds = %17, %14
ret i8* getelementptr inbounds ([256 x i8], [256 x i8]* @resolve_address.addr_str, i64 0, i64 0)
}