#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 */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int hostname_to_ip(char *hostname, char *ip) {
  struct hostent *he;
  struct in_addr **addr_list;
  int i;
  if ((he = gethostbyname(hostname)) == NULL) {
    return 0;
  }
  addr_list = (struct in_addr **)he->h_addr_list;
  for (i = 0; addr_list[i] != NULL; i++) {
    strcpy(ip, inet_ntoa(*addr_list[i]));
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<hostname_to_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%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 <hostname_to_ip+0x33>
movl   $0x0,-0x4(%rbp)
jmp    11c1 <hostname_to_ip+0x91>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11ba <hostname_to_ip+0x8a>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    11c1 <hostname_to_ip+0x91>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
define i32 @hostname_to_ip(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.hostent*
%7 = alloca %struct.in_addr**
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call %struct.hostent* @gethostbyname(i8* %9)
store %struct.hostent* %10, %struct.hostent** %6
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %40
13: ; preds = %2
%14 = load %struct.hostent*, %struct.hostent** %6
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to %struct.in_addr**
store %struct.in_addr** %17, %struct.in_addr*** %7
store i32 0, i32* %8
br label %18
18: ; preds = %36, %13
%19 = load %struct.in_addr**, %struct.in_addr*** %7
%20 = load i32, i32* %8
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %19, i64 %21
%23 = load %struct.in_addr*, %struct.in_addr** %22
%24 = icmp ne %struct.in_addr* %23, null
br i1 %24, label %25, label %39
25: ; preds = %18
%26 = load i8*, i8** %5
%27 = load %struct.in_addr**, %struct.in_addr*** %7
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %27, i64 %29
%31 = load %struct.in_addr*, %struct.in_addr** %30
%32 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @inet_ntoa(i32 %33)
%35 = call i32 @strcpy(i8* %26, i32 %34)
store i32 1, i32* %3
br label %40
36: ; No predecessors!
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %18
39: ; preds = %18
store i32 0, i32* %3
br label %40
40: ; preds = %39, %25, %12
%41 = load i32, i32* %3
ret i32 %41
}

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