#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 hostent {
  scalar_t__ h_addr;
};

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
unsigned long inet_addr(char *);
int /*<<< orphan*/ stderr;
unsigned long int get_ip_addr(char *str) {
  struct hostent *hostp;
  unsigned long int addr;
  if ((addr = inet_addr(str)) == -1) {
    if ((hostp = gethostbyname(str)))
      return *(unsigned long int *)(hostp->h_addr);
    else {
      fprintf(stderr, "unknown host %s\n", str);
    }
  }
  return addr;
}


x86 assembly (clang, -O0):
<get_ip_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <inet_addr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0xffffffffffffffff,%rax
jne    119b <get_ip_addr+0x6b>
mov    -0x10(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     117d <get_ip_addr+0x4d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x8(%rbp)
jmp    11a3 <get_ip_addr+0x73>
mov    0x2e5c(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe6f(%rip),%rsi
call   1050 <fprintf@plt>
jmp    119b <get_ip_addr+0x6b>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip_addr>:
push   %rbx
mov    %rdi,%rbx
call   1030 <inet_addr@plt>
cmp    $0xffffffffffffffff,%rax
je     1141 <get_ip_addr+0x11>
pop    %rbx
ret
mov    %rbx,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     1156 <get_ip_addr+0x26>
mov    (%rax),%rax
mov    (%rax),%rax
pop    %rbx
ret
mov    0x2e83(%rip),%rax
mov    (%rax),%edi
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
mov    $0xffffffffffffffff,%rax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
@stderr = global i32 0
@.str = [17 x i8] c"unknown host %s\0A\00"
define i64 @get_ip_addr(i8* %0) {
%2 = alloca i64
%3 = alloca i8*
%4 = alloca %struct.hostent*
%5 = alloca i64
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i64 @inet_addr(i8* %6)
store i64 %7, i64* %5
%8 = icmp eq i64 %7, -1
br i1 %8, label %9, label %24
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call %struct.hostent* @gethostbyname(i8* %10)
store %struct.hostent* %11, %struct.hostent** %4
%12 = icmp ne %struct.hostent* %11, null
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = load %struct.hostent*, %struct.hostent** %4
%15 = getelementptr inbounds %struct.hostent, %struct.hostent* %14, i32 0, i32 0
%16 = load i64, i64* %15
%17 = inttoptr i64 %16 to i64*
%18 = load i64, i64* %17
store i64 %18, i64* %2
br label %26
19: ; preds = %9
%20 = load i32, i32* @stderr
%21 = load i8*, i8** %3
%22 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %21)
br label %23
23: ; preds = %19
br label %24
24: ; preds = %23, %1
%25 = load i64, i64* %5
store i64 %25, i64* %2
br label %26
26: ; preds = %24, %13
%27 = load i64, i64* %2
ret i64 %27
}

LLVM IR (-O2):
%struct.hostent = type { i64 }
@stderr = global i32 0
@.str = [17 x i8] c"unknown host %s\0A\00"
define i64 @get_ip_addr(i8* %0) {
%2 = tail call i64 @inet_addr(i8* %0)
%3 = icmp eq i64 %2, -1
br i1 %3, label %4, label %15
4: ; preds = %1
%5 = tail call %struct.hostent* @gethostbyname(i8* %0)
%6 = icmp eq %struct.hostent* %5, null
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %5, i64 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to i64*
%11 = load i64, i64* %10
br label %15
12: ; preds = %4
%13 = load i32, i32* @stderr
%14 = tail call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0)
br label %15
15: ; preds = %1, %12, %7
%16 = phi i64 [ %11, %7 ], [ -1, %12 ], [ %2, %1 ]
ret i64 %16
}