#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 {
  unsigned long s_addr;
};
struct hostent {
  scalar_t__ *h_addr_list;
};

/* Variables and functions */
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ inet_aton(char *, struct in_addr *);
int read_ip(char *line, void *arg) {
  struct in_addr *addr = arg;
  struct hostent *host;
  int retval = 1;
  if (!inet_aton(line, addr)) {
    if ((host = gethostbyname(line)))
      addr->s_addr = *((unsigned long *)host->h_addr_list[0]);
    else
      retval = 0;
  }
  return retval;
}


x86 assembly (clang, -O0):
<read_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <inet_aton@plt>
cmp    $0x0,%eax
jne    1191 <read_ip+0x71>
mov    -0x8(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1185 <read_ip+0x65>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
jmp    118c <read_ip+0x6c>
movl   $0x0,-0x24(%rbp)
jmp    1191 <read_ip+0x71>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ip>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%rbp
call   1040 <inet_aton@plt>
mov    $0x1,%r14d
test   %eax,%eax
jne    1157 <read_ip+0x37>
mov    %rbp,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     1154 <read_ip+0x34>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,(%rbx)
jmp    1157 <read_ip+0x37>
xor    %r14d,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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