#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 */
typedef int /*<<< orphan*/ uint8_t;
struct in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ h_addr_list;
};

/* Variables and functions */
struct hostent *gethostbyname(int /*<<< orphan*/ *);
int /*<<< orphan*/ inet_ntoa(struct in_addr);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcpy(int /*<<< orphan*/ *, int /*<<< orphan*/);
int host_to_ip(uint8_t *ip, uint8_t *name) {
  int i;
  struct hostent *he;
  struct in_addr **addr_list;
  if ((he = gethostbyname(name)) == NULL) {
    printf("\nERR: Cannot get host by name"
           "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
           "2022-01-22/02-19-57/repos/arekkusztal/Network/refs/heads/master/"
           "protocols/smtpclient/smtp_utils.c");
    return -1;
  }
  addr_list = (struct in_addr **)he->h_addr_list;
  for (i = 0; addr_list[i] != NULL; i++) {
    strcpy(ip, inet_ntoa(*addr_list[i]));
    return 0;
  }
  return -1;
}


x86 assembly (clang, -O0):
<host_to_ip>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    117f <host_to_ip+0x3f>
lea    0xe92(%rip),%rdi
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11dd <host_to_ip+0x9d>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11d6 <host_to_ip+0x96>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
movl   $0x0,-0x4(%rbp)
jmp    11dd <host_to_ip+0x9d>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<host_to_ip>:
push   %rbx
mov    %rdi,%rbx
mov    %rsi,%rdi
call   1060 <gethostbyname@plt>
test   %rax,%rax
je     1171 <host_to_ip+0x31>
mov    (%rax),%rax
mov    (%rax),%rax
test   %rax,%rax
je     117d <host_to_ip+0x3d>
mov    (%rax),%edi
call   1040 <inet_ntoa@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe88(%rip),%rdi
call   1050 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [191 x i8] c"\0AERR: Cannot get host by name/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/arekkusztal/Network/refs/heads/master/protocols/smtpclient/smtp_utils.c\00"
define i32 @host_to_ip(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i32
%7 = alloca %struct.hostent*
%8 = alloca %struct.in_addr**
store i32* %0, i32** %4
store i32* %1, i32** %5
%9 = load i32*, i32** %5
%10 = call %struct.hostent* @gethostbyname(i32* %9)
store %struct.hostent* %10, %struct.hostent** %7
%11 = icmp eq %struct.hostent* %10, null
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([191 x i8], [191 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %41
14: ; preds = %2
%15 = load %struct.hostent*, %struct.hostent** %7
%16 = getelementptr inbounds %struct.hostent, %struct.hostent* %15, i32 0, i32 0
%17 = load i64, i64* %16
%18 = inttoptr i64 %17 to %struct.in_addr**
store %struct.in_addr** %18, %struct.in_addr*** %8
store i32 0, i32* %6
br label %19
19: ; preds = %37, %14
%20 = load %struct.in_addr**, %struct.in_addr*** %8
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %20, i64 %22
%24 = load %struct.in_addr*, %struct.in_addr** %23
%25 = icmp ne %struct.in_addr* %24, null
br i1 %25, label %26, label %40
26: ; preds = %19
%27 = load i32*, i32** %4
%28 = load %struct.in_addr**, %struct.in_addr*** %8
%29 = load i32, i32* %6
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds %struct.in_addr*, %struct.in_addr** %28, i64 %30
%32 = load %struct.in_addr*, %struct.in_addr** %31
%33 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %32, i32 0, i32 0
%34 = load i32, i32* %33
%35 = call i32 @inet_ntoa(i32 %34)
%36 = call i32 @strcpy(i32* %27, i32 %35)
store i32 0, i32* %3
br label %41
37: ; No predecessors!
%38 = load i32, i32* %6
%39 = add nsw i32 %38, 1
store i32 %39, i32* %6
br label %19
40: ; preds = %19
store i32 -1, i32* %3
br label %41
41: ; preds = %40, %26, %12
%42 = load i32, i32* %3
ret i32 %42
}

LLVM IR (-O2):
%struct.hostent = type { i64 }
%struct.in_addr = type { i32 }
@.str = [191 x i8] c"\0AERR: Cannot get host by name/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/arekkusztal/Network/refs/heads/master/protocols/smtpclient/smtp_utils.c\00"
define i32 @host_to_ip(i32* %0, i32* %1) {
%3 = tail call %struct.hostent* @gethostbyname(i32* %1)
%4 = icmp eq %struct.hostent* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([191 x i8], [191 x i8]* @.str, i64 0, i64 0))
br label %18
7: ; preds = %2
%8 = getelementptr inbounds %struct.hostent, %struct.hostent* %3, i64 0, i32 0
%9 = load i64, i64* %8
%10 = inttoptr i64 %9 to %struct.in_addr**
%11 = load %struct.in_addr*, %struct.in_addr** %10
%12 = icmp eq %struct.in_addr* %11, null
br i1 %12, label %18, label %13
13: ; preds = %7
%14 = getelementptr inbounds %struct.in_addr, %struct.in_addr* %11, i64 0, i32 0
%15 = load i32, i32* %14
%16 = tail call i32 @inet_ntoa(i32 %15)
%17 = tail call i32 @strcpy(i32* %0, i32 %16)
br label %18
18: ; preds = %7, %13, %5
%19 = phi i32 [ -1, %5 ], [ 0, %13 ], [ -1, %7 ]
ret i32 %19
}