#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 */
typedef struct TYPE_2__ TYPE_1__;

/* Type definitions */
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct hostent {
  char **h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
struct hostent *gethostbyname(char const *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ logStuff(char *);
int /*<<< orphan*/ logerr();
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, char *, int);
struct sockaddr_in getipa(const char *hostname, int port) {
  struct sockaddr_in ipa;
  ipa.sin_family = AF_INET;
  ipa.sin_port = htons(port);
  struct hostent *localhost = gethostbyname(hostname);
  logStuff(("Resolution de localhost"));
  if ((!localhost)) {
    logerr();
    return (ipa);
  };
  char *addr = localhost->h_addr_list[0];
  memcpy(&ipa.sin_addr.s_addr, addr, sizeof addr);
  return ipa;
}


x86 assembly (clang, -O0):
<getipa>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x18(%rbp)
mov    %esi,-0x1c(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    -0x1c(%rbp),%edi
call   1040 <htons@plt>
mov    %eax,-0xc(%rbp)
mov    -0x18(%rbp),%rdi
call   1050 <gethostbyname@plt>
mov    %rax,-0x28(%rbp)
lea    0xe76(%rip),%rdi
call   1030 <logStuff@plt>
cmpq   $0x0,-0x28(%rbp)
jne    11a6 <getipa+0x56>
mov    $0x0,%al
call   1070 <logerr@plt>
jmp    11c6 <getipa+0x76>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
lea    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    -0x38(%rbp),%edx
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getipa>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
mov    %rdi,%rbx
mov    0x2e88(%rip),%rax
mov    (%rax),%ebp
mov    %ebp,0x10(%rsp)
mov    %esi,%edi
call   1040 <htons@plt>
mov    %eax,0xc(%rsp)
mov    %rbx,%rdi
call   1050 <gethostbyname@plt>
mov    %rax,%rbx
lea    0xe7d(%rip),%rdi
call   1030 <logStuff@plt>
test   %rbx,%rbx
je     11a8 <getipa+0x58>
mov    (%rbx),%rax
mov    (%rax),%rsi
lea    0x8(%rsp),%rdi
mov    $0x8,%edx
call   1060 <memcpy@plt>
mov    0x10(%rsp),%ebp
jmp    11af <getipa+0x5f>
xor    %eax,%eax
call   1070 <logerr@plt>
mov    0x8(%rsp),%rax
mov    %ebp,%edx
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8** }
@AF_INET = global i32 0
@.str = [24 x i8] c"Resolution de localhost\00"
define { i64, i32 } @getipa(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.hostent*
%7 = alloca i8*
%8 = alloca { i64, i32 }
store i8* %0, i8** %4
store i32 %1, i32* %5
%9 = load i32, i32* @AF_INET
%10 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 2
store i32 %9, i32* %10
%11 = load i32, i32* %5
%12 = call i32 @htons(i32 %11)
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 1
store i32 %12, i32* %13
%14 = load i8*, i8** %4
%15 = call %struct.hostent* @gethostbyname(i8* %14)
store %struct.hostent* %15, %struct.hostent** %6
%16 = call i32 @logStuff(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%17 = load %struct.hostent*, %struct.hostent** %6
%18 = icmp ne %struct.hostent* %17, null
br i1 %18, label %21, label %19
19: ; preds = %2
%20 = call i32 (...) @logerr()
br label %31
21: ; preds = %2
%22 = load %struct.hostent*, %struct.hostent** %6
%23 = getelementptr inbounds %struct.hostent, %struct.hostent* %22, i32 0, i32 0
%24 = load i8**, i8*** %23
%25 = getelementptr inbounds i8*, i8** %24, i64 0
%26 = load i8*, i8** %25
store i8* %26, i8** %7
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i32 0, i32 0
%28 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %27, i32 0, i32 0
%29 = load i8*, i8** %7
%30 = call i32 @memcpy(i32* %28, i8* %29, i32 8)
br label %31
31: ; preds = %21, %19
%32 = bitcast { i64, i32 }* %8 to i8*
%33 = bitcast %struct.sockaddr_in* %3 to i8*
%34 = load { i64, i32 }, { i64, i32 }* %8
ret { i64, i32 } %34
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i8** }
@AF_INET = global i32 0
@.str = [24 x i8] c"Resolution de localhost\00"
define { i64, i32 } @getipa(i8* %0, i32 %1) {
%3 = alloca %struct.sockaddr_in
%4 = load i32, i32* @AF_INET
%5 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %4, i32* %5
%6 = tail call i32 @htons(i32 %1)
%7 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %6, i32* %7
%8 = tail call %struct.hostent* @gethostbyname(i8* %0)
%9 = tail call i32 @logStuff(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq %struct.hostent* %8, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = tail call i32 (...) @logerr()
br label %20
13: ; preds = %2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%15 = load i8**, i8*** %14
%16 = load i8*, i8** %15
%17 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%18 = call i32 @memcpy(i32* %17, i8* %16, i32 8)
%19 = load i32, i32* %5
br label %20
20: ; preds = %13, %11
%21 = phi i32 [ %19, %13 ], [ %4, %11 ]
%22 = bitcast %struct.sockaddr_in* %3 to i64*
%23 = load i64, i64* %22
%24 = insertvalue { i64, i32 } poison, i64 %23, 0
%25 = insertvalue { i64, i32 } %24, i32 %21, 1
ret { i64, i32 } %25
}