#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 /*<<< orphan*/ memcpy(char *, char *, int);
int read_ip(char *line, void *arg) {
  struct in_addr addr;
  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;
  }
  memcpy((char *)arg, (char *)&addr, sizeof(struct in_addr));
  return retval;
}


x86 assembly (clang, -O0):
<read_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1050 <inet_aton@plt>
cmp    $0x0,%eax
jne    1196 <read_ip+0x66>
mov    -0x8(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     118a <read_ip+0x5a>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1191 <read_ip+0x61>
movl   $0x0,-0x24(%rbp)
jmp    1196 <read_ip+0x66>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_ip>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rsi
call   1050 <inet_aton@plt>
mov    $0x1,%ebp
test   %eax,%eax
jne    1170 <read_ip+0x40>
mov    %rbx,%rdi
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     116e <read_ip+0x3e>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    1170 <read_ip+0x40>
xor    %ebp,%ebp
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
mov    $0x8,%edx
call   1040 <memcpy@plt>
mov    %ebp,%eax
add    $0x10,%rsp
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
store i32 1, i32* %7
%8 = load i8*, i8** %3
%9 = call i32 @inet_aton(i8* %8, %struct.in_addr* %5)
%10 = icmp ne i32 %9, 0
br i1 %10, label %26, label %11
11: ; preds = %2
%12 = load i8*, i8** %3
%13 = call %struct.hostent* @gethostbyname(i8* %12)
store %struct.hostent* %13, %struct.hostent** %6
%14 = icmp ne %struct.hostent* %13, null
br i1 %14, label %15, label %24
15: ; preds = %11
%16 = load %struct.hostent*, %struct.hostent** %6
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %16, i32 0, i32 0
%18 = load i64*, i64** %17
%19 = getelementptr inbounds i64, i64* %18, i64 0
%20 = load i64, i64* %19
%21 = inttoptr i64 %20 to i64*
%22 = load i64, i64* %21
%23 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %5, i32 0, i32 0
store i64 %22, i64* %23
br label %25
24: ; preds = %11
store i32 0, i32* %7
br label %25
25: ; preds = %24, %15
br label %26
26: ; preds = %25, %2
%27 = load i8*, i8** %4
%28 = bitcast %struct.in_addr* %5 to i8*
%29 = call i32 @memcpy(i8* %27, i8* %28, i32 8)
%30 = load i32, i32* %7
ret i32 %30
}

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