#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 in_addr {
  int dummy;
};
struct hostent {
  scalar_t__ 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__ *, struct in_addr *, int);
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;
  struct in_addr **pptr;
  bzero(adsock, sizeof(struct sockaddr_in));
  if (name) {
    haddr = gethostbyname(name);
    if (haddr <= 0) {
      perror("Nom de machine inconnu");
    } else {
      pptr = (struct in_addr **)haddr->h_addr_list;
      memcpy(&adsock->sin_addr, *pptr, sizeof(struct in_addr));
    }
  } 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    $0x30,%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     11f0 <CreerSockAddr+0x90>
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    11eb <CreerSockAddr+0x8b>
mov    -0x20(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
add    $0x8,%rdi
mov    -0x28(%rbp),%rax
mov    (%rax),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
jmp    1200 <CreerSockAddr+0xa0>
mov    0x2de9(%rip),%rax
mov    (%rax),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,0x8(%rax)
mov    0x2de1(%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    $0x30,%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     11af <CreerSockAddr+0x4f>
mov    %rbp,%rdi
call   1040 <gethostbyname@plt>
test   %rax,%rax
je     11d9 <CreerSockAddr+0x79>
mov    (%rax),%rax
mov    %rbx,%rdi
add    $0x8,%rdi
mov    (%rax),%rsi
mov    $0x4,%edx
call   1050 <memcpy@plt>
jmp    11bb <CreerSockAddr+0x5b>
mov    0x2e2a(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x8(%rbx)
mov    0x2e26(%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    0xe20(%rip),%rdi
call   1070 <perror@plt>
jmp    11bb <CreerSockAddr+0x5b>

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

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, i32, %struct.TYPE_2__ }
%struct.TYPE_2__ = type { i32 }
%struct.hostent = type { i64 }
%struct.in_addr = type { 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 %19, 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 %22
12: ; preds = %7
%13 = getelementptr inbounds %struct.hostent, %struct.hostent* %8, i64 0, i32 0
%14 = load i64, i64* %13
%15 = inttoptr i64 %14 to %struct.in_addr**
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
%17 = load %struct.in_addr*, %struct.in_addr** %15
%18 = tail call i32 @memcpy(%struct.TYPE_2__* %16, %struct.in_addr* %17, i32 4)
br label %22
19: ; preds = %2
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2, i32 0
store i32 %20, i32* %21
br label %22
22: ; preds = %10, %12, %19
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1
store i32 %23, i32* %24
%25 = tail call i32 @htons(i32 %1)
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %25, i32* %26
ret %struct.sockaddr_in* %4
}