#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 */
typedef int /*<<< orphan*/ tcpaddr;
struct TYPE_2__ {
  int /*<<< orphan*/ s_addr;
};
struct sockaddr_in {
  TYPE_1__ sin_addr;
  int /*<<< orphan*/ sin_port;
  int /*<<< orphan*/ sin_family;
};
struct sockaddr {
  int dummy;
};
typedef int /*<<< orphan*/ socklen_t;
typedef int /*<<< orphan*/ peer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ INADDR_ANY;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int /*<<< orphan*/ *);
int atoi(char *);
scalar_t__ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char findEndOfString(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int /*<<< orphan*/, int,
                          int /*<<< orphan*/ *);
int /*<<< orphan*/ htonl(int /*<<< orphan*/);
int /*<<< orphan*/ htons(int);
int /*<<< orphan*/ inet_ntoa(TYPE_1__);
char isSet(char *);
int listen(int, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *, char *, int);
int recv(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, char);
int /*<<< orphan*/ substring(char *, char *, char, char);
int /*<<< orphan*/ system(char *);
int /*<<< orphan*/ writeClientIp(int /*<<< orphan*/);
int /*<<< orphan*/ writeMyPort(int);
int main(int argc, char **argv) {
  char key[1024] = "";
  char value[1024] = "";
  char buf[1024];
  char eq_position, end_position;
  char str_length = 0;
  int tcpserver_port = 27000;
  int bytes_read;
  const char PORT_ARGUMENT = 1;
  tcpserver_port = atoi(argv[PORT_ARGUMENT]);
  writeMyPort(tcpserver_port);
  int tcpsock, new_sock;
  struct sockaddr_in tcpaddr, peer;
  int ready_to_recieve;
  tcpsock = socket(AF_INET, SOCK_STREAM, 0);
  if (tcpsock < 0) {
    perror("cannot create tcpsocket");
    exit(1);
  }
  tcpaddr.sin_family = AF_INET;
  tcpaddr.sin_port = htons(tcpserver_port);
  tcpaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  if (bind(tcpsock, (struct sockaddr *)&tcpaddr, sizeof(tcpaddr)) < 0) {
    perror("cannot bind tcpsocket");
    exit(2);
  }
  ready_to_recieve = listen(tcpsock, 1);
  while (1) {
    if (ready_to_recieve == 0) {
      int size = sizeof(peer);
      new_sock = accept(tcpsock, (struct sockaddr *)&peer, (socklen_t *)&size);
      if (new_sock < 0) {
        perror("accept");
        exit(3);
      }
      writeClientIp(inet_ntoa(peer.sin_addr));
      system("./feedback");
      while (1) {
        bytes_read = recv(new_sock, buf, 1024, 0);
        if (bytes_read <= 0)
          break;
        char filename[1024] = "";
        char output[1024];
        eq_position = isSet(buf);
        end_position = findEndOfString(buf);
        str_length = end_position - eq_position;
        strncpy(key, buf, eq_position);
        substring(value, buf, eq_position + 1, str_length);
        key[eq_position] = '\0';
        value[str_length] = '\0';
        printf("KEY: '%s' - VALUE: '%s'; BYTES_READ: %d\n", key, value,
               bytes_read);
        strcat(filename, "./control/");
        strcat(filename, key);
        FILE *file;
        if ((file = fopen(filename, "w")) == NULL) {
          perror("Cannot open file.");
          exit(1);
        }
        fwrite(value, strlen(value), 1, file);
        fclose(file);
      }
      close(new_sock);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1460,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1100 <memset@plt>
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1100 <memset@plt>
movb   $0x0,-0xc13(%rbp)
movl   $0x6978,-0xc18(%rbp)
movb   $0x1,-0xc1d(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1180 <atoi@plt>
mov    %eax,-0xc18(%rbp)
mov    -0xc18(%rbp),%edi
call   1130 <writeMyPort@plt>
mov    0x2ccc(%rip),%rax
mov    (%rax),%edi
mov    0x2cab(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11c0 <socket@plt>
mov    %eax,-0xc24(%rbp)
cmpl   $0x0,-0xc24(%rbp)
jge    1357 <main+0xb7>
lea    0xcb8(%rip),%rdi
call   1160 <perror@plt>
mov    $0x1,%edi
call   11a0 <exit@plt>
mov    0x2c8a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc30(%rbp)
mov    -0xc18(%rbp),%edi
call   10c0 <htons@plt>
mov    %eax,-0xc34(%rbp)
mov    0x2c62(%rip),%rax
mov    (%rax),%edi
call   10f0 <htonl@plt>
mov    %eax,-0xc38(%rbp)
mov    -0xc24(%rbp),%edi
lea    -0xc38(%rbp),%rsi
mov    $0xc,%edx
call   1140 <bind@plt>
cmp    $0x0,%rax
jge    13c2 <main+0x122>
lea    0xc65(%rip),%rdi
call   1160 <perror@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    -0xc24(%rbp),%edi
mov    $0x1,%esi
call   1120 <listen@plt>
mov    %eax,-0xc4c(%rbp)
cmpl   $0x0,-0xc4c(%rbp)
jne    15fe <main+0x35e>
movl   $0xc,-0xc50(%rbp)
mov    -0xc24(%rbp),%edi
lea    -0xc48(%rbp),%rsi
lea    -0xc50(%rbp),%rdx
call   1170 <accept@plt>
mov    %eax,-0xc28(%rbp)
cmpl   $0x0,-0xc28(%rbp)
jge    1431 <main+0x191>
lea    0xc0c(%rip),%rdi
call   1160 <perror@plt>
mov    $0x3,%edi
call   11a0 <exit@plt>
mov    -0xc48(%rbp),%edi
call   1070 <inet_ntoa@plt>
mov    %eax,%edi
call   1060 <writeClientIp@plt>
lea    0xbeb(%rip),%rdi
call   10b0 <system@plt>
mov    -0xc28(%rbp),%edi
lea    -0xc10(%rbp),%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,-0xc1c(%rbp)
cmpl   $0x0,-0xc1c(%rbp)
jg     1480 <main+0x1e0>
jmp    15f3 <main+0x353>
lea    -0x1050(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1100 <memset@plt>
lea    -0xc10(%rbp),%rdi
call   1030 <isSet@plt>
mov    %al,-0xc11(%rbp)
lea    -0xc10(%rbp),%rdi
call   1090 <findEndOfString@plt>
mov    %al,-0xc12(%rbp)
movsbl -0xc12(%rbp),%eax
movsbl -0xc11(%rbp),%ecx
sub    %ecx,%eax
mov    %al,-0xc13(%rbp)
lea    -0x410(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
movsbl -0xc11(%rbp),%edx
call   1050 <strncpy@plt>
lea    -0x810(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
movsbl -0xc11(%rbp),%eax
add    $0x1,%eax
movsbl %al,%edx
movsbl -0xc13(%rbp),%ecx
call   10e0 <substring@plt>
movsbq -0xc11(%rbp),%rax
ff
movb   $0x0,-0x410(%rbp,%rax,1)
movsbq -0xc13(%rbp),%rax
ff
movb   $0x0,-0x810(%rbp,%rax,1)
lea    -0x410(%rbp),%rsi
lea    -0x810(%rbp),%rdx
mov    -0xc1c(%rbp),%ecx
lea    0xaf7(%rip),%rdi
call   10d0 <printf@plt>
lea    -0x1050(%rbp),%rdi
lea    0xb0d(%rip),%rsi
call   1190 <strcat@plt>
lea    -0x1050(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1190 <strcat@plt>
lea    -0x1050(%rbp),%rdi
lea    0xaf2(%rip),%rsi
call   1150 <fopen@plt>
mov    %rax,-0x1458(%rbp)
cmp    $0x0,%rax
jne    15ae <main+0x30e>
lea    0xad7(%rip),%rdi
call   1160 <perror@plt>
mov    $0x1,%edi
call   11a0 <exit@plt>
lea    -0x810(%rbp),%rax
mov    %rax,-0x1460(%rbp)
lea    -0x810(%rbp),%rdi
call   10a0 <strlen@plt>
mov    -0x1460(%rbp),%rdi
mov    %eax,%esi
mov    -0x1458(%rbp),%rcx
mov    $0x1,%edx
call   11b0 <fwrite@plt>
mov    -0x1458(%rbp),%rdi
call   1080 <fclose@plt>
jmp    144f <main+0x1af>
mov    -0xc28(%rbp),%edi
call   1110 <close@plt>
jmp    13d8 <main+0x138>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1038,%rsp
mov    %rsi,%rbx
lea    0x430(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1100 <memset@plt>
lea    0x30(%rsp),%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1100 <memset@plt>
mov    0x8(%rbx),%rdi
call   1180 <atoi@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1130 <writeMyPort@plt>
mov    0x2cf6(%rip),%r14
mov    (%r14),%edi
mov    0x2cd4(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   11c0 <socket@plt>
test   %eax,%eax
jns    1315 <main+0x75>
lea    0xcf0(%rip),%rdi
jmp    151e <main+0x27e>
mov    %eax,%r15d
mov    (%r14),%eax
mov    %eax,0x18(%rsp)
mov    %ebx,%edi
call   10c0 <htons@plt>
mov    %eax,0x14(%rsp)
mov    0x2caf(%rip),%rax
mov    (%rax),%edi
call   10f0 <htonl@plt>
mov    %eax,0x10(%rsp)
lea    0x10(%rsp),%rsi
mov    %r15d,%edi
mov    $0xc,%edx
call   1140 <bind@plt>
test   %rax,%rax
jns    1369 <main+0xc9>
lea    0xcbe(%rip),%rdi
call   1160 <perror@plt>
mov    $0x2,%edi
call   11a0 <exit@plt>
mov    %r15d,%edi
mov    $0x1,%esi
call   1120 <listen@plt>
mov    %eax,%ebx
lea    0xc30(%rsp),%r14
mov    %r15d,0x8(%rsp)
mov    %eax,0x4(%rsp)
jmp    13a1 <main+0x101>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%edi
call   1110 <close@plt>
mov    0x8(%rsp),%r15d
mov    0x4(%rsp),%ebx
test   %ebx,%ebx
jne    13a1 <main+0x101>
movl   $0xc,0xc(%rsp)
mov    %r15d,%edi
lea    0x20(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1170 <accept@plt>
test   %eax,%eax
js     152d <main+0x28d>
mov    %eax,%ebp
mov    0x20(%rsp),%edi
call   1070 <inet_ntoa@plt>
mov    %eax,%edi
call   1060 <writeClientIp@plt>
lea    0xc55(%rip),%rdi
call   10b0 <system@plt>
mov    %ebp,(%rsp)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
test   %eax,%eax
lea    0x30(%rsp),%r15
jle    1390 <main+0xf0>
mov    %eax,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x400,%edx
lea    0x830(%rsp),%rdi
xor    %esi,%esi
call   1100 <memset@plt>
mov    %r14,%rdi
call   1030 <isSet@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1090 <findEndOfString@plt>
mov    %eax,%ebx
sub    %bpl,%bl
movsbl %bpl,%ebp
mov    %r14,%r12
lea    0x430(%rsp),%r14
mov    %r14,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
call   1050 <strncpy@plt>
lea    0x1(%rbp),%eax
movsbl %bl,%ebx
movsbl %al,%edx
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebx,%ecx
call   10e0 <substring@plt>
movsbq %bpl,%rax
movb   $0x0,0x430(%rsp,%rax,1)
movsbq %bl,%rax
movb   $0x0,0x30(%rsp,%rax,1)
lea    0xbb7(%rip),%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r13d,%ecx
call   10d0 <printf@plt>
lea    0x830(%rsp),%rbx
mov    %rbx,%rdi
lea    0xbc0(%rip),%rsi
call   1190 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1190 <strcat@plt>
mov    %rbx,%rdi
lea    0xbb1(%rip),%rsi
call   1150 <fopen@plt>
test   %rax,%rax
je     1517 <main+0x277>
mov    %rax,%rbp
mov    %r15,%rdi
call   10a0 <strlen@plt>
mov    %r15,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   11b0 <fwrite@plt>
mov    %rbp,%rdi
call   1080 <fclose@plt>
mov    (%rsp),%edi
mov    %r12,%rsi
mov    $0x400,%edx
xor    %ecx,%ecx
call   1040 <recv@plt>
mov    %eax,%r13d
test   %eax,%eax
mov    %r12,%r14
jg     1410 <main+0x170>
jmp    1390 <main+0xf0>
lea    0xb58(%rip),%rdi
call   1160 <perror@plt>
mov    $0x1,%edi
call   11a0 <exit@plt>
lea    0xafa(%rip),%rdi
call   1160 <perror@plt>
mov    $0x3,%edi
call   11a0 <exit@plt>

LLVM IR (-O0):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"cannot create tcpsocket\00"
@INADDR_ANY = global i32 0
@.str.1 = [22 x i8] c"cannot bind tcpsocket\00"
@.str.2 = [7 x i8] c"accept\00"
@.str.3 = [11 x i8] c"./feedback\00"
@.str.4 = [41 x i8] c"KEY: '%s' - VALUE: '%s'; BYTES_READ: %d\0A\00"
@.str.5 = [11 x i8] c"./control/\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [18 x i8] c"Cannot open file.\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca [1024 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8
%12 = alloca i32
%13 = alloca i32
%14 = alloca i8
%15 = alloca i32
%16 = alloca i32
%17 = alloca %struct.sockaddr_in
%18 = alloca %struct.sockaddr_in
%19 = alloca i32
%20 = alloca i32
%21 = alloca [1024 x i8]
%22 = alloca [1024 x i8]
%23 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%24 = bitcast [1024 x i8]* %6 to i8*
%25 = bitcast [1024 x i8]* %7 to i8*
store i8 0, i8* %11
store i32 27000, i32* %12
store i8 1, i8* %14
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %12
%30 = load i32, i32* %12
%31 = call i32 @writeMyPort(i32 %30)
%32 = load i32, i32* @AF_INET
%33 = load i32, i32* @SOCK_STREAM
%34 = call i32 @socket(i32 %32, i32 %33, i32 0)
store i32 %34, i32* %15
%35 = load i32, i32* %15
%36 = icmp slt i32 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %2
%38 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %2
%41 = load i32, i32* @AF_INET
%42 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 2
store i32 %41, i32* %42
%43 = load i32, i32* %12
%44 = call i32 @htons(i32 %43)
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 1
store i32 %44, i32* %45
%46 = load i32, i32* @INADDR_ANY
%47 = call i32 @htonl(i32 %46)
%48 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %17, i32 0, i32 0
%49 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %48, i32 0, i32 0
store i32 %47, i32* %49
%50 = load i32, i32* %15
%51 = bitcast %struct.sockaddr_in* %17 to %struct.sockaddr*
%52 = call i64 @bind(i32 %50, %struct.sockaddr* %51, i32 12)
%53 = icmp slt i64 %52, 0
br i1 %53, label %54, label %57
54: ; preds = %40
%55 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%56 = call i32 @exit(i32 2)
unreachable
57: ; preds = %40
%58 = load i32, i32* %15
%59 = call i32 @listen(i32 %58, i32 1)
store i32 %59, i32* %19
br label %60
60: ; preds = %57, %142
%61 = load i32, i32* %19
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %142
63: ; preds = %60
store i32 12, i32* %20
%64 = load i32, i32* %15
%65 = bitcast %struct.sockaddr_in* %18 to %struct.sockaddr*
%66 = call i32 @accept(i32 %64, %struct.sockaddr* %65, i32* %20)
store i32 %66, i32* %16
%67 = load i32, i32* %16
%68 = icmp slt i32 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %63
%70 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%71 = call i32 @exit(i32 3)
unreachable
72: ; preds = %63
%73 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %18, i32 0, i32 0
%74 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %73, i32 0, i32 0
%75 = load i32, i32* %74
%76 = call i32 @inet_ntoa(i32 %75)
%77 = call i32 @writeClientIp(i32 %76)
%78 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
br label %79
79: ; preds = %72, %131
%80 = load i32, i32* %16
%81 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%82 = call i32 @recv(i32 %80, i8* %81, i32 1024, i32 0)
store i32 %82, i32* %13
%83 = load i32, i32* %13
%84 = icmp sle i32 %83, 0
br i1 %84, label %85, label %86
85: ; preds = %79
br label %139
86: ; preds = %79
%87 = bitcast [1024 x i8]* %21 to i8*
%88 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%89 = call signext i8 @isSet(i8* %88)
store i8 %89, i8* %9
%90 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%91 = call signext i8 @findEndOfString(i8* %90)
store i8 %91, i8* %10
%92 = load i8, i8* %10
%93 = sext i8 %92 to i32
%94 = load i8, i8* %9
%95 = sext i8 %94 to i32
%96 = sub nsw i32 %93, %95
%97 = trunc i32 %96 to i8
store i8 %97, i8* %11
%98 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%99 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%100 = load i8, i8* %9
%101 = call i32 @strncpy(i8* %98, i8* %99, i8 signext %100)
%102 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%103 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%104 = load i8, i8* %9
%105 = sext i8 %104 to i32
%106 = add nsw i32 %105, 1
%107 = trunc i32 %106 to i8
%108 = load i8, i8* %11
%109 = call i32 @substring(i8* %102, i8* %103, i8 signext %107, i8 signext %108)
%110 = load i8, i8* %9
%111 = sext i8 %110 to i64
%112 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 %111
store i8 0, i8* %112
%113 = load i8, i8* %11
%114 = sext i8 %113 to i64
%115 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 %114
store i8 0, i8* %115
%116 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%117 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%118 = load i32, i32* %13
%119 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %116, i8* %117, i32 %118)
%120 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%121 = call i32 @strcat(i8* %120, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%122 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%123 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%124 = call i32 @strcat(i8* %122, i8* %123)
%125 = getelementptr inbounds [1024 x i8], [1024 x i8]* %21, i64 0, i64 0
%126 = call i32* @fopen(i8* %125, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %126, i32** %23
%127 = icmp eq i32* %126, null
br i1 %127, label %128, label %131
128: ; preds = %86
%129 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%130 = call i32 @exit(i32 1)
unreachable
131: ; preds = %86
%132 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%133 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%134 = call i32 @strlen(i8* %133)
%135 = load i32*, i32** %23
%136 = call i32 @fwrite(i8* %132, i32 %134, i32 1, i32* %135)
%137 = load i32*, i32** %23
%138 = call i32 @fclose(i32* %137)
br label %79
139: ; preds = %85
%140 = load i32, i32* %16
%141 = call i32 @close(i32 %140)
br label %142
142: ; preds = %139, %60
br label %60
}

LLVM IR (-O2):
%struct.sockaddr_in = type { %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr = type { i32 }
@AF_INET = global i32 0
@SOCK_STREAM = global i32 0
@.str = [24 x i8] c"cannot create tcpsocket\00"
@INADDR_ANY = global i32 0
@.str.1 = [22 x i8] c"cannot bind tcpsocket\00"
@.str.2 = [7 x i8] c"accept\00"
@.str.3 = [11 x i8] c"./feedback\00"
@.str.4 = [41 x i8] c"KEY: '%s' - VALUE: '%s'; BYTES_READ: %d\0A\00"
@.str.5 = [11 x i8] c"./control/\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [18 x i8] c"Cannot open file.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = alloca %struct.sockaddr_in
%7 = alloca %struct.sockaddr_in
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i32 @atoi(i8* %14)
%16 = tail call i32 @writeMyPort(i32 %15)
%17 = bitcast %struct.sockaddr_in* %6 to i8*
%18 = bitcast %struct.sockaddr_in* %7 to i8*
%19 = load i32, i32* @AF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = tail call i32 @socket(i32 %19, i32 %20, i32 0)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %26
23: ; preds = %2
%24 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %2
%27 = load i32, i32* @AF_INET
%28 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 2
store i32 %27, i32* %28
%29 = tail call i32 @htons(i32 %15)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 1
store i32 %29, i32* %30
%31 = load i32, i32* @INADDR_ANY
%32 = tail call i32 @htonl(i32 %31)
%33 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %6, i64 0, i32 0, i32 0
store i32 %32, i32* %33
%34 = bitcast %struct.sockaddr_in* %6 to %struct.sockaddr*
%35 = call i64 @bind(i32 %21, %struct.sockaddr* %34, i32 12)
%36 = icmp slt i64 %35, 0
br i1 %36, label %37, label %40
37: ; preds = %26
%38 = call i32 @perror(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 2)
unreachable
40: ; preds = %26
%41 = call i32 @listen(i32 %21, i32 1)
%42 = icmp eq i32 %41, 0
%43 = bitcast i32* %8 to i8*
%44 = bitcast %struct.sockaddr_in* %7 to %struct.sockaddr*
%45 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %7, i64 0, i32 0, i32 0
%46 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
br label %47
47: ; preds = %89, %40
br i1 %42, label %48, label %89
48: ; preds = %47
store i32 12, i32* %8
%49 = call i32 @accept(i32 %21, %struct.sockaddr* %44, i32* %8)
%50 = icmp slt i32 %49, 0
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%53 = call i32 @exit(i32 3)
unreachable
54: ; preds = %48
%55 = load i32, i32* %45
%56 = call i32 @inet_ntoa(i32 %55)
%57 = call i32 @writeClientIp(i32 %56)
%58 = call i32 @system(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%59 = call i32 @recv(i32 %49, i8* %12, i32 1024, i32 0)
%60 = icmp slt i32 %59, 1
br i1 %60, label %87, label %61
61: ; preds = %54, %81
%62 = phi i32 [ %85, %81 ], [ %59, %54 ]
%63 = call signext i8 @isSet(i8* %12)
%64 = call signext i8 @findEndOfString(i8* %12)
%65 = sub i8 %64, %63
%66 = call i32 @strncpy(i8* %10, i8* %12, i8 signext %63)
%67 = add i8 %63, 1
%68 = call i32 @substring(i8* %11, i8* %12, i8 signext %67, i8 signext %65)
%69 = sext i8 %63 to i64
%70 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 %69
store i8 0, i8* %70
%71 = sext i8 %65 to i64
%72 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 %71
store i8 0, i8* %72
%73 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.4, i64 0, i64 0), i8* %10, i8* %11, i32 %62)
%74 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @strcat(i8* %46, i8* %10)
%76 = call i32* @fopen(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%77 = icmp eq i32* %76, null
br i1 %77, label %78, label %81
78: ; preds = %61
%79 = call i32 @perror(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0))
%80 = call i32 @exit(i32 1)
unreachable
81: ; preds = %61
%82 = call i32 @strlen(i8* %11)
%83 = call i32 @fwrite(i8* %11, i32 %82, i32 1, i32* %76)
%84 = call i32 @fclose(i32* %76)
%85 = call i32 @recv(i32 %49, i8* %12, i32 1024, i32 0)
%86 = icmp slt i32 %85, 1
br i1 %86, label %87, label %61
87: ; preds = %81, %54
%88 = call i32 @close(i32 %49)
br label %89
89: ; preds = %87, %47
br label %47
}