#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_3__ TYPE_1__;

/* Type definitions */
struct TYPE_3__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef size_t ssize_t;
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ client;
typedef int /*<<< orphan*/ address;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
scalar_t__ connect(int, struct sockaddr *, int);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_aton(char *, TYPE_1__ *);
char *inet_ntoa(TYPE_1__);
int /*<<< orphan*/ listen(int, int);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
size_t recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ send(int, char *, int /*<<< orphan*/, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main(int argc, char **argv) {
  printf("Chat\n\n\n");
  char *buffer = (char *)malloc(sizeof(char) * 256);
  ssize_t size;
  struct sockaddr_in address;
  int sock = socket(PF_INET, SOCK_STREAM, 0);
  int new_socket;
  address.sin_family = AF_INET;
  address.sin_port = htons(4711);
  if (argc < 2) {
    printf("Warte auf Client\n");
    address.sin_addr.s_addr = INADDR_ANY;
    if (bind(sock, (struct sockaddr *)&address, sizeof(address)) != 0) {
      printf("Port belegt!\n");
    }
    listen(sock, 5);
    struct sockaddr_in client;
    int client_len = sizeof(client);
    new_socket =
        accept(sock, (struct sockaddr *)&client, (socklen_t *)&client_len);
    if (new_socket > 0) {
      printf("Verbindung mit %s hergestellt.\n", inet_ntoa(address.sin_addr));
    }
    do {
      printf("Ich: ");
      fgets(buffer, 256, stdin);
      send(new_socket, buffer, strlen(buffer), 0);
      size = recv(new_socket, buffer, 256 - 1, 0);
      if (size > 0)
        buffer[size] = '\0';
      printf("Du: %s", buffer);
    } while (strcmp(buffer, "quit\n") != 0);
    close(new_socket);
    close(sock);
  } else {
    sock = socket(AF_INET, SOCK_STREAM, 0);
    inet_aton(argv[1], &address.sin_addr);
    if (connect(sock, (struct sockaddr *)&address, sizeof(address)) == 0) {
      printf("Verbindung mit %s hergestellt.\n", inet_ntoa(address.sin_addr));
    }
    do {
      size = recv(sock, buffer, 256 - 1, 0);
      if (size > 0)
        buffer[size] = '\0';
      printf("Du: %s", buffer);
      if (strcmp(buffer, "quit\n")) {
        printf("Ich: ");
        fgets(buffer, 256, stdin);
        send(sock, buffer, strlen(buffer), 0);
      }
    } while (strcmp(buffer, "quit\n") != 0);
    close(sock);
  }
  free(buffer);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xdd3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    $0x100,%edi
call   10e0 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    0x2d77(%rip),%rax
mov    (%rax),%edi
mov    0x2d76(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x34(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x28(%rbp)
mov    $0x1267,%edi
call   1070 <htons@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    13ce <main+0x1be>
lea    0xd80(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    0x2d42(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x30(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
cmp    $0x0,%rax
je     12c4 <main+0xb4>
lea    0xd5d(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x34(%rbp),%edi
mov    $0x5,%esi
call   10f0 <listen@plt>
movl   $0xc,-0x4c(%rbp)
mov    -0x34(%rbp),%edi
lea    -0x48(%rbp),%rsi
lea    -0x4c(%rbp),%rdx
call   1110 <accept@plt>
mov    %eax,-0x38(%rbp)
cmpl   $0x0,-0x38(%rbp)
jle    130e <main+0xfe>
mov    -0x30(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xd21(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1313 <main+0x103>
lea    0xd2e(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2cb4(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   10b0 <fgets@plt>
mov    -0x38(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
mov    -0x38(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    138d <main+0x17d>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xcb6(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xcab(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1313 <main+0x103>
mov    -0x38(%rbp),%edi
call   10a0 <close@plt>
mov    -0x34(%rbp),%edi
call   10a0 <close@plt>
jmp    1501 <main+0x2f1>
mov    0x2c13(%rip),%rax
mov    (%rax),%edi
mov    0x2bea(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1130 <socket@plt>
mov    %eax,-0x34(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x30(%rbp),%rsi
call   10d0 <inet_aton@plt>
mov    -0x34(%rbp),%edi
lea    -0x30(%rbp),%rsi
mov    $0xc,%edx
call   1120 <connect@plt>
cmp    $0x0,%rax
jne    142f <main+0x21f>
mov    -0x30(%rbp),%edi
call   1050 <inet_ntoa@plt>
mov    %rax,%rsi
lea    0xc00(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
jmp    1434 <main+0x224>
mov    -0x34(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jbe    1462 <main+0x252>
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rsi
lea    0xbe1(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%rdi
lea    0xbd6(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
je     14da <main+0x2ca>
lea    0xbb3(%rip),%rdi
mov    $0x0,%al
call   1090 <printf@plt>
mov    -0x18(%rbp),%rdi
mov    0x2b39(%rip),%rax
mov    (%rax),%edx
mov    $0x100,%esi
call   10b0 <fgets@plt>
mov    -0x34(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1080 <send@plt>
jmp    14df <main+0x2cf>
mov    -0x18(%rbp),%rdi
lea    0xb6b(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1434 <main+0x224>
mov    -0x34(%rbp),%edi
call   10a0 <close@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    0x2aa7(%rip),%rax
mov    (%rax),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%r15
mov    %edi,%r13d
lea    0xdf8(%rip),%rdi
call   1050 <puts@plt>
mov    $0x100,%edi
call   10f0 <malloc@plt>
mov    %rax,%rbx
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    0x2d6b(%rip),%r14
mov    (%r14),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%ebp
mov    0x2d78(%rip),%r12
mov    (%r12),%eax
mov    %eax,0x8(%rsp)
mov    $0x1267,%edi
call   1080 <htons@plt>
mov    %eax,0x4(%rsp)
cmp    $0x1,%r13d
jg     139d <main+0x17d>
lea    0xda3(%rip),%rdi
call   1050 <puts@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
mov    %rsp,%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1110 <bind@plt>
test   %rax,%rax
je     12c8 <main+0xa8>
lea    0xd88(%rip),%rdi
call   1050 <puts@plt>
mov    %ebp,%edi
mov    $0x5,%esi
call   1100 <listen@plt>
movl   $0xc,0x14(%rsp)
lea    0x18(%rsp),%rsi
lea    0x14(%rsp),%rdx
mov    %ebp,0x10(%rsp)
mov    %ebp,%edi
call   1120 <accept@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    1310 <main+0xf0>
mov    (%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xcfa(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xd09(%rip),%r15
mov    0x2cc2(%rip),%r14
lea    0xd01(%rip),%r12
lea    0xd01(%rip),%r13
jmp    1351 <main+0x131>
xchg   %ax,%ax
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     148a <main+0x26a>
mov    %r15,%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %rax,%rax
je     1330 <main+0x110>
movb   $0x0,(%rbx,%rax,1)
jmp    1330 <main+0x110>
mov    (%r12),%edi
mov    (%r14),%esi
xor    %edx,%edx
call   1140 <socket@plt>
mov    %eax,%ebp
mov    0x8(%r15),%rdi
mov    %rsp,%r14
mov    %r14,%rsi
call   10e0 <inet_aton@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xc,%edx
call   1130 <connect@plt>
test   %rax,%rax
jne    13e9 <main+0x1c9>
mov    (%rsp),%edi
call   1060 <inet_ntoa@plt>
lea    0xc21(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
lea    0xc36(%rip),%r14
lea    0xc36(%rip),%r15
lea    0xc22(%rip),%r12
mov    0x2bdb(%rip),%r13
jmp    1420 <main+0x200>
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     1497 <main+0x277>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xff,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %rax,%rax
je     143a <main+0x21a>
movb   $0x0,(%rbx,%rax,1)
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10d0 <strcmp@plt>
test   %rax,%rax
je     1410 <main+0x1f0>
mov    %r12,%rdi
xor    %eax,%eax
call   10a0 <printf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x100,%esi
call   10c0 <fgets@plt>
mov    %rbx,%rdi
call   1070 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
xor    %ecx,%ecx
call   1090 <send@plt>
jmp    1410 <main+0x1f0>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    0x10(%rsp),%edi
jmp    1499 <main+0x279>
mov    %ebp,%edi
call   10b0 <close@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    0x2b0b(%rip),%rax
mov    (%rax),%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_3__, i32, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@.str = [8 x i8] c"Chat\0A\0A\0A\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str.1 = [18 x i8] c"Warte auf Client\0A\00"
@INADDR_ANY = global i32 0
@.str.2 = [14 x i8] c"Port belegt!\0A\00"
@.str.3 = [32 x i8] c"Verbindung mit %s hergestellt.\0A\00"
@.str.4 = [6 x i8] c"Ich: \00"
@stdin = global i32 0
@.str.5 = [7 x i8] c"Du: %s\00"
@.str.6 = [6 x i8] c"quit\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca %struct.sockaddr_in
%9 = alloca i32
%10 = alloca i32
%11 = alloca %struct.sockaddr_in
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%14 = call i64 @malloc(i32 256)
%15 = inttoptr i64 %14 to i8*
store i8* %15, i8** %6
%16 = load i32, i32* @PF_INET
%17 = load i32, i32* @SOCK_STREAM
%18 = call i32 @socket(i32 %16, i32 %17, i32 0)
store i32 %18, i32* %9
%19 = load i32, i32* @AF_INET
%20 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 2
store i32 %19, i32* %20
%21 = call i32 @htons(i32 4711)
%22 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 1
store i32 %21, i32* %22
%23 = load i32, i32* %4
%24 = icmp slt i32 %23, 2
br i1 %24, label %25, label %82
25: ; preds = %2
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%27 = load i32, i32* @INADDR_ANY
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %28, i32 0, i32 0
store i32 %27, i32* %29
%30 = load i32, i32* %9
%31 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%32 = call i64 @bind(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = icmp ne i64 %32, 0
br i1 %33, label %34, label %36
34: ; preds = %25
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
br label %36
36: ; preds = %34, %25
%37 = load i32, i32* %9
%38 = call i32 @listen(i32 %37, i32 5)
store i32 12, i32* %12
%39 = load i32, i32* %9
%40 = bitcast %struct.sockaddr_in* %11 to %struct.sockaddr*
%41 = call i32 @accept(i32 %39, %struct.sockaddr* %40, i32* %12)
store i32 %41, i32* %10
%42 = load i32, i32* %10
%43 = icmp sgt i32 %42, 0
br i1 %43, label %44, label %50
44: ; preds = %36
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%46 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %45, i32 0, i32 0
%47 = load i32, i32* %46
%48 = call i8* @inet_ntoa(i32 %47)
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %44, %36
br label %51
51: ; preds = %73, %50
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%53 = load i8*, i8** %6
%54 = load i32, i32* @stdin
%55 = call i32 @fgets(i8* %53, i32 256, i32 %54)
%56 = load i32, i32* %10
%57 = load i8*, i8** %6
%58 = load i8*, i8** %6
%59 = call i32 @strlen(i8* %58)
%60 = call i32 @send(i32 %56, i8* %57, i32 %59, i32 0)
%61 = load i32, i32* %10
%62 = load i8*, i8** %6
%63 = call i64 @recv(i32 %61, i8* %62, i32 255, i32 0)
store i64 %63, i64* %7
%64 = load i64, i64* %7
%65 = icmp ugt i64 %64, 0
br i1 %65, label %66, label %70
66: ; preds = %51
%67 = load i8*, i8** %6
%68 = load i64, i64* %7
%69 = getelementptr inbounds i8, i8* %67, i64 %68
store i8 0, i8* %69
br label %70
70: ; preds = %66, %51
%71 = load i8*, i8** %6
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %71)
br label %73
73: ; preds = %70
%74 = load i8*, i8** %6
%75 = call i64 @strcmp(i8* %74, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%76 = icmp ne i64 %75, 0
br i1 %76, label %51, label %77
77: ; preds = %73
%78 = load i32, i32* %10
%79 = call i32 @close(i32 %78)
%80 = load i32, i32* %9
%81 = call i32 @close(i32 %80)
br label %136
82: ; preds = %2
%83 = load i32, i32* @AF_INET
%84 = load i32, i32* @SOCK_STREAM
%85 = call i32 @socket(i32 %83, i32 %84, i32 0)
store i32 %85, i32* %9
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 1
%88 = load i8*, i8** %87
%89 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%90 = call i32 @inet_aton(i8* %88, %struct.TYPE_3__* %89)
%91 = load i32, i32* %9
%92 = bitcast %struct.sockaddr_in* %8 to %struct.sockaddr*
%93 = call i64 @connect(i32 %91, %struct.sockaddr* %92, i32 12)
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %101
95: ; preds = %82
%96 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %8, i32 0, i32 0
%97 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %96, i32 0, i32 0
%98 = load i32, i32* %97
%99 = call i8* @inet_ntoa(i32 %98)
%100 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %99)
br label %101
101: ; preds = %95, %82
br label %102
102: ; preds = %129, %101
%103 = load i32, i32* %9
%104 = load i8*, i8** %6
%105 = call i64 @recv(i32 %103, i8* %104, i32 255, i32 0)
store i64 %105, i64* %7
%106 = load i64, i64* %7
%107 = icmp ugt i64 %106, 0
br i1 %107, label %108, label %112
108: ; preds = %102
%109 = load i8*, i8** %6
%110 = load i64, i64* %7
%111 = getelementptr inbounds i8, i8* %109, i64 %110
store i8 0, i8* %111
br label %112
112: ; preds = %108, %102
%113 = load i8*, i8** %6
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %113)
%115 = load i8*, i8** %6
%116 = call i64 @strcmp(i8* %115, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%117 = icmp ne i64 %116, 0
br i1 %117, label %118, label %128
118: ; preds = %112
%119 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%120 = load i8*, i8** %6
%121 = load i32, i32* @stdin
%122 = call i32 @fgets(i8* %120, i32 256, i32 %121)
%123 = load i32, i32* %9
%124 = load i8*, i8** %6
%125 = load i8*, i8** %6
%126 = call i32 @strlen(i8* %125)
%127 = call i32 @send(i32 %123, i8* %124, i32 %126, i32 0)
br label %128
128: ; preds = %118, %112
br label %129
129: ; preds = %128
%130 = load i8*, i8** %6
%131 = call i64 @strcmp(i8* %130, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%132 = icmp ne i64 %131, 0
br i1 %132, label %102, label %133
133: ; preds = %129
%134 = load i32, i32* %9
%135 = call i32 @close(i32 %134)
br label %136
136: ; preds = %133, %77
%137 = load i8*, i8** %6
%138 = call i32 @free(i8* %137)
%139 = load i32, i32* @EXIT_SUCCESS
ret i32 %139
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_3__, i32, i32 }
%struct.TYPE_3__ = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@INADDR_ANY = global i32 0
@.str.3 = [32 x i8] c"Verbindung mit %s hergestellt.\0A\00"
@.str.4 = [6 x i8] c"Ich: \00"
@stdin = global i32 0
@.str.5 = [7 x i8] c"Du: %s\00"
@.str.6 = [6 x i8] c"quit\0A\00"
@EXIT_SUCCESS = global i32 0
@str = [7 x i8] c"Chat\0A\0A\00"
@str.7 = [17 x i8] c"Warte auf Client\00"
@str.8 = [13 x i8] c"Port belegt!\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.sockaddr_in
%4 = alloca %struct.sockaddr_in
%5 = alloca i32
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @str, i64 0, i64 0))
%7 = tail call i64 @malloc(i32 256)
%8 = inttoptr i64 %7 to i8*
%9 = bitcast %struct.sockaddr_in* %3 to i8*
%10 = load i32, i32* @PF_INET
%11 = load i32, i32* @SOCK_STREAM
%12 = tail call i32 @socket(i32 %10, i32 %11, i32 0)
%13 = load i32, i32* @AF_INET
%14 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 2
store i32 %13, i32* %14
%15 = tail call i32 @htons(i32 4711)
%16 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 1
store i32 %15, i32* %16
%17 = icmp slt i32 %0, 2
br i1 %17, label %18, label %56
18: ; preds = %2
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.7, i64 0, i64 0))
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
store i32 %20, i32* %21
%22 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%23 = call i64 @bind(i32 %12, %struct.sockaddr* %22, i32 12)
%24 = icmp eq i64 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %18
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0))
br label %27
27: ; preds = %25, %18
%28 = call i32 @listen(i32 %12, i32 5)
%29 = bitcast %struct.sockaddr_in* %4 to i8*
%30 = bitcast i32* %5 to i8*
store i32 12, i32* %5
%31 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%32 = call i32 @accept(i32 %12, %struct.sockaddr* %31, i32* %5)
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %38
34: ; preds = %27
%35 = load i32, i32* %21
%36 = call i8* @inet_ntoa(i32 %35)
%37 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %36)
br label %38
38: ; preds = %34, %27
br label %39
39: ; preds = %38, %49
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%41 = load i32, i32* @stdin
%42 = call i32 @fgets(i8* %8, i32 256, i32 %41)
%43 = call i32 @strlen(i8* %8)
%44 = call i32 @send(i32 %32, i8* %8, i32 %43, i32 0)
%45 = call i64 @recv(i32 %32, i8* %8, i32 255, i32 0)
%46 = icmp eq i64 %45, 0
br i1 %46, label %49, label %47
47: ; preds = %39
%48 = getelementptr inbounds i8, i8* %8, i64 %45
store i8 0, i8* %48
br label %49
49: ; preds = %47, %39
%50 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%51 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%52 = icmp eq i64 %51, 0
br i1 %52, label %53, label %39
53: ; preds = %49
%54 = call i32 @close(i32 %32)
%55 = call i32 @close(i32 %12)
br label %93
56: ; preds = %2
%57 = load i32, i32* @AF_INET
%58 = load i32, i32* @SOCK_STREAM
%59 = tail call i32 @socket(i32 %57, i32 %58, i32 0)
%60 = getelementptr inbounds i8*, i8** %1, i64 1
%61 = load i8*, i8** %60
%62 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0
%63 = call i32 @inet_aton(i8* %61, %struct.TYPE_3__* %62)
%64 = bitcast %struct.sockaddr_in* %3 to %struct.sockaddr*
%65 = call i64 @connect(i32 %59, %struct.sockaddr* %64, i32 12)
%66 = icmp eq i64 %65, 0
br i1 %66, label %67, label %72
67: ; preds = %56
%68 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %3, i64 0, i32 0, i32 0
%69 = load i32, i32* %68
%70 = call i8* @inet_ntoa(i32 %69)
%71 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.3, i64 0, i64 0), i8* %70)
br label %72
72: ; preds = %67, %56
br label %73
73: ; preds = %72, %88
%74 = call i64 @recv(i32 %59, i8* %8, i32 255, i32 0)
%75 = icmp eq i64 %74, 0
br i1 %75, label %78, label %76
76: ; preds = %73
%77 = getelementptr inbounds i8, i8* %8, i64 %74
store i8 0, i8* %77
br label %78
78: ; preds = %76, %73
%79 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %8)
%80 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%81 = icmp eq i64 %80, 0
br i1 %81, label %88, label %82
82: ; preds = %78
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.4, i64 0, i64 0))
%84 = load i32, i32* @stdin
%85 = call i32 @fgets(i8* %8, i32 256, i32 %84)
%86 = call i32 @strlen(i8* %8)
%87 = call i32 @send(i32 %59, i8* %8, i32 %86, i32 0)
br label %88
88: ; preds = %78, %82
%89 = call i64 @strcmp(i8* %8, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%90 = icmp eq i64 %89, 0
br i1 %90, label %91, label %73
91: ; preds = %88
%92 = call i32 @close(i32 %59)
br label %93
93: ; preds = %91, %53
%94 = call i32 @free(i8* %8)
%95 = load i32, i32* @EXIT_SUCCESS
ret i32 %95
}