#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 in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
scalar_t__ gethostbyname(char *);
char *inet_ntoa(struct in_addr);
int strlen(char *);
char *getIPAddr(char *addr) {
  struct hostent *hent;
  char *haddr;
  int len = strlen(addr);
  if ((hent = (struct hostent *)gethostbyname(addr)) != NULL) {
    haddr = inet_ntoa(*((struct in_addr *)hent->h_addr_list[0]));
  }
  return haddr;
}


x86 assembly (clang, -O0):
<getIPAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
je     1174 <getIPAddr+0x44>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIPAddr>:
push   %rbx
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1154 <getIPAddr+0x24>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1030 <inet_ntoa@plt>
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
define i8* @getIPAddr(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.hostent*
%4 = alloca i8*
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %5
%8 = load i8*, i8** %2
%9 = call i64 @gethostbyname(i8* %8)
%10 = inttoptr i64 %9 to %struct.hostent*
store %struct.hostent* %10, %struct.hostent** %3
%11 = icmp ne %struct.hostent* %10, null
br i1 %11, label %12, label %22
12: ; preds = %1
%13 = load %struct.hostent*, %struct.hostent** %3
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %13, i32 0, i32 0
%15 = load i64*, i64** %14
%16 = getelementptr inbounds i64, i64* %15, i64 0
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to %struct.in_addr*
%19 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %18, i32 0, i32 0
%20 = load i32, i32* %19
%21 = call i8* @inet_ntoa(i32 %20)
store i8* %21, i8** %4
br label %22
22: ; preds = %12, %1
%23 = load i8*, i8** %4
ret i8* %23
}

LLVM IR (-O2):
%struct.hostent = type { i64* }
%struct.in_addr = type { i32 }
define i8* @getIPAddr(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call i64 @gethostbyname(i8* %0)
%4 = icmp eq i64 %3, 0
br i1 %4, label %14, label %5
5: ; preds = %1
%6 = inttoptr i64 %3 to %struct.hostent*
%7 = getelementptr inbounds %struct.hostent, %struct.hostent* %6, i64 0, i32 0
%8 = load i64*, i64** %7
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to %struct.in_addr*
%11 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %10, i64 0, i32 0
%12 = load i32, i32* %11
%13 = tail call i8* @inet_ntoa(i32 %12)
br label %14
14: ; preds = %5, %1
%15 = phi i8* [ %13, %5 ], [ undef, %1 ]
ret i8* %15
}