#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 {
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
  TYPE_1__ sin_addr;
};
struct hostent {
  int /*<<< orphan*/ h_length;
  int /*<<< orphan*/ *h_addr_list;
};

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ bzero(struct sockaddr_in *, int);
struct hostent *gethostbyname(char *);
int /*<<< orphan*/ htons(int);
scalar_t__ malloc(int);
int /*<<< orphan*/ memcpy(TYPE_1__ *, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
struct sockaddr_in *creerSockAddr(char *name, int port) {
  struct sockaddr_in *adsock =
      (struct sockaddr_in *)malloc(sizeof(struct sockaddr_in));
  struct hostent *haddr = NULL;
  bzero(adsock, sizeof(struct sockaddr_in));
  if (name) {
    haddr = gethostbyname(name);
    if (haddr <= 0) {
      perror("Nom de machine inconnu");
    } else {
      memcpy(&(adsock->sin_addr), haddr->h_addr_list[0], haddr->h_length);
    }
  } else {
    adsock->sin_addr.s_addr = INADDR_ANY;
  }
  adsock->sin_family = AF_INET;
  adsock->sin_port = htons(port);
  return (adsock);
}


x86 assembly (clang, -O0):
<creerSockAddr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
cmpq   $0x0,-0x8(%rbp)
je     11e9 <creerSockAddr+0x89>
mov    -0x8(%rbp),%rdi
call   1040 <gethostbyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
ja     11c7 <creerSockAddr+0x67>
lea    0xe43(%rip),%rdi
call   1070 <perror@plt>
jmp    11e4 <creerSockAddr+0x84>
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
mov    -0x20(%rbp),%rax
mov    0x8(%rax),%rax
mov    (%rax),%esi
mov    -0x20(%rbp),%rax
mov    (%rax),%edx
call   1050 <memcpy@plt>
jmp    11f9 <creerSockAddr+0x99>
mov    0x2df0(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2de8(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0xc(%rbp),%edi
call   1030 <htons@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creerSockAddr>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
mov    $0xc,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0xc,%esi
call   1080 <bzero@plt>
test   %rbp,%rbp
je     11ac <creerSockAddr+0x4c>
mov    %rbp,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     11d6 <creerSockAddr+0x76>
mov    %rbx,%rdi
add    $0x8,%rdi
mov    0x8(%rax),%rcx
mov    (%rcx),%esi
mov    (%rax),%edx
call   1050 <memcpy@plt>
jmp    11b8 <creerSockAddr+0x58>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2e29(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x4(%rbx)
mov    %r14d,%edi
call   1030 <htons@plt>
mov    %eax,(%rbx)
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe23(%rip),%rdi
call   1070 <perror@plt>
jmp    11b8 <creerSockAddr+0x58>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32* }
@.str = [23 x i8] c"Nom de machine inconnu\00"
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
define %struct.sockaddr_in* @creerSockAddr(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca %struct.sockaddr_in*
%6 = alloca %struct.hostent*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = call i64 @malloc(i32 12)
%8 = inttoptr i64 %7 to %struct.sockaddr_in*
store %struct.sockaddr_in* %8, %struct.sockaddr_in** %5
store %struct.hostent* null, %struct.hostent** %6
%9 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%10 = call i32 @bzero(%struct.sockaddr_in* %9, i32 12)
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %33
13: ; preds = %2
%14 = load i8*, i8** %3
%15 = call %struct.hostent* @gethostbyname(i8* %14)
store %struct.hostent* %15, %struct.hostent** %6
%16 = load %struct.hostent*, %struct.hostent** %6
%17 = icmp ule %struct.hostent* %16, null
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %32
20: ; preds = %13
%21 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %21, i32 0, i32 2
%23 = load %struct.hostent*, %struct.hostent** %6
%24 = getelementptr inbounds %struct.hostent, %struct.hostent* %23, i32 0, i32 1
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = load %struct.hostent*, %struct.hostent** %6
%29 = getelementptr inbounds %struct.hostent, %struct.hostent* %28, i32 0, i32 0
%30 = load i32, i32* %29
%31 = call i32 @memcpy(%struct.TYPE_2__* %22, i32 %27, i32 %30)
br label %32
32: ; preds = %20, %18
br label %38
33: ; preds = %2
%34 = load i32, i32* @INADDR_ANY
%35 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%36 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %35, i32 0, i32 2
%37 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %36, i32 0, i32 0
store i32 %34, i32* %37
br label %38
38: ; preds = %33, %32
%39 = load i32, i32* @AF_INET
%40 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%41 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %40, i32 0, i32 1
store i32 %39, i32* %41
%42 = load i32, i32* %4
%43 = call i32 @htons(i32 %42)
%44 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %44, i32 0, i32 0
store i32 %43, i32* %45
%46 = load %struct.sockaddr_in*, %struct.sockaddr_in** %5
ret %struct.sockaddr_in* %46
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i32, i32* }
@.str = [23 x i8] c"Nom de machine inconnu\00"
@INADDR_ANY = global i32 0
@AF_INET = global i32 0
define %struct.sockaddr_in* @creerSockAddr(i8* %0, i32 %1) {
%3 = tail call i64 @malloc(i32 12)
%4 = inttoptr i64 %3 to %struct.sockaddr_in*
%5 = tail call i32 @bzero(%struct.sockaddr_in* %4, i32 12)
%6 = icmp eq i8* %0, null
br i1 %6, label %20, label %7
7: ; preds = %2
%8 = tail call %struct.hostent* @gethostbyname(i8* %0)
%9 = icmp eq %struct.hostent* %8, null
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %23
12: ; preds = %7
%13 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
%14 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 1
%15 = load i32*, i32** %14
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%18 = load i32, i32* %17
%19 = tail call i32 @memcpy(%struct.TYPE_2__* %13, i32 %16, i32 %18)
br label %23
20: ; preds = %2
%21 = load i32, i32* @INADDR_ANY
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2, i32 0
store i32 %21, i32* %22
br label %23
23: ; preds = %10, %12, %20
%24 = load i32, i32* @AF_INET
%25 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %24, i32* %25
%26 = tail call i32 @htons(i32 %1)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %26, i32* %27
ret %struct.sockaddr_in* %4
}