#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;
};
typedef int in_addr_t;

/* Variables and functions */
int /*<<< orphan*/ ft_dprintf(int, char *, ...);
struct hostent *gethostbyname(char *);
int inet_addr(char *);
char *inet_ntoa(struct in_addr);
in_addr_t get_addr(char *ip) {
  struct hostent *host;
  ft_dprintf(1, "Solve proxy\n");
  host = gethostbyname(ip);
  if (host)
    ip = inet_ntoa(*((struct in_addr *)host->h_addr));
  else
    return (-1);
  ft_dprintf(1, "%s\n", ip);
  return (inet_addr(ip));
}


x86 assembly (clang, -O0):
<get_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    $0x1,%edi
lea    0xea8(%rip),%rsi
mov    $0x0,%al
call   1060 <ft_dprintf@plt>
mov    -0x10(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     118e <get_addr+0x4e>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,-0x10(%rbp)
jmp    119a <get_addr+0x5a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bd <get_addr+0x7d>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe63(%rip),%rsi
mov    $0x0,%al
call   1060 <ft_dprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <inet_addr@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_addr>:
push   %rbx
mov    %rdi,%rbx
lea    0xeb5(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1060 <ft_dprintf@plt>
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
test   %rax,%rax
je     1190 <get_addr+0x50>
mov    (%rax),%rax
mov    (%rax),%edi
call   1030 <inet_ntoa@plt>
mov    %rax,%rbx
lea    0xe95(%rip),%rsi
mov    $0x1,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <ft_dprintf@plt>
mov    %rbx,%rdi
pop    %rbx
jmp    1040 <inet_addr@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

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

LLVM IR (-O2):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [13 x i8] c"Solve proxy\0A\00"
@.str.1 = [4 x i8] c"%s\0A\00"
define i32 @get_addr(i8* %0) {
%2 = tail call i32 (i32, i8*, ...) @ft_dprintf(i32 1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%3 = tail call %struct.hostent* @gethostbyname(i8* %0)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %14, label %5
5: ; preds = %1
%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 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %8, i64 0, i32 0
%10 = load i32, i32* %9
%11 = tail call i8* @inet_ntoa(i32 %10)
%12 = tail call i32 (i32, i8*, ...) @ft_dprintf(i32 1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call i32 @inet_addr(i8* %11)
br label %14
14: ; preds = %1, %5
%15 = phi i32 [ %13, %5 ], [ -1, %1 ]
ret i32 %15
}