#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_s {
  int dummy;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ h_name;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ WINS_AddrToString(struct sockaddr_s *);
struct hostent *gethostbyaddr(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(char *, char *, int);
int WINS_GetNameFromAddr(struct sockaddr_s *addr, char *name) {
  struct hostent *hostentry;
  hostentry = gethostbyaddr((char *)&((struct sockaddr_in *)addr)->sin_addr,
                            sizeof(struct in_addr), AF_INET);
  if (hostentry) {
    strncpy(name, (char *)hostentry->h_name, 64 - 1);
    return 0;
  }
  strcpy(name, WINS_AddrToString(addr));
  return 0;
}


x86 assembly (clang, -O0):
<WINS_GetNameFromAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8d(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <gethostbyaddr@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1197 <WINS_GetNameFromAddr+0x57>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
mov    (%rax),%rsi
mov    $0x3f,%edx
call   1040 <strncpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11ba <WINS_GetNameFromAddr+0x7a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <WINS_AddrToString@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1050 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WINS_GetNameFromAddr>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
mov    0x2e97(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1060 <gethostbyaddr@plt>
test   %rax,%rax
je     1174 <WINS_GetNameFromAddr+0x34>
mov    (%rax),%rsi
mov    %r14,%rdi
mov    $0x3f,%edx
call   1040 <strncpy@plt>
jmp    1186 <WINS_GetNameFromAddr+0x46>
mov    %rbx,%rdi
call   1030 <WINS_AddrToString@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1050 <strcpy@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.sockaddr_s = type { i32 }
%struct.hostent = type { i64 }
%struct.sockaddr_in = type { i32 }
@AF_INET = global i32 0
define i32 @WINS_GetNameFromAddr(%struct.sockaddr_s* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.sockaddr_s*
%5 = alloca i8*
%6 = alloca %struct.hostent*
store %struct.sockaddr_s* %0, %struct.sockaddr_s** %4
store i8* %1, i8** %5
%7 = load %struct.sockaddr_s*, %struct.sockaddr_s** %4
%8 = bitcast %struct.sockaddr_s* %7 to %struct.sockaddr_in*
%9 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%10 = bitcast i32* %9 to i8*
%11 = load i32, i32* @AF_INET
%12 = call %struct.hostent* @gethostbyaddr(i8* %10, i32 4, i32 %11)
store %struct.hostent* %12, %struct.hostent** %6
%13 = load %struct.hostent*, %struct.hostent** %6
%14 = icmp ne %struct.hostent* %13, null
br i1 %14, label %15, label %22
15: ; preds = %2
%16 = load i8*, i8** %5
%17 = load %struct.hostent*, %struct.hostent** %6
%18 = getelementptr inbounds %struct.hostent, %struct.hostent* %17, i32 0, i32 0
%19 = load i64, i64* %18
%20 = inttoptr i64 %19 to i8*
%21 = call i32 @strncpy(i8* %16, i8* %20, i32 63)
store i32 0, i32* %3
br label %27
22: ; preds = %2
%23 = load i8*, i8** %5
%24 = load %struct.sockaddr_s*, %struct.sockaddr_s** %4
%25 = call i32 @WINS_AddrToString(%struct.sockaddr_s* %24)
%26 = call i32 @strcpy(i8* %23, i32 %25)
store i32 0, i32* %3
br label %27
27: ; preds = %22, %15
%28 = load i32, i32* %3
ret i32 %28
}

LLVM IR (-O2):
%struct.sockaddr_s = type { i32 }
%struct.hostent = type { i64 }
@AF_INET = global i32 0
define i32 @WINS_GetNameFromAddr(%struct.sockaddr_s* %0, i8* %1) {
%3 = bitcast %struct.sockaddr_s* %0 to i8*
%4 = load i32, i32* @AF_INET
%5 = tail call %struct.hostent* @gethostbyaddr(i8* %3, i32 4, i32 %4)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i8*
%11 = tail call i32 @strncpy(i8* %1, i8* %10, i32 63)
br label %15
12: ; preds = %2
%13 = tail call i32 @WINS_AddrToString(%struct.sockaddr_s* %0)
%14 = tail call i32 @strcpy(i8* %1, i32 %13)
br label %15
15: ; preds = %12, %7
ret i32 0
}