#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 sockaddr_in {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
};

/* Variables and functions */
struct addrinfo *getAddrInfo(char *, char *, int);
int /*<<< orphan*/ perror(char *);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
struct sockaddr_in *creerSock(char *name, char *port, int type, int *sockId) {
  struct addrinfo *res;
  res = getAddrInfo(name, port, type);
  if ((*sockId = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) <=
      0) {
    perror("\n pb creation socket \n");
  }
  return ((struct sockaddr_in *)res->ai_addr);
}


x86 assembly (clang, -O0):
<creerSock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <getAddrInfo@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x28(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x28(%rbp),%rax
mov    0x8(%rax),%edx
call   1050 <socket@plt>
mov    -0x20(%rbp),%rcx
mov    %eax,(%rcx)
cmp    $0x0,%eax
jg     1190 <creerSock+0x60>
lea    0xe75(%rip),%rdi
call   1040 <perror@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<creerSock>:
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
call   1030 <getAddrInfo@plt>
mov    %rax,%rbx
mov    0x10(%rax),%edi
mov    0x8(%rax),%edx
mov    0xc(%rax),%esi
call   1050 <socket@plt>
mov    %eax,(%r14)
test   %eax,%eax
jle    115f <creerSock+0x2f>
mov    (%rbx),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe9a(%rip),%rdi
call   1040 <perror@plt>
jmp    1154 <creerSock+0x24>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32 }
%struct.addrinfo = type { i64, i32, i32, i32 }
@.str = [23 x i8] c"\0A pb creation socket \0A\00"
define %struct.sockaddr_in* @creerSock(i8* %0, i8* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca %struct.addrinfo*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
%10 = load i8*, i8** %5
%11 = load i8*, i8** %6
%12 = load i32, i32* %7
%13 = call %struct.addrinfo* @getAddrInfo(i8* %10, i8* %11, i32 %12)
store %struct.addrinfo* %13, %struct.addrinfo** %9
%14 = load %struct.addrinfo*, %struct.addrinfo** %9
%15 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %14, i32 0, i32 3
%16 = load i32, i32* %15
%17 = load %struct.addrinfo*, %struct.addrinfo** %9
%18 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %17, i32 0, i32 2
%19 = load i32, i32* %18
%20 = load %struct.addrinfo*, %struct.addrinfo** %9
%21 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %20, i32 0, i32 1
%22 = load i32, i32* %21
%23 = call i32 @socket(i32 %16, i32 %19, i32 %22)
%24 = load i32*, i32** %8
store i32 %23, i32* %24
%25 = icmp sle i32 %23, 0
br i1 %25, label %26, label %28
26: ; preds = %4
%27 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %28
28: ; preds = %26, %4
%29 = load %struct.addrinfo*, %struct.addrinfo** %9
%30 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %29, i32 0, i32 0
%31 = load i64, i64* %30
%32 = inttoptr i64 %31 to %struct.sockaddr_in*
ret %struct.sockaddr_in* %32
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32 }
%struct.addrinfo = type { i64, i32, i32, i32 }
@.str = [23 x i8] c"\0A pb creation socket \0A\00"
define %struct.sockaddr_in* @creerSock(i8* %0, i8* %1, i32 %2, i32* nocapture writeonly %3) {
%5 = tail call %struct.addrinfo* @getAddrInfo(i8* %0, i8* %1, i32 %2)
%6 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 3
%7 = load i32, i32* %6
%8 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 2
%9 = load i32, i32* %8
%10 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 1
%11 = load i32, i32* %10
%12 = tail call i32 @socket(i32 %7, i32 %9, i32 %11)
store i32 %12, i32* %3
%13 = icmp slt i32 %12, 1
br i1 %13, label %14, label %16
14: ; preds = %4
%15 = tail call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %14, %4
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 0
%18 = load i64, i64* %17
%19 = inttoptr i64 %18 to %struct.sockaddr_in*
ret %struct.sockaddr_in* %19
}