#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;
};

/* Variables and functions */
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int getIpAdress(const char *server_addr, char *buf) {
  struct hostent *h;
  if ((h = gethostbyname(server_addr)) == NULL)
    return -1;
  strcpy(buf, inet_ntoa(*((struct in_addr *)h->h_addr)));
  return 0;
}


x86 assembly (clang, -O0):
<getIpAdress>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1163 <getIpAdress+0x33>
movl   $0xffffffff,-0x4(%rbp)
jmp    118b <getIpAdress+0x5b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getIpAdress>:
push   %rbx
mov    %rsi,%rbx
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1156 <getIpAdress+0x26>
mov    (%rax),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    $0xffffffff,%eax
pop    %rbx
ret

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

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