#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_in6 {
  int /*<<< orphan*/ sin6_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_addr;
};
struct sockaddr {
  int dummy;
};
struct addrinfo {
  scalar_t__ ai_family;
  int /*<<< orphan*/ ai_addrlen;
  scalar_t__ ai_addr;
  int /*<<< orphan*/ ai_protocol;
  int /*<<< orphan*/ ai_socktype;
  struct addrinfo *ai_next;
};
typedef int /*<<< orphan*/ ipstr;

/* Variables and functions */
scalar_t__ AF_INET;
scalar_t__ AF_INET6;
scalar_t__ AF_UNSPEC;
int EXIT_FAILURE;
int INET6_ADDRSTRLEN;
int /*<<< orphan*/ SOCK_STREAM;
scalar_t__ bind(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, scalar_t__, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ freeaddrinfo(struct addrinfo *);
char *gai_strerror(int);
int getaddrinfo(char const *, char *, struct addrinfo *, struct addrinfo **);
int /*<<< orphan*/ inet_ntop(scalar_t__, void *, char *, int);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(struct addrinfo *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int socket(scalar_t__, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char const *, char *);
int createSocket(const char *dest, const char *type) {
  int resSocket = -1;
  char portStr[10];
  struct addrinfo *result, *rp, *sockAddr = NULL;
  struct addrinfo hints;
  memset(&hints, 0, sizeof hints);
  hints.ai_socktype = SOCK_STREAM;
  hints.ai_family = AF_UNSPEC;
  char ipstr[INET6_ADDRSTRLEN];
  printf("Resolving Server %s\n", dest);
  sprintf(portStr, "%d", 7777);
  int status = getaddrinfo(dest, portStr, &hints, &result);
  if (status != 0) {
    fprintf(stderr, "getaddrinfo error: %s\n", gai_strerror(status));
    exit(EXIT_FAILURE);
  }
  for (rp = result; rp != NULL; rp = rp->ai_next) {
    struct sockaddr *sa = (struct sockaddr *)rp->ai_addr;
    if (rp->ai_family == AF_INET) {
      sockAddr = rp;
      inet_ntop(rp->ai_family, (void *)&((struct sockaddr_in *)sa)->sin_addr,
                ipstr, sizeof(ipstr));
      break;
    } else if (rp->ai_family == AF_INET6) {
      sockAddr = rp;
      inet_ntop(rp->ai_family, (void *)&((struct sockaddr_in6 *)sa)->sin6_addr,
                ipstr, sizeof(ipstr));
      break;
    }
    printf("Address %s found\n", ipstr);
  }
  if (sockAddr == NULL) {
    printf("No valid address found!\n");
    exit(1);
  } else {
    printf("Using address %s\n", ipstr);
  }
  if ((resSocket = socket(sockAddr->ai_family, sockAddr->ai_socktype,
                          sockAddr->ai_protocol)) < 0) {
    perror("TCP Socket");
    exit(1);
  }
  printf("Socket created.\n");
  printf("Inhalt von type: %s\n", type);
  if (strcmp(type, "CLIENT") == 0) {
    printf("Client Socket\n");
    if (connect(resSocket, sockAddr->ai_addr, sockAddr->ai_addrlen) < 0) {
      printf("\n");
      perror("Connect");
      exit(1);
    }
  } else if (strcmp(type, "SERVER") == 0) {
    printf("Server Socket!\n");
    if (bind(resSocket, sockAddr->ai_addr, sockAddr->ai_addrlen) < 0) {
      perror("bind");
      exit(1);
    }
    if (listen(resSocket, 5) < 0) {
      perror("listen");
      close(resSocket);
      exit(1);
    }
  }
  freeaddrinfo(result);
  return resSocket;
}


x86 assembly (clang, -O0):
<createSocket>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0xffffffff,-0x14(%rbp)
movq   $0x0,-0x38(%rbp)
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1060 <memset@plt>
mov    0x2d7f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    0x2d93(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x60(%rbp)
mov    0x2d95(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x90(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x68(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x88(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xd73(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x1e(%rbp),%rdi
lea    0xd76(%rip),%rsi
mov    $0x1e61,%edx
call   10d0 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x1e(%rbp),%rsi
lea    -0x60(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1100 <getaddrinfo@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0x0,-0x74(%rbp)
je     1305 <createSocket+0x105>
mov    0x2cee(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x94(%rbp)
mov    -0x74(%rbp),%edi
call   1050 <gai_strerror@plt>
mov    -0x94(%rbp),%edi
mov    %rax,%rdx
lea    0xd26(%rip),%rsi
call   1090 <fprintf@plt>
mov    0x2cb2(%rip),%rax
mov    (%rax),%edi
call   10e0 <exit@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     13d7 <createSocket+0x1d7>
mov    -0x30(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x80(%rbp)
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    0x2cae(%rip),%rcx
cmp    (%rcx),%rax
jne    1368 <createSocket+0x168>
mov    -0x88(%rbp),%rdx
mov    -0x90(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,-0x38(%rbp)
mov    -0x30(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
jmp    13d7 <createSocket+0x1d7>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    0x2c5a(%rip),%rcx
cmp    (%rcx),%rax
jne    13ac <createSocket+0x1ac>
mov    -0x88(%rbp),%rdx
mov    -0x90(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,-0x38(%rbp)
mov    -0x30(%rbp),%rcx
mov    (%rcx),%rdi
mov    -0x80(%rbp),%rsi
mov    %eax,%ecx
call   1030 <inet_ntop@plt>
jmp    13d7 <createSocket+0x1d7>
jmp    13b1 <createSocket+0x1b1>
mov    -0x88(%rbp),%rsi
lea    0xc70(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x30(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    130d <createSocket+0x10d>
cmpq   $0x0,-0x38(%rbp)
jne    13fa <createSocket+0x1fa>
lea    0xc58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x88(%rbp),%rsi
lea    0xc52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rax
mov    (%rax),%rdi
mov    -0x38(%rbp),%rax
mov    0x1c(%rax),%esi
mov    -0x38(%rbp),%rax
mov    0x18(%rax),%edx
call   1120 <socket@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    144b <createSocket+0x24b>
lea    0xc30(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
lea    0xc25(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rsi
lea    0xc24(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
lea    0xc27(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    14dd <createSocket+0x2dd>
lea    0xc18(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   10f0 <connect@plt>
cmp    $0x0,%rax
jge    14d8 <createSocket+0x2d8>
lea    0xb9d(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xbea(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    157b <createSocket+0x37b>
mov    -0x10(%rbp),%rdi
lea    0xbd3(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    1576 <createSocket+0x376>
lea    0xbc4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    -0x38(%rbp),%rax
mov    0x10(%rax),%rsi
mov    -0x38(%rbp),%rax
mov    0x8(%rax),%edx
call   10b0 <bind@plt>
cmp    $0x0,%rax
jge    153c <createSocket+0x33c>
lea    0xba5(%rip),%rdi
call   10c0 <perror@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    $0x5,%esi
call   10a0 <listen@plt>
cmp    $0x0,%rax
jge    1571 <createSocket+0x371>
lea    0xb7d(%rip),%rdi
call   10c0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    $0x1,%edi
call   10e0 <exit@plt>
jmp    1576 <createSocket+0x376>
jmp    157b <createSocket+0x37b>
mov    -0x28(%rbp),%rdi
call   1110 <freeaddrinfo@plt>
mov    -0x14(%rbp),%eax
mov    -0x68(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<createSocket>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,-0x40(%rbp)
mov    %rdi,%r12
lea    -0x80(%rbp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x28,%edx
call   1080 <memset@plt>
mov    %rsp,-0x38(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2d76(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x80(%rbp)
mov    0x2d78(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%r13
mov    %rax,-0x48(%rbp)
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r13
mov    %r13,%rsp
lea    0xd72(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xd76(%rip),%rsi
lea    -0x52(%rbp),%r14
mov    %r14,%rdi
mov    $0x1e61,%edx
call   10f0 <sprintf@plt>
lea    -0x30(%rbp),%rcx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1120 <getaddrinfo@plt>
test   %eax,%eax
jne    143f <createSocket+0x21f>
mov    -0x30(%rbp),%rbx
test   %rbx,%rbx
je     1313 <createSocket+0xf3>
mov    0x2d06(%rip),%r14
mov    0x2cef(%rip),%r15
lea    0xd47(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    (%rbx),%rdi
cmp    (%r14),%rdi
je     1329 <createSocket+0x109>
cmp    (%r15),%rdi
je     1329 <createSocket+0x109>
mov    %r12,%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rbx),%rbx
test   %rbx,%rbx
jne    12f0 <createSocket+0xd0>
lea    0xda8(%rip),%rdi
call   1050 <puts@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x10(%rbx),%rsi
mov    %r13,%rdx
mov    -0x48(%rbp),%rcx
call   1030 <inet_ntop@plt>
lea    0xd01(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    (%rbx),%rdi
mov    0x1c(%rbx),%esi
mov    0x18(%rbx),%edx
call   1140 <socket@plt>
test   %eax,%eax
js     146e <createSocket+0x24e>
mov    %eax,%r14d
lea    0xd2b(%rip),%rdi
call   1050 <puts@plt>
lea    0xce8(%rip),%rdi
mov    -0x40(%rbp),%r15
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xce8(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
je     1400 <createSocket+0x1e0>
lea    0xce3(%rip),%rsi
mov    %r15,%rdi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1420 <createSocket+0x200>
lea    0xcf2(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%rbx),%rsi
mov    0x8(%rbx),%edx
mov    %r14d,%edi
call   10d0 <bind@plt>
test   %rax,%rax
js     148a <createSocket+0x26a>
mov    %r14d,%edi
mov    $0x5,%esi
call   10c0 <listen@plt>
test   %rax,%rax
jns    1420 <createSocket+0x200>
lea    0xca5(%rip),%rdi
call   10e0 <perror@plt>
mov    %r14d,%edi
call   1090 <close@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xcad(%rip),%rdi
call   1050 <puts@plt>
mov    0x10(%rbx),%rsi
mov    0x8(%rbx),%edx
mov    %r14d,%edi
call   1110 <connect@plt>
test   %rax,%rax
js     1477 <createSocket+0x257>
mov    -0x30(%rbp),%rdi
call   1130 <freeaddrinfo@plt>
mov    -0x38(%rbp),%rsp
mov    %r14d,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2b7a(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1070 <gai_strerror@plt>
lea    0xbc2(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   10b0 <fprintf@plt>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
call   1100 <exit@plt>
lea    0xbde(%rip),%rdi
jmp    1491 <createSocket+0x271>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xbf2(%rip),%rdi
jmp    1491 <createSocket+0x271>
lea    0xbf8(%rip),%rdi
call   10e0 <perror@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.addrinfo = type { i64, i32, i64, i32, i32, %struct.addrinfo* }
%struct.sockaddr = type { i32 }
%struct.sockaddr_in = type { i32 }
%struct.sockaddr_in6 = type { i32 }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i64 0
@INET6_ADDRSTRLEN = global i32 0
@.str = [21 x i8] c"Resolving Server %s\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"getaddrinfo error: %s\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i64 0
@AF_INET6 = global i64 0
@.str.3 = [18 x i8] c"Address %s found\0A\00"
@.str.4 = [25 x i8] c"No valid address found!\0A\00"
@.str.5 = [18 x i8] c"Using address %s\0A\00"
@.str.6 = [11 x i8] c"TCP Socket\00"
@.str.7 = [17 x i8] c"Socket created.\0A\00"
@.str.8 = [21 x i8] c"Inhalt von type: %s\0A\00"
@.str.9 = [7 x i8] c"CLIENT\00"
@.str.10 = [15 x i8] c"Client Socket\0A\00"
@.str.11 = [2 x i8] c"\0A\00"
@.str.12 = [8 x i8] c"Connect\00"
@.str.13 = [7 x i8] c"SERVER\00"
@.str.14 = [16 x i8] c"Server Socket!\0A\00"
@.str.15 = [5 x i8] c"bind\00"
@.str.16 = [7 x i8] c"listen\00"
define i32 @createSocket(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [10 x i8]
%7 = alloca %struct.addrinfo*
%8 = alloca %struct.addrinfo*
%9 = alloca %struct.addrinfo*
%10 = alloca %struct.addrinfo
%11 = alloca i8*
%12 = alloca i64
%13 = alloca i32
%14 = alloca %struct.sockaddr*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 -1, i32* %5
store %struct.addrinfo* null, %struct.addrinfo** %9
%15 = call i32 @memset(%struct.addrinfo* %10, i32 0, i32 40)
%16 = load i32, i32* @SOCK_STREAM
%17 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 4
store i32 %16, i32* %17
%18 = load i64, i64* @AF_UNSPEC
%19 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %10, i32 0, i32 0
store i64 %18, i64* %19
%20 = load i32, i32* @INET6_ADDRSTRLEN
%21 = zext i32 %20 to i64
%22 = call i8* @llvm.stacksave()
store i8* %22, i8** %11
%23 = alloca i8, i64 %21
store i64 %21, i64* %12
%24 = load i8*, i8** %3
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%27 = call i32 @sprintf(i8* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 7777)
%28 = load i8*, i8** %3
%29 = getelementptr inbounds [10 x i8], [10 x i8]* %6, i64 0, i64 0
%30 = call i32 @getaddrinfo(i8* %28, i8* %29, %struct.addrinfo* %10, %struct.addrinfo** %7)
store i32 %30, i32* %13
%31 = load i32, i32* %13
%32 = icmp ne i32 %31, 0
br i1 %32, label %33, label %40
33: ; preds = %2
%34 = load i32, i32* @stderr
%35 = load i32, i32* %13
%36 = call i8* @gai_strerror(i32 %35)
%37 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %36)
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %2
%41 = load %struct.addrinfo*, %struct.addrinfo** %7
store %struct.addrinfo* %41, %struct.addrinfo** %8
br label %42
42: ; preds = %86, %40
%43 = load %struct.addrinfo*, %struct.addrinfo** %8
%44 = icmp ne %struct.addrinfo* %43, null
br i1 %44, label %45, label %90
45: ; preds = %42
%46 = load %struct.addrinfo*, %struct.addrinfo** %8
%47 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %46, i32 0, i32 2
%48 = load i64, i64* %47
%49 = inttoptr i64 %48 to %struct.sockaddr*
store %struct.sockaddr* %49, %struct.sockaddr** %14
%50 = load %struct.addrinfo*, %struct.addrinfo** %8
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %50, i32 0, i32 0
%52 = load i64, i64* %51
%53 = load i64, i64* @AF_INET
%54 = icmp eq i64 %52, %53
br i1 %54, label %55, label %66
55: ; preds = %45
%56 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %56, %struct.addrinfo** %9
%57 = load %struct.addrinfo*, %struct.addrinfo** %8
%58 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %57, i32 0, i32 0
%59 = load i64, i64* %58
%60 = load %struct.sockaddr*, %struct.sockaddr** %14
%61 = bitcast %struct.sockaddr* %60 to %struct.sockaddr_in*
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %61, i32 0, i32 0
%63 = bitcast i32* %62 to i8*
%64 = trunc i64 %21 to i32
%65 = call i32 @inet_ntop(i64 %59, i8* %63, i8* %23, i32 %64)
br label %90
66: ; preds = %45
%67 = load %struct.addrinfo*, %struct.addrinfo** %8
%68 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %67, i32 0, i32 0
%69 = load i64, i64* %68
%70 = load i64, i64* @AF_INET6
%71 = icmp eq i64 %69, %70
br i1 %71, label %72, label %83
72: ; preds = %66
%73 = load %struct.addrinfo*, %struct.addrinfo** %8
store %struct.addrinfo* %73, %struct.addrinfo** %9
%74 = load %struct.addrinfo*, %struct.addrinfo** %8
%75 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %74, i32 0, i32 0
%76 = load i64, i64* %75
%77 = load %struct.sockaddr*, %struct.sockaddr** %14
%78 = bitcast %struct.sockaddr* %77 to %struct.sockaddr_in6*
%79 = getelementptr inbounds %struct.sockaddr_in6, %struct.sockaddr_in6* %78, i32 0, i32 0
%80 = bitcast i32* %79 to i8*
%81 = trunc i64 %21 to i32
%82 = call i32 @inet_ntop(i64 %76, i8* %80, i8* %23, i32 %81)
br label %90
83: ; preds = %66
br label %84
84: ; preds = %83
%85 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %86
86: ; preds = %84
%87 = load %struct.addrinfo*, %struct.addrinfo** %8
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %87, i32 0, i32 5
%89 = load %struct.addrinfo*, %struct.addrinfo** %88
store %struct.addrinfo* %89, %struct.addrinfo** %8
br label %42
90: ; preds = %72, %55, %42
%91 = load %struct.addrinfo*, %struct.addrinfo** %9
%92 = icmp eq %struct.addrinfo* %91, null
br i1 %92, label %93, label %96
93: ; preds = %90
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.4, i64 0, i64 0))
%95 = call i32 @exit(i32 1)
unreachable
96: ; preds = %90
%97 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %23)
br label %98
98: ; preds = %96
%99 = load %struct.addrinfo*, %struct.addrinfo** %9
%100 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %99, i32 0, i32 0
%101 = load i64, i64* %100
%102 = load %struct.addrinfo*, %struct.addrinfo** %9
%103 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %102, i32 0, i32 4
%104 = load i32, i32* %103
%105 = load %struct.addrinfo*, %struct.addrinfo** %9
%106 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %105, i32 0, i32 3
%107 = load i32, i32* %106
%108 = call i32 @socket(i64 %101, i32 %104, i32 %107)
store i32 %108, i32* %5
%109 = icmp slt i32 %108, 0
br i1 %109, label %110, label %113
110: ; preds = %98
%111 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%112 = call i32 @exit(i32 1)
unreachable
113: ; preds = %98
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0))
%115 = load i8*, i8** %4
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %115)
%117 = load i8*, i8** %4
%118 = call i64 @strcmp(i8* %117, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %136
120: ; preds = %113
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0))
%122 = load i32, i32* %5
%123 = load %struct.addrinfo*, %struct.addrinfo** %9
%124 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %123, i32 0, i32 2
%125 = load i64, i64* %124
%126 = load %struct.addrinfo*, %struct.addrinfo** %9
%127 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %126, i32 0, i32 1
%128 = load i32, i32* %127
%129 = call i64 @connect(i32 %122, i64 %125, i32 %128)
%130 = icmp slt i64 %129, 0
br i1 %130, label %131, label %135
131: ; preds = %120
%132 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.11, i64 0, i64 0))
%133 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
%134 = call i32 @exit(i32 1)
unreachable
135: ; preds = %120
br label %165
136: ; preds = %113
%137 = load i8*, i8** %4
%138 = call i64 @strcmp(i8* %137, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%139 = icmp eq i64 %138, 0
br i1 %139, label %140, label %164
140: ; preds = %136
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.14, i64 0, i64 0))
%142 = load i32, i32* %5
%143 = load %struct.addrinfo*, %struct.addrinfo** %9
%144 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %143, i32 0, i32 2
%145 = load i64, i64* %144
%146 = load %struct.addrinfo*, %struct.addrinfo** %9
%147 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %146, i32 0, i32 1
%148 = load i32, i32* %147
%149 = call i64 @bind(i32 %142, i64 %145, i32 %148)
%150 = icmp slt i64 %149, 0
br i1 %150, label %151, label %154
151: ; preds = %140
%152 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%153 = call i32 @exit(i32 1)
unreachable
154: ; preds = %140
%155 = load i32, i32* %5
%156 = call i64 @listen(i32 %155, i32 5)
%157 = icmp slt i64 %156, 0
br i1 %157, label %158, label %163
158: ; preds = %154
%159 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0))
%160 = load i32, i32* %5
%161 = call i32 @close(i32 %160)
%162 = call i32 @exit(i32 1)
unreachable
163: ; preds = %154
br label %164
164: ; preds = %163, %136
br label %165
165: ; preds = %164, %135
%166 = load %struct.addrinfo*, %struct.addrinfo** %7
%167 = call i32 @freeaddrinfo(%struct.addrinfo* %166)
%168 = load i32, i32* %5
%169 = load i8*, i8** %11
ret i32 %168
}

LLVM IR (-O2):
%struct.addrinfo = type { i64, i32, i64, i32, i32, %struct.addrinfo* }
@SOCK_STREAM = global i32 0
@AF_UNSPEC = global i64 0
@INET6_ADDRSTRLEN = global i32 0
@.str = [21 x i8] c"Resolving Server %s\0A\00"
@.str.1 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.2 = [23 x i8] c"getaddrinfo error: %s\0A\00"
@EXIT_FAILURE = global i32 0
@AF_INET = global i64 0
@AF_INET6 = global i64 0
@.str.3 = [18 x i8] c"Address %s found\0A\00"
@.str.5 = [18 x i8] c"Using address %s\0A\00"
@.str.6 = [11 x i8] c"TCP Socket\00"
@.str.8 = [21 x i8] c"Inhalt von type: %s\0A\00"
@.str.9 = [7 x i8] c"CLIENT\00"
@.str.12 = [8 x i8] c"Connect\00"
@.str.13 = [7 x i8] c"SERVER\00"
@.str.15 = [5 x i8] c"bind\00"
@.str.16 = [7 x i8] c"listen\00"
@str = [16 x i8] c"Socket created.\00"
@str.17 = [15 x i8] c"Server Socket!\00"
@str.18 = [14 x i8] c"Client Socket\00"
@str.19 = [24 x i8] c"No valid address found!\00"
define i32 @createSocket(i8* %0, i8* %1) {
%3 = alloca [10 x i8]
%4 = alloca %struct.addrinfo*
%5 = alloca %struct.addrinfo
%6 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%7 = bitcast %struct.addrinfo** %4 to i8*
%8 = bitcast %struct.addrinfo* %5 to i8*
%9 = call i32 @memset(%struct.addrinfo* %5, i32 0, i32 40)
%10 = load i32, i32* @SOCK_STREAM
%11 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 4
store i32 %10, i32* %11
%12 = load i64, i64* @AF_UNSPEC
%13 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %5, i64 0, i32 0
store i64 %12, i64* %13
%14 = load i32, i32* @INET6_ADDRSTRLEN
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
%17 = alloca i8, i64 %15
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%19 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 7777)
%20 = call i32 @getaddrinfo(i8* %0, i8* %6, %struct.addrinfo* %5, %struct.addrinfo** %4)
%21 = icmp eq i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load %struct.addrinfo*, %struct.addrinfo** %4
%24 = icmp eq %struct.addrinfo* %23, null
br i1 %24, label %45, label %31
25: ; preds = %2
%26 = load i32, i32* @stderr
%27 = call i8* @gai_strerror(i32 %20)
%28 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %22, %40
%32 = phi %struct.addrinfo* [ %43, %40 ], [ %23, %22 ]
%33 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 0
%34 = load i64, i64* %33
%35 = load i64, i64* @AF_INET
%36 = icmp eq i64 %34, %35
%37 = load i64, i64* @AF_INET6
%38 = icmp eq i64 %34, %37
%39 = select i1 %36, i1 true, i1 %38
br i1 %39, label %48, label %40
40: ; preds = %31
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i8* %17)
%42 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 5
%43 = load %struct.addrinfo*, %struct.addrinfo** %42
%44 = icmp eq %struct.addrinfo* %43, null
br i1 %44, label %45, label %31
45: ; preds = %40, %22
%46 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str.19, i64 0, i64 0))
%47 = call i32 @exit(i32 1)
unreachable
48: ; preds = %31
%49 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 2
%50 = load i64, i64* %49
%51 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 2
%52 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 0
%53 = inttoptr i64 %50 to i8*
%54 = call i32 @inet_ntop(i64 %34, i8* %53, i8* %17, i32 %14)
%55 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%56 = load i64, i64* %52
%57 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 4
%58 = load i32, i32* %57
%59 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 3
%60 = load i32, i32* %59
%61 = call i32 @socket(i64 %56, i32 %58, i32 %60)
%62 = icmp slt i32 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %48
%64 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.6, i64 0, i64 0))
%65 = call i32 @exit(i32 1)
unreachable
66: ; preds = %48
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%68 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.8, i64 0, i64 0), i8* %1)
%69 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %82
71: ; preds = %66
%72 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.18, i64 0, i64 0))
%73 = load i64, i64* %51
%74 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 1
%75 = load i32, i32* %74
%76 = call i64 @connect(i32 %61, i64 %73, i32 %75)
%77 = icmp slt i64 %76, 0
br i1 %77, label %78, label %102
78: ; preds = %71
%79 = call i32 @putchar(i32 10)
%80 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.12, i64 0, i64 0))
%81 = call i32 @exit(i32 1)
unreachable
82: ; preds = %66
%83 = call i64 @strcmp(i8* %1, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.13, i64 0, i64 0))
%84 = icmp eq i64 %83, 0
br i1 %84, label %85, label %102
85: ; preds = %82
%86 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str.17, i64 0, i64 0))
%87 = load i64, i64* %51
%88 = getelementptr inbounds %struct.addrinfo, %struct.addrinfo* %32, i64 0, i32 1
%89 = load i32, i32* %88
%90 = call i64 @bind(i32 %61, i64 %87, i32 %89)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %95
92: ; preds = %85
%93 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.15, i64 0, i64 0))
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %85
%96 = call i64 @listen(i32 %61, i32 5)
%97 = icmp slt i64 %96, 0
br i1 %97, label %98, label %102
98: ; preds = %95
%99 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.16, i64 0, i64 0))
%100 = call i32 @close(i32 %61)
%101 = call i32 @exit(i32 1)
unreachable
102: ; preds = %82, %95, %71
%103 = load %struct.addrinfo*, %struct.addrinfo** %4
%104 = call i32 @freeaddrinfo(%struct.addrinfo* %103)
ret i32 %61
}