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

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
struct hostent *gethostbyname(char *);
int ntohl(int);
int /*<<< orphan*/ stderr;
int get_ip_address(char *hostname) {
  int **addr_list;
  struct hostent *answer;
  int ipaddr = 0;
  int b0, b1, b2, b3;
  if (NULL == (answer = gethostbyname(hostname))) {
    fprintf(stderr, "Cannot get address for host=%s\n", hostname);
    return (-1);
  }
  addr_list = (int **)answer->h_addr_list;
  ipaddr = ntohl(**addr_list);
  b0 = ipaddr >> 24;
  b1 = ipaddr >> 16;
  b2 = ipaddr >> 8;
  b3 = ipaddr;
  b0 &= 255;
  b1 &= 255;
  b2 &= 255;
  b3 &= 255;
  return (ipaddr);
}


x86 assembly (clang, -O0):
<get_ip_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <gethostbyname@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1183 <get_ip_address+0x53>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe8e(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f2 <get_ip_address+0xc2>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1050 <ntohl@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x18,%eax
mov    %eax,-0x28(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x24(%rbp),%eax
sar    $0x8,%eax
mov    %eax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x28(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x30(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
and    $0xff,%eax
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ip_address>:
push   %rbx
mov    %rdi,%rbx
call   1030 <gethostbyname@plt>
test   %rax,%rax
je     114c <get_ip_address+0x1c>
mov    (%rax),%rax
mov    (%rax),%rax
mov    (%rax),%edi
pop    %rbx
jmp    1050 <ntohl@plt>
mov    0x2e8d(%rip),%rax
mov    (%rax),%edi
lea    0xea4(%rip),%rsi
mov    %rbx,%rdx
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
@stderr = global i32 0
@.str = [32 x i8] c"Cannot get address for host=%s\0A\00"
define i32 @get_ip_address(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32**
%5 = alloca %struct.hostent*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %3
store i32 0, i32* %6
%11 = load i8*, i8** %3
%12 = call %struct.hostent* @gethostbyname(i8* %11)
store %struct.hostent* %12, %struct.hostent** %5
%13 = icmp eq %struct.hostent* null, %12
br i1 %13, label %14, label %18
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = load i8*, i8** %3
%17 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %16)
store i32 -1, i32* %2
br label %43
18: ; preds = %1
%19 = load %struct.hostent*, %struct.hostent** %5
%20 = getelementptr inbounds %struct.hostent, %struct.hostent* %19, i32 0, i32 0
%21 = load i64, i64* %20
%22 = inttoptr i64 %21 to i32**
store i32** %22, i32*** %4
%23 = load i32**, i32*** %4
%24 = load i32*, i32** %23
%25 = load i32, i32* %24
%26 = call i32 @ntohl(i32 %25)
store i32 %26, i32* %6
%27 = load i32, i32* %6
%28 = ashr i32 %27, 24
store i32 %28, i32* %7
%29 = load i32, i32* %6
%30 = ashr i32 %29, 16
store i32 %30, i32* %8
%31 = load i32, i32* %6
%32 = ashr i32 %31, 8
store i32 %32, i32* %9
%33 = load i32, i32* %6
store i32 %33, i32* %10
%34 = load i32, i32* %7
%35 = and i32 %34, 255
store i32 %35, i32* %7
%36 = load i32, i32* %8
%37 = and i32 %36, 255
store i32 %37, i32* %8
%38 = load i32, i32* %9
%39 = and i32 %38, 255
store i32 %39, i32* %9
%40 = load i32, i32* %10
%41 = and i32 %40, 255
store i32 %41, i32* %10
%42 = load i32, i32* %6
store i32 %42, i32* %2
br label %43
43: ; preds = %18, %14
%44 = load i32, i32* %2
ret i32 %44
}

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