#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 addrinfo {
  int /*<<< orphan*/ ai_addrlen;
  int /*<<< orphan*/ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  int /*<<< orphan*/ ai_family;
  struct addrinfo *ai_next;
};
typedef int /*<<< orphan*/ hints;

/* Variables and functions */
int /*<<< orphan*/ AF_UNSPEC;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
int connect(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int make_socket(char *host, char *port) {
  struct addrinfo hints, *servinfo, *p;
  int sock, r;
  memset(&hints, 0, sizeof(hints));
  hints.ai_family = AF_UNSPEC;
  hints.ai_socktype = SOCK_STREAM;
  if ((r = getaddrinfo(host, port, &hints, &servinfo)) != 0) {
    fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(r));
    exit(0);
  }
  for (p = servinfo; p != NULL; p = p->ai_next) {
    if ((sock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
      continue;
    }
    if (connect(sock, p->ai_addr, p->ai_addrlen) == -1) {
      close(sock);
      continue;
    }
    break;
  }
  if (p == NULL) {
    if (servinfo)
      freeaddrinfo(servinfo);
    fprintf(stderr, "Konekciju nije moguce napraviti\n");
    exit(0);
  }
  if (servinfo)
    freeaddrinfo(servinfo);
  fprintf(stderr, "[Konektovan -> %s:%s]\n", host, port);
  return sock;
}


x86 assembly (clang, -O0):
<make_socket>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    0x2e31(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    0x2e0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
lea    -0x30(%rbp),%rdx
lea    -0x38(%rbp),%rcx
call   1090 <getaddrinfo@plt>
mov    %eax,-0x48(%rbp)
cmp    $0x0,%eax
je     1218 <make_socket+0x88>
mov    0x2de8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x48(%rbp),%edi
call   1030 <gai_strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xdf6(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
je     1297 <make_socket+0x107>
mov    -0x40(%rbp),%rax
mov    0x10(%rax),%edi
mov    -0x40(%rbp),%rax
mov    0xc(%rax),%esi
mov    -0x40(%rbp),%rax
mov    0x8(%rax),%edx
call   10b0 <socket@plt>
mov    %eax,-0x44(%rbp)
cmp    $0xffffffff,%eax
jne    1256 <make_socket+0xc6>
jmp    1286 <make_socket+0xf6>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rax
mov    0x4(%rax),%esi
mov    -0x40(%rbp),%rax
mov    (%rax),%edx
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
jne    1281 <make_socket+0xf1>
mov    -0x44(%rbp),%edi
call   1050 <close@plt>
jmp    1286 <make_socket+0xf6>
jmp    1297 <make_socket+0x107>
mov    -0x40(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1220 <make_socket+0x90>
cmpq   $0x0,-0x40(%rbp)
jne    12d4 <make_socket+0x144>
cmpq   $0x0,-0x38(%rbp)
je     12b6 <make_socket+0x126>
mov    -0x38(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    0x2d1b(%rip),%rax
mov    (%rax),%edi
lea    0xd4b(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
je     12e8 <make_socket+0x158>
mov    -0x38(%rbp),%rdi
call   10a0 <freeaddrinfo@plt>
mov    0x2ce9(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    0xd32(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x44(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_socket>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0x8(%rsp),%rbp
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1040 <memset@plt>
mov    0x2e2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x18(%rsp)
mov    0x2e08(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x14(%rsp)
mov    %rsp,%rcx
mov    %r15,%rdi
mov    %r14,%rsi
mov    %rbp,%rdx
call   1090 <getaddrinfo@plt>
test   %eax,%eax
jne    129a <make_socket+0x10a>
mov    (%rsp),%rbx
test   %rbx,%rbx
jne    1210 <make_socket+0x80>
jmp    127c <make_socket+0xec>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x18(%rbx),%rbx
test   %rbx,%rbx
je     126e <make_socket+0xde>
mov    0x10(%rbx),%edi
mov    0x8(%rbx),%edx
mov    0xc(%rbx),%esi
call   10b0 <socket@plt>
cmp    $0xffffffff,%eax
je     1207 <make_socket+0x77>
mov    %eax,%ebp
mov    (%rbx),%edx
mov    0x4(%rbx),%esi
mov    %eax,%edi
call   1080 <connect@plt>
cmp    $0xffffffff,%eax
je     1200 <make_socket+0x70>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     1244 <make_socket+0xb4>
call   10a0 <freeaddrinfo@plt>
mov    0x2d8d(%rip),%rax
mov    (%rax),%edi
lea    0xdde(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    (%rsp),%rdi
test   %rdi,%rdi
je     127c <make_socket+0xec>
call   10a0 <freeaddrinfo@plt>
mov    0x2d55(%rip),%rax
mov    (%rax),%edi
lea    0xd85(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
mov    0x2d37(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1030 <gai_strerror@plt>
lea    0xd4f(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.1 = [33 x i8] c"Konekciju nije moguce napraviti\0A\00"
@.str.2 = [23 x i8] c"[Konektovan -> %s:%s]\0A\00"
define i32 @make_socket(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.addrinfo
%6 = alloca %struct.addrinfo*
%7 = alloca %struct.addrinfo*
%8 = alloca i32
%9 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 32)
%11 = load i32, i32* @AF_UNSPEC
%12 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 4
store i32 %11, i32* %12
%13 = load i32, i32* @SOCK_STREAM
%14 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i32 0, i32 3
store i32 %13, i32* %14
%15 = load i8*, i8** %3
%16 = load i8*, i8** %4
%17 = call i32 @getaddrinfo(i8* %15, i8* %16, %struct.addrinfo* %5, %struct.addrinfo** %6)
store i32 %17, i32* %9
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i32, i32* %9
%22 = call i8* @gai_strerror(i32 %21)
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %2
%26 = load %struct.addrinfo*, %struct.addrinfo** %6
store %struct.addrinfo* %26, %struct.addrinfo** %7
br label %27
27: ; preds = %57, %25
%28 = load %struct.addrinfo*, %struct.addrinfo** %7
%29 = icmp ne %struct.addrinfo* %28, null
br i1 %29, label %30, label %61
30: ; preds = %27
%31 = load %struct.addrinfo*, %struct.addrinfo** %7
%32 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %31, i32 0, i32 4
%33 = load i32, i32* %32
%34 = load %struct.addrinfo*, %struct.addrinfo** %7
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %34, i32 0, i32 3
%36 = load i32, i32* %35
%37 = load %struct.addrinfo*, %struct.addrinfo** %7
%38 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %37, i32 0, i32 2
%39 = load i32, i32* %38
%40 = call i32 @socket(i32 %33, i32 %36, i32 %39)
store i32 %40, i32* %8
%41 = icmp eq i32 %40, -1
br i1 %41, label %42, label %43
42: ; preds = %30
br label %57
43: ; preds = %30
%44 = load i32, i32* %8
%45 = load %struct.addrinfo*, %struct.addrinfo** %7
%46 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %45, i32 0, i32 1
%47 = load i32, i32* %46
%48 = load %struct.addrinfo*, %struct.addrinfo** %7
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %48, i32 0, i32 0
%50 = load i32, i32* %49
%51 = call i32 @connect(i32 %44, i32 %47, i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %56
53: ; preds = %43
%54 = load i32, i32* %8
%55 = call i32 @close(i32 %54)
br label %57
56: ; preds = %43
br label %61
57: ; preds = %53, %42
%58 = load %struct.addrinfo*, %struct.addrinfo** %7
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %58, i32 0, i32 5
%60 = load %struct.addrinfo*, %struct.addrinfo** %59
store %struct.addrinfo* %60, %struct.addrinfo** %7
br label %27
61: ; preds = %56, %27
%62 = load %struct.addrinfo*, %struct.addrinfo** %7
%63 = icmp eq %struct.addrinfo* %62, null
br i1 %63, label %64, label %74
64: ; preds = %61
%65 = load %struct.addrinfo*, %struct.addrinfo** %6
%66 = icmp ne %struct.addrinfo* %65, null
br i1 %66, label %67, label %70
67: ; preds = %64
%68 = load %struct.addrinfo*, %struct.addrinfo** %6
%69 = call i32 @freeaddrinfo(%struct.addrinfo* %68)
br label %70
70: ; preds = %67, %64
%71 = load i32, i32* @stderr
%72 = call i32 (i32, i8*, ...) @fprintf(i32 %71, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%73 = call i32 @exit(i32 0)
unreachable
74: ; preds = %61
%75 = load %struct.addrinfo*, %struct.addrinfo** %6
%76 = icmp ne %struct.addrinfo* %75, null
br i1 %76, label %77, label %80
77: ; preds = %74
%78 = load %struct.addrinfo*, %struct.addrinfo** %6
%79 = call i32 @freeaddrinfo(%struct.addrinfo* %78)
br label %80
80: ; preds = %77, %74
%81 = load i32, i32* @stderr
%82 = load i8*, i8** %3
%83 = load i8*, i8** %4
%84 = call i32 (i32, i8*, ...) @fprintf(i32 %81, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %82, i8* %83)
%85 = load i32, i32* %8
ret i32 %85
}

LLVM IR (-O2):
%struct.addrinfo = type { i32, i32, i32, i32, i32, %struct.addrinfo* }
@AF_UNSPEC = global i32 0
@SOCK_STREAM = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"getaddrinfo: %s\0A\00"
@.str.1 = [33 x i8] c"Konekciju nije moguce napraviti\0A\00"
@.str.2 = [23 x i8] c"[Konektovan -> %s:%s]\0A\00"
define i32 @make_socket(i8* %0, i8* %1) {
%3 = alloca %struct.addrinfo
%4 = alloca %struct.addrinfo*
%5 = bitcast %struct.addrinfo* %3 to i8*
%6 = bitcast %struct.addrinfo** %4 to i8*
%7 = call i32 @memset(%struct.addrinfo* %3, i32 0, i32 32)
%8 = load i32, i32* @AF_UNSPEC
%9 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 4
store i32 %8, i32* %9
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %3, i64 0, i32 3
store i32 %10, i32* %11
%12 = call i32 @getaddrinfo(i8* %0, i8* %1, %struct.addrinfo* %3, %struct.addrinfo** %4)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = load %struct.addrinfo*, %struct.addrinfo** %4
%16 = icmp eq %struct.addrinfo* %15, null
br i1 %16, label %50, label %22
17: ; preds = %2
%18 = load i32, i32* @stderr
%19 = call i8* @gai_strerror(i32 %12)
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 0)
unreachable
22: ; preds = %14, %41
%23 = phi %struct.addrinfo* [ %43, %41 ], [ %15, %14 ]
%24 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 4
%25 = load i32, i32* %24
%26 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 3
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 2
%29 = load i32, i32* %28
%30 = call i32 @socket(i32 %25, i32 %27, i32 %29)
%31 = icmp eq i32 %30, -1
br i1 %31, label %41, label %32
32: ; preds = %22
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 1
%34 = load i32, i32* %33
%35 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 0
%36 = load i32, i32* %35
%37 = call i32 @connect(i32 %30, i32 %34, i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %54
39: ; preds = %32
%40 = call i32 @close(i32 %30)
br label %41
41: ; preds = %22, %39
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %23, i64 0, i32 5
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %22
45: ; preds = %41
%46 = load %struct.addrinfo*, %struct.addrinfo** %4
%47 = icmp eq %struct.addrinfo* %46, null
br i1 %47, label %50, label %48
48: ; preds = %45
%49 = call i32 @freeaddrinfo(%struct.addrinfo* %46)
br label %50
50: ; preds = %14, %48, %45
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0))
%53 = call i32 @exit(i32 0)
unreachable
54: ; preds = %32
%55 = load %struct.addrinfo*, %struct.addrinfo** %4
%56 = icmp eq %struct.addrinfo* %55, null
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 @freeaddrinfo(%struct.addrinfo* %55)
br label %59
59: ; preds = %57, %54
%60 = load i32, i32* @stderr
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %60, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1)
ret i32 %30
}