#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 stat {
  size_t st_size;
};
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  int /*<<< orphan*/ sin_port;
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int socklen_t;
typedef scalar_t__ pid_t;
typedef int /*<<< orphan*/ client;
typedef int /*<<< orphan*/ addr;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int EXIT_SUCCESS;
int /*<<< orphan*/ INADDR_ANY;
int O_APPEND;
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ STDOUT_FILENO;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ bzero(char *, int);
int /*<<< orphan*/ close(int);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ listen(int, int);
int open(char *, int, ...);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ stdout;
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *strtok(char *, char *);
int /*<<< orphan*/ wait(int *);
scalar_t__ write(int, char *, int);
int main() {
  int sockid, connection, status, i, savestdout;
  socklen_t clientlen;
  char buffer[32768];
  struct sockaddr_in addr, client;
  int stdoutpipe[2];
  pid_t childPID;
  pid_t clientPID;
  char *geteilt;
  sockid = socket(AF_INET, SOCK_STREAM, 0);
  addr.sin_family = AF_INET;
  addr.sin_addr.s_addr = INADDR_ANY;
  addr.sin_port = htons(9000);
  bind(sockid, (struct sockaddr *)&addr, sizeof(addr));
  listen(sockid, 5);
  while (1) {
    clientPID = fork();
    if (clientPID > 0) {
      clientlen = sizeof(client);
      connection = accept(sockid, (struct sockaddr *)&client, &clientlen);
    } else {
      if (clientPID == 0) {
        bzero(buffer, 32768);
        read(connection, buffer, 32767);
        if (strcmp("exit\n", buffer) == 0) {
          break;
        } else {
          buffer[strlen(buffer) - 1] = 0;
          printf("Kommando: %s \n", buffer);
          char *argv[20];
          i = 0;
          geteilt = strtok(buffer, " ");
          while (geteilt != NULL) {
            argv[i] = geteilt;
            geteilt = strtok(NULL, " ");
            i++;
          }
          argv[i] = 0;
          printf("%s", argv[0]);
          if (strcmp(argv[0], "put") == 0) {
            int fileDescriptor =
                open(argv[1], O_WRONLY | O_CREAT | O_APPEND, 00644);
            if (write(fileDescriptor, argv[2], strlen(argv[2])) !=
                strlen(argv[2])) {
              write(connection, "-1", 2);
            } else {
              write(connection, buffer, strlen(buffer));
            }
          } else {
            if (strcmp(argv[0], "get") == 0) {
              int fileDescriptor = open(argv[1], O_RDONLY);
              if (fileDescriptor) {
                write(connection, "-1", 2);
              } else {
                size_t size;
                struct stat st;
                stat(argv[1], &st);
                size = st.st_size;
                read(fileDescriptor, buffer, size);
                write(connection, buffer, strlen(buffer));
              }
            } else {
              savestdout = dup(STDOUT_FILENO);
              pipe(stdoutpipe);
              dup2(stdoutpipe[1], STDOUT_FILENO);
              close(stdoutpipe[1]);
              childPID = fork();
              if (childPID == 0) {
                execvp(argv[0], argv);
                exit(-1);
              } else {
                wait(&status);
              }
              read(stdoutpipe[0], buffer, 32767);
              fflush(stdout);
              dup2(savestdout, STDOUT_FILENO);
              write(connection, buffer, strlen(buffer));
            }
          }
        }
      } else {
        exit(1);
      }
    }
  }
  close(connection);
  close(sockid);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8160,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2d4f(%rip),%rax
mov    (%rax),%edi
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,-0x8(%rbp)
mov    0x2d33(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8028(%rbp)
mov    0x2d14(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x802c(%rbp)
mov    $0x2328,%edi
call   1050 <htons@plt>
mov    %eax,-0x8030(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x8030(%rbp),%rsi
mov    $0xc,%edx
call   1100 <bind@plt>
mov    -0x8(%rbp),%edi
mov    $0x5,%esi
call   10f0 <listen@plt>
mov    $0x0,%al
call   1180 <fork@plt>
mov    %rax,-0x8058(%rbp)
cmpq   $0x0,-0x8058(%rbp)
jle    132b <main+0xbb>
movl   $0xc,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x8040(%rbp),%rsi
lea    -0x1c(%rbp),%rdx
call   1140 <accept@plt>
mov    %eax,-0xc(%rbp)
jmp    171f <main+0x4af>
cmpq   $0x0,-0x8058(%rbp)
jne    1710 <main+0x4a0>
lea    -0x8020(%rbp),%rdi
mov    $0x8000,%esi
call   1130 <bzero@plt>
mov    -0xc(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    $0x7fff,%edx
call   10b0 <read@plt>
lea    -0x8020(%rbp),%rsi
lea    0xc94(%rip),%rdi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1380 <main+0x110>
jmp    1724 <main+0x4b4>
lea    -0x8020(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x8020(%rbp,%rax,1)
lea    -0x8020(%rbp),%rsi
lea    0xc5f(%rip),%rdi
call   1070 <printf@plt>
movl   $0x0,-0x14(%rbp)
lea    -0x8020(%rbp),%rdi
lea    0xc54(%rip),%rsi
call   1120 <strtok@plt>
mov    %rax,-0x8060(%rbp)
cmpq   $0x0,-0x8060(%rbp)
je     1413 <main+0x1a3>
mov    -0x8060(%rbp),%rcx
movslq -0x14(%rbp),%rax
mov    %rcx,-0x8100(%rbp,%rax,8)
ff
xor    %eax,%eax
mov    %eax,%edi
lea    0xc1c(%rip),%rsi
call   1120 <strtok@plt>
mov    %rax,-0x8060(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    13cd <main+0x15d>
movslq -0x14(%rbp),%rax
movq   $0x0,-0x8100(%rbp,%rax,8)
mov    -0x8100(%rbp),%rsi
lea    0xbe6(%rip),%rdi
call   1070 <printf@plt>
mov    -0x8100(%rbp),%rdi
lea    0xbd6(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    153e <main+0x2ce>
mov    -0x80f8(%rbp),%rdi
mov    0x2b37(%rip),%rax
mov    (%rax),%esi
mov    0x2b8e(%rip),%rax
or     (%rax),%esi
mov    0x2b1d(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
mov    $0x0,%al
call   1110 <open@plt>
mov    %eax,-0x8104(%rbp)
mov    -0x8104(%rbp),%eax
mov    %eax,-0x812c(%rbp)
mov    -0x80f0(%rbp),%rax
mov    %rax,-0x8128(%rbp)
mov    -0x80f0(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x812c(%rbp),%edi
mov    -0x8128(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,-0x8120(%rbp)
mov    -0x80f0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x8120(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
je     1502 <main+0x292>
mov    -0xc(%rbp),%edi
lea    0xb2b(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    1539 <main+0x2c9>
mov    -0xc(%rbp),%eax
mov    %eax,-0x813c(%rbp)
lea    -0x8020(%rbp),%rax
mov    %rax,-0x8138(%rbp)
lea    -0x8020(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x813c(%rbp),%edi
mov    -0x8138(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1706 <main+0x496>
mov    -0x8100(%rbp),%rdi
lea    0xad5(%rip),%rsi
call   10c0 <strcmp@plt>
cmp    $0x0,%rax
jne    1616 <main+0x3a6>
mov    -0x80f8(%rbp),%rdi
mov    0x2a67(%rip),%rax
mov    (%rax),%esi
mov    $0x0,%al
call   1110 <open@plt>
mov    %eax,-0x8108(%rbp)
cmpl   $0x0,-0x8108(%rbp)
je     159e <main+0x32e>
mov    -0xc(%rbp),%edi
lea    0xa8f(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
jmp    1611 <main+0x3a1>
mov    -0x80f8(%rbp),%rdi
lea    -0x8118(%rbp),%rsi
call   10d0 <stat@plt>
mov    -0x8118(%rbp),%rax
mov    %rax,-0x8110(%rbp)
mov    -0x8108(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    -0x8110(%rbp),%rax
mov    %eax,%edx
call   10b0 <read@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x814c(%rbp)
lea    -0x8020(%rbp),%rax
mov    %rax,-0x8148(%rbp)
lea    -0x8020(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x814c(%rbp),%edi
mov    -0x8148(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1701 <main+0x491>
mov    0x29cb(%rip),%rax
mov    (%rax),%edi
call   1080 <dup@plt>
mov    %eax,-0x18(%rbp)
lea    -0x8048(%rbp),%rdi
call   10a0 <pipe@plt>
mov    -0x8044(%rbp),%edi
mov    0x29a8(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0x8044(%rbp),%edi
call   1090 <close@plt>
mov    $0x0,%al
call   1180 <fork@plt>
mov    %rax,-0x8050(%rbp)
cmpq   $0x0,-0x8050(%rbp)
jne    168b <main+0x41b>
mov    -0x8100(%rbp),%rdi
lea    -0x8100(%rbp),%rsi
call   1150 <execvp@plt>
mov    $0xffffffff,%edi
call   1160 <exit@plt>
lea    -0x10(%rbp),%rdi
call   1170 <wait@plt>
mov    -0x8048(%rbp),%edi
lea    -0x8020(%rbp),%rsi
mov    $0x7fff,%edx
call   10b0 <read@plt>
mov    0x28fe(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    -0x18(%rbp),%edi
mov    0x2925(%rip),%rax
mov    (%rax),%esi
call   1060 <dup2@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x815c(%rbp)
lea    -0x8020(%rbp),%rax
mov    %rax,-0x8158(%rbp)
lea    -0x8020(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x815c(%rbp),%edi
mov    -0x8158(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1706 <main+0x496>
jmp    170b <main+0x49b>
jmp    171a <main+0x4aa>
mov    $0x1,%edi
call   1160 <exit@plt>
jmp    171f <main+0x4af>
jmp    12ed <main+0x7d>
mov    -0xc(%rbp),%edi
call   1090 <close@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
mov    0x286d(%rip),%rax
mov    (%rax),%eax
add    $0x8160,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80f8,%rsp
mov    0x2d50(%rip),%rbx
mov    (%rbx),%edi
mov    0x2d27(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1190 <socket@plt>
mov    %eax,%ebp
mov    (%rbx),%eax
mov    %eax,0x28(%rsp)
mov    0x2d1f(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x24(%rsp)
mov    $0x2328,%edi
call   1050 <htons@plt>
mov    %eax,0x20(%rsp)
lea    0x20(%rsp),%rsi
mov    %ebp,%edi
mov    $0xc,%edx
call   1100 <bind@plt>
mov    %ebp,0x10(%rsp)
mov    %ebp,%edi
mov    $0x5,%esi
call   10f0 <listen@plt>
lea    0xf0(%rsp),%r13
lea    0xd13(%rip),%r12
lea    0xd21(%rip),%r14
jmp    131d <main+0xad>
cs nopw 0x0(%rax,%rax,1)
movl   $0xc,0x1c(%rsp)
mov    0x10(%rsp),%edi
lea    0x40(%rsp),%rsi
lea    0x1c(%rsp),%rdx
call   1140 <accept@plt>
mov    %eax,%ebx
mov    %ebx,0xc(%rsp)
jmp    1367 <main+0xf7>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    0x58(%rsp),%rbp
mov    0x2c94(%rip),%rax
mov    (%rax),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1110 <open@plt>
test   %eax,%eax
je     153f <main+0x2cf>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
lea    0xcc1(%rip),%rsi
mov    $0x2,%edx
call   1030 <write@plt>
xor    %eax,%eax
call   1180 <fork@plt>
test   %rax,%rax
jg     1300 <main+0x90>
jne    15a2 <main+0x332>
mov    %r13,%rdi
mov    $0x8000,%esi
call   1130 <bzero@plt>
mov    %ebx,%edi
mov    %r13,%rsi
mov    $0x7fff,%edx
call   10b0 <read@plt>
mov    %r12,%rdi
mov    %r13,%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1577 <main+0x307>
mov    %r13,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r13,1)
lea    0xc46(%rip),%rdi
mov    %r13,%rsi
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %r14,%rsi
call   1120 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     13f8 <main+0x188>
nopw   0x0(%rax,%rax,1)
mov    %rax,0x50(%rsp,%rbx,8)
xor    %edi,%edi
mov    %r14,%rsi
call   1120 <strtok@plt>
add    $0x1,%rbx
test   %rax,%rax
jne    13e0 <main+0x170>
mov    %ebx,%eax
movq   $0x0,0x50(%rsp,%rax,8)
mov    0x50(%rsp),%r15
lea    0xc08(%rip),%rdi
mov    %r15,%rsi
call   1070 <printf@plt>
mov    %r15,%rdi
lea    0xbf9(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     14e0 <main+0x270>
mov    %r15,%rdi
lea    0xbe8(%rip),%rsi
call   10c0 <strcmp@plt>
test   %rax,%rax
je     1330 <main+0xc0>
mov    %r12,%rbp
mov    0x2b97(%rip),%rbx
mov    (%rbx),%edi
call   1080 <dup@plt>
mov    %eax,%r12d
lea    0x14(%rsp),%rdi
call   10a0 <pipe@plt>
mov    0x18(%rsp),%edi
mov    (%rbx),%esi
call   1060 <dup2@plt>
mov    0x18(%rsp),%edi
call   1090 <close@plt>
xor    %eax,%eax
call   1180 <fork@plt>
test   %rax,%rax
je     15ac <main+0x33c>
lea    0x3c(%rsp),%rdi
call   1170 <wait@plt>
mov    0x14(%rsp),%edi
mov    %r13,%rsi
mov    $0x7fff,%edx
call   10b0 <read@plt>
mov    0x2b05(%rip),%rax
mov    (%rax),%edi
call   10e0 <fflush@plt>
mov    (%rbx),%esi
mov    %r12d,%edi
call   1060 <dup2@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rbp,%r12
jmp    1367 <main+0xf7>
nopl   0x0(%rax)
mov    0x58(%rsp),%rdi
mov    0x2b0c(%rip),%rax
mov    (%rax),%esi
mov    0x2aa3(%rip),%rax
or     (%rax),%esi
mov    0x2a92(%rip),%rax
or     (%rax),%esi
mov    $0x1a4,%edx
xor    %eax,%eax
call   1110 <open@plt>
mov    %eax,%ebp
mov    0x60(%rsp),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jne    1350 <main+0xe0>
jmp    155a <main+0x2ea>
mov    %rbp,%rdi
lea    0x30(%rsp),%rsi
call   10d0 <stat@plt>
mov    0x30(%rsp),%edx
xor    %edi,%edi
mov    %r13,%rsi
call   10b0 <read@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
mov    0xc(%rsp),%ebx
mov    %ebx,%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <write@plt>
jmp    1367 <main+0xf7>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x10(%rsp),%edi
call   1090 <close@plt>
mov    0x2a1a(%rip),%rax
mov    (%rax),%eax
add    $0x80f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%edi
call   1160 <exit@plt>
lea    0x50(%rsp),%rsi
mov    %r15,%rdi
call   1150 <execvp@plt>
mov    $0xffffffff,%edi
call   1160 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [6 x i8] c"exit\0A\00"
@.str.1 = [15 x i8] c"Kommando: %s \0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c"put\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@.str.5 = [3 x i8] c"-1\00"
@.str.6 = [4 x i8] c"get\00"
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [32768 x i8]
%9 = alloca %struct.sockaddr_in
%10 = alloca %struct.sockaddr_in
%11 = alloca [2 x i32]
%12 = alloca i64
%13 = alloca i64
%14 = alloca i8*
%15 = alloca [20 x i8*]
%16 = alloca i32
%17 = alloca i32
%18 = alloca i64
%19 = alloca %struct.stat
store i32 0, i32* %1
%20 = load i32, i32* @AF_INET
%21 = load i32, i32* @SOCK_STREAM
%22 = call i32 @socket(i32 %20, i32 %21, i32 0)
store i32 %22, i32* %2
%23 = load i32, i32* @AF_INET
%24 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 2
store i32 %23, i32* %24
%25 = load i32, i32* @INADDR_ANY
%26 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 1
%27 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %26, i32 0, i32 0
store i32 %25, i32* %27
%28 = call i32 @htons(i32 9000)
%29 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %9, i32 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* %2
%31 = bitcast %struct.sockaddr_in* %9 to %struct.sockaddr*
%32 = call i32 @bind(i32 %30, %struct.sockaddr* %31, i32 12)
%33 = load i32, i32* %2
%34 = call i32 @listen(i32 %33, i32 5)
br label %35
35: ; preds = %0, %195
%36 = call i64 (...) @fork()
store i64 %36, i64* %13
%37 = load i64, i64* %13
%38 = icmp sgt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %35
store i32 12, i32* %7
%40 = load i32, i32* %2
%41 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%42 = call i32 @accept(i32 %40, %struct.sockaddr* %41, i32* %7)
store i32 %42, i32* %3
br label %195
43: ; preds = %35
%44 = load i64, i64* %13
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %192
46: ; preds = %43
%47 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%48 = call i32 @bzero(i8* %47, i32 32768)
%49 = load i32, i32* %3
%50 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%51 = call i32 @read(i32 %49, i8* %50, i32 32767)
%52 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%53 = call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %52)
%54 = icmp eq i64 %53, 0
br i1 %54, label %55, label %56
55: ; preds = %46
br label %196
56: ; preds = %46
%57 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%58 = call i32 @strlen(i8* %57)
%59 = sub nsw i32 %58, 1
%60 = sext i32 %59 to i64
%61 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 %60
store i8 0, i8* %61
%62 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%63 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %62)
store i32 0, i32* %5
%64 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%65 = call i8* @strtok(i8* %64, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %65, i8** %14
br label %66
66: ; preds = %69, %56
%67 = load i8*, i8** %14
%68 = icmp ne i8* %67, null
br i1 %68, label %69, label %77
69: ; preds = %66
%70 = load i8*, i8** %14
%71 = load i32, i32* %5
%72 = sext i32 %71 to i64
%73 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 %72
store i8* %70, i8** %73
%74 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i8* %74, i8** %14
%75 = load i32, i32* %5
%76 = add nsw i32 %75, 1
store i32 %76, i32* %5
br label %66
77: ; preds = %66
%78 = load i32, i32* %5
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 %79
store i8* null, i8** %80
%81 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 0
%82 = load i8*, i8** %81
%83 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %82)
%84 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 0
%85 = load i8*, i8** %84
%86 = call i64 @strcmp(i8* %85, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%87 = icmp eq i64 %86, 0
br i1 %87, label %88, label %119
88: ; preds = %77
%89 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 1
%90 = load i8*, i8** %89
%91 = load i32, i32* @O_WRONLY
%92 = load i32, i32* @O_CREAT
%93 = or i32 %91, %92
%94 = load i32, i32* @O_APPEND
%95 = or i32 %93, %94
%96 = call i32 (i8*, i32, ...) @open(i8* %90, i32 %95, i32 420)
store i32 %96, i32* %16
%97 = load i32, i32* %16
%98 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 2
%99 = load i8*, i8** %98
%100 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 2
%101 = load i8*, i8** %100
%102 = call i32 @strlen(i8* %101)
%103 = call i64 @write(i32 %97, i8* %99, i32 %102)
%104 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 2
%105 = load i8*, i8** %104
%106 = call i32 @strlen(i8* %105)
%107 = sext i32 %106 to i64
%108 = icmp ne i64 %103, %107
br i1 %108, label %109, label %112
109: ; preds = %88
%110 = load i32, i32* %3
%111 = call i64 @write(i32 %110, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %118
112: ; preds = %88
%113 = load i32, i32* %3
%114 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%115 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%116 = call i32 @strlen(i8* %115)
%117 = call i64 @write(i32 %113, i8* %114, i32 %116)
br label %118
118: ; preds = %112, %109
br label %190
119: ; preds = %77
%120 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 0
%121 = load i8*, i8** %120
%122 = call i64 @strcmp(i8* %121, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%123 = icmp eq i64 %122, 0
br i1 %123, label %124, label %151
124: ; preds = %119
%125 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 1
%126 = load i8*, i8** %125
%127 = load i32, i32* @O_RDONLY
%128 = call i32 (i8*, i32, ...) @open(i8* %126, i32 %127)
store i32 %128, i32* %17
%129 = load i32, i32* %17
%130 = icmp ne i32 %129, 0
br i1 %130, label %131, label %134
131: ; preds = %124
%132 = load i32, i32* %3
%133 = call i64 @write(i32 %132, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %150
134: ; preds = %124
%135 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 1
%136 = load i8*, i8** %135
%137 = call i32 @stat(i8* %136, %struct.stat* %19)
%138 = getelementptr inbounds %struct.stat, %struct.stat* %19, i32 0, i32 0
%139 = load i64, i64* %138
store i64 %139, i64* %18
%140 = load i32, i32* %17
%141 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%142 = load i64, i64* %18
%143 = trunc i64 %142 to i32
%144 = call i32 @read(i32 %140, i8* %141, i32 %143)
%145 = load i32, i32* %3
%146 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%147 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%148 = call i32 @strlen(i8* %147)
%149 = call i64 @write(i32 %145, i8* %146, i32 %148)
br label %150
150: ; preds = %134, %131
br label %189
151: ; preds = %119
%152 = load i32, i32* @STDOUT_FILENO
%153 = call i32 @dup(i32 %152)
store i32 %153, i32* %6
%154 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%155 = call i32 @pipe(i32* %154)
%156 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%157 = load i32, i32* %156
%158 = load i32, i32* @STDOUT_FILENO
%159 = call i32 @dup2(i32 %157, i32 %158)
%160 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 1
%161 = load i32, i32* %160
%162 = call i32 @close(i32 %161)
%163 = call i64 (...) @fork()
store i64 %163, i64* %12
%164 = load i64, i64* %12
%165 = icmp eq i64 %164, 0
br i1 %165, label %166, label %172
166: ; preds = %151
%167 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 0
%168 = load i8*, i8** %167
%169 = getelementptr inbounds [20 x i8*], [20 x i8*]* %15, i64 0, i64 0
%170 = call i32 @execvp(i8* %168, i8** %169)
%171 = call i32 @exit(i32 -1)
unreachable
172: ; preds = %151
%173 = call i32 @wait(i32* %4)
br label %174
174: ; preds = %172
%175 = getelementptr inbounds [2 x i32], [2 x i32]* %11, i64 0, i64 0
%176 = load i32, i32* %175
%177 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%178 = call i32 @read(i32 %176, i8* %177, i32 32767)
%179 = load i32, i32* @stdout
%180 = call i32 @fflush(i32 %179)
%181 = load i32, i32* %6
%182 = load i32, i32* @STDOUT_FILENO
%183 = call i32 @dup2(i32 %181, i32 %182)
%184 = load i32, i32* %3
%185 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%186 = getelementptr inbounds [32768 x i8], [32768 x i8]* %8, i64 0, i64 0
%187 = call i32 @strlen(i8* %186)
%188 = call i64 @write(i32 %184, i8* %185, i32 %187)
br label %189
189: ; preds = %174, %150
br label %190
190: ; preds = %189, %118
br label %191
191: ; preds = %190
br label %194
192: ; preds = %43
%193 = call i32 @exit(i32 1)
unreachable
194: ; preds = %191
br label %195
195: ; preds = %194, %39
br label %35
196: ; preds = %55
%197 = load i32, i32* %3
%198 = call i32 @close(i32 %197)
%199 = load i32, i32* %2
%200 = call i32 @close(i32 %199)
%201 = load i32, i32* @EXIT_SUCCESS
ret i32 %201
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.stat = type { i64 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@INADDR_ANY = global i32 0
@.str = [6 x i8] c"exit\0A\00"
@.str.1 = [15 x i8] c"Kommando: %s \0A\00"
@.str.2 = [2 x i8] c" \00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [4 x i8] c"put\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_APPEND = global i32 0
@.str.5 = [3 x i8] c"-1\00"
@.str.6 = [4 x i8] c"get\00"
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@stdout = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [32768 x i8]
%4 = alloca %struct.sockaddr_in
%5 = alloca %struct.sockaddr_in
%6 = alloca [2 x i32]
%7 = alloca [20 x i8*]
%8 = alloca %struct.stat
%9 = bitcast i32* %1 to i8*
%10 = bitcast i32* %2 to i8*
%11 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 0
%12 = bitcast %struct.sockaddr_in* %4 to i8*
%13 = bitcast %struct.sockaddr_in* %5 to i8*
%14 = bitcast [2 x i32]* %6 to i8*
%15 = load i32, i32* @AF_INET
%16 = load i32, i32* @SOCK_STREAM
%17 = tail call i32 @socket(i32 %15, i32 %16, i32 0)
%18 = load i32, i32* @AF_INET
%19 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 2
store i32 %18, i32* %19
%20 = load i32, i32* @INADDR_ANY
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 1, i32 0
store i32 %20, i32* %21
%22 = tail call i32 @htons(i32 9000)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %4, i64 0, i32 0
store i32 %22, i32* %23
%24 = bitcast %struct.sockaddr_in* %4 to %struct.sockaddr*
%25 = call i32 @bind(i32 %17, %struct.sockaddr* %24, i32 12)
%26 = call i32 @listen(i32 %17, i32 5)
%27 = bitcast [20 x i8*]* %7 to i8*
%28 = getelementptr inbounds [20 x i8*], [20 x i8*]* %7, i64 0, i64 0
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%31 = getelementptr inbounds [20 x i8*], [20 x i8*]* %7, i64 0, i64 1
%32 = bitcast %struct.stat* %8 to i8*
%33 = getelementptr inbounds %struct.stat, %struct.stat* %8, i64 0, i32 0
%34 = getelementptr inbounds [20 x i8*], [20 x i8*]* %7, i64 0, i64 2
%35 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
br label %36
36: ; preds = %41, %0
%37 = phi i32 [ %42, %41 ], [ undef, %0 ]
br label %38
38: ; preds = %36, %133
%39 = call i64 (...) @fork()
%40 = icmp sgt i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %38
store i32 12, i32* %2
%42 = call i32 @accept(i32 %17, %struct.sockaddr* %35, i32* %2)
br label %36
43: ; preds = %38
%44 = icmp eq i64 %39, 0
br i1 %44, label %45, label %134
45: ; preds = %43
%46 = call i32 @bzero(i8* %11, i32 32768)
%47 = call i32 @read(i32 %37, i8* %11, i32 32767)
%48 = call i64 @strcmp(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %11)
%49 = icmp eq i64 %48, 0
br i1 %49, label %136, label %50
50: ; preds = %45
%51 = call i32 @strlen(i8* %11)
%52 = add nsw i32 %51, -1
%53 = sext i32 %52 to i64
%54 = getelementptr inbounds [32768 x i8], [32768 x i8]* %3, i64 0, i64 %53
store i8 0, i8* %54
%55 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%56 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%57 = icmp eq i8* %56, null
br i1 %57, label %65, label %58
58: ; preds = %50, %58
%59 = phi i64 [ %63, %58 ], [ 0, %50 ]
%60 = phi i8* [ %62, %58 ], [ %56, %50 ]
%61 = getelementptr inbounds [20 x i8*], [20 x i8*]* %7, i64 0, i64 %59
store i8* %60, i8** %61
%62 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%63 = add nuw i64 %59, 1
%64 = icmp eq i8* %62, null
br i1 %64, label %65, label %58
65: ; preds = %58, %50
%66 = phi i64 [ 0, %50 ], [ %63, %58 ]
%67 = and i64 %66, 4294967295
%68 = getelementptr inbounds [20 x i8*], [20 x i8*]* %7, i64 0, i64 %67
store i8* null, i8** %68
%69 = load i8*, i8** %28
%70 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %69)
%71 = call i64 @strcmp(i8* %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0))
%72 = icmp eq i64 %71, 0
br i1 %72, label %73, label %92
73: ; preds = %65
%74 = load i8*, i8** %31
%75 = load i32, i32* @O_WRONLY
%76 = load i32, i32* @O_CREAT
%77 = or i32 %76, %75
%78 = load i32, i32* @O_APPEND
%79 = or i32 %77, %78
%80 = call i32 (i8*, i32, ...) @open(i8* %74, i32 %79, i32 420)
%81 = load i8*, i8** %34
%82 = call i32 @strlen(i8* %81)
%83 = call i64 @write(i32 %80, i8* %81, i32 %82)
%84 = call i32 @strlen(i8* %81)
%85 = sext i32 %84 to i64
%86 = icmp eq i64 %83, %85
br i1 %86, label %89, label %87
87: ; preds = %73
%88 = call i64 @write(i32 %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %133
89: ; preds = %73
%90 = call i32 @strlen(i8* %11)
%91 = call i64 @write(i32 %37, i8* %11, i32 %90)
br label %133
92: ; preds = %65
%93 = call i64 @strcmp(i8* %69, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0))
%94 = icmp eq i64 %93, 0
br i1 %94, label %95, label %109
95: ; preds = %92
%96 = load i8*, i8** %31
%97 = load i32, i32* @O_RDONLY
%98 = call i32 (i8*, i32, ...) @open(i8* %96, i32 %97)
%99 = icmp eq i32 %98, 0
br i1 %99, label %102, label %100
100: ; preds = %95
%101 = call i64 @write(i32 %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32 2)
br label %133
102: ; preds = %95
%103 = call i32 @stat(i8* %96, %struct.stat* %8)
%104 = load i64, i64* %33
%105 = trunc i64 %104 to i32
%106 = call i32 @read(i32 0, i8* %11, i32 %105)
%107 = call i32 @strlen(i8* %11)
%108 = call i64 @write(i32 %37, i8* %11, i32 %107)
br label %133
109: ; preds = %92
%110 = load i32, i32* @STDOUT_FILENO
%111 = call i32 @dup(i32 %110)
%112 = call i32 @pipe(i32* %29)
%113 = load i32, i32* %30
%114 = load i32, i32* @STDOUT_FILENO
%115 = call i32 @dup2(i32 %113, i32 %114)
%116 = load i32, i32* %30
%117 = call i32 @close(i32 %116)
%118 = call i64 (...) @fork()
%119 = icmp eq i64 %118, 0
br i1 %119, label %120, label %123
120: ; preds = %109
%121 = call i32 @execvp(i8* %69, i8** %28)
%122 = call i32 @exit(i32 -1)
unreachable
123: ; preds = %109
%124 = call i32 @wait(i32* %1)
%125 = load i32, i32* %29
%126 = call i32 @read(i32 %125, i8* %11, i32 32767)
%127 = load i32, i32* @stdout
%128 = call i32 @fflush(i32 %127)
%129 = load i32, i32* @STDOUT_FILENO
%130 = call i32 @dup2(i32 %111, i32 %129)
%131 = call i32 @strlen(i8* %11)
%132 = call i64 @write(i32 %37, i8* %11, i32 %131)
br label %133
133: ; preds = %100, %102, %87, %89, %123
br label %38
134: ; preds = %43
%135 = call i32 @exit(i32 1)
unreachable
136: ; preds = %45
%137 = call i32 @close(i32 %37)
%138 = call i32 @close(i32 %17)
%139 = load i32, i32* @EXIT_SUCCESS
ret i32 %139
}