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

/* Variables and functions */
int /*<<< orphan*/ AF_INET;
int /*<<< orphan*/ PF_INET;
int /*<<< orphan*/ SOCK_STREAM;
int accept(int, struct sockaddr *, int *);
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ bind(int, struct sockaddr *, int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ forwardPaths(char *, char *, char *);
int /*<<< orphan*/ htons(int /*<<< orphan*/);
int /*<<< orphan*/ inet_addr(char *);
scalar_t__ listen(int, int);
int /*<<< orphan*/ memset(int /*<<< orphan*/, char, int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ recv(int, char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ removeRules(char *, char *, char *);
int /*<<< orphan*/ send(int, char *, int, int /*<<< orphan*/);
int socket(int /*<<< orphan*/, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strcmp(char *, char *);
char *strtok(char *, char const *);
int start(char *addr, char *port, char *pub_addr) {
  int fwdSocket, newSocket;
  char buffer[1024];
  struct sockaddr_in fwdAddr;
  struct sockaddr_storage fwdStorage;
  socklen_t addr_size;
  char *tmp_addr, *src_addr, *dst_addr, *type;
  const char s[2] = "-";
  fwdSocket = socket(PF_INET, SOCK_STREAM, 0);
  fwdAddr.sin_family = AF_INET;
  fwdAddr.sin_port = htons(atoi(port));
  fwdAddr.sin_addr.s_addr = inet_addr(addr);
  memset(fwdAddr.sin_zero, '\0', sizeof fwdAddr.sin_zero);
  bind(fwdSocket, (struct sockaddr *)&fwdAddr, sizeof(fwdAddr));
  if (listen(fwdSocket, 10) == 0)
    printf("Listening\n");
  else
    printf("Error\n");
  addr_size = sizeof fwdStorage;
  while (1) {
    newSocket = accept(fwdSocket, (struct sockaddr *)&fwdStorage, &addr_size);
    recv(newSocket, buffer, 512, 0);
    type = strtok(buffer, s);
    src_addr = strtok(NULL, s);
    dst_addr = strtok(NULL, s);
    printf("TYPE IS: %s\n", type);
    if (!strcmp(type, "A"))
      forwardPaths(addr, src_addr, dst_addr);
    else
      removeRules(addr, src_addr, dst_addr);
    send(newSocket, type, 512, 0);
  }
  close(newSocket);
  close(fwdSocket);
  return 0;
}


x86 assembly (clang, -O0):
<start>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    0xdf2(%rip),%ax
mov    %ax,-0x462(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%edi
mov    0x2db3(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1110 <socket@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%rdi
call   1100 <atoi@plt>
mov    %eax,%edi
call   1050 <htons@plt>
mov    %eax,-0x428(%rbp)
mov    -0x8(%rbp),%rdi
call   1090 <inet_addr@plt>
mov    %eax,-0x42c(%rbp)
mov    -0x430(%rbp),%edi
xor    %esi,%esi
mov    $0x4,%edx
call   1080 <memset@plt>
mov    -0x1c(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x10,%edx
call   10d0 <bind@plt>
mov    -0x1c(%rbp),%edi
mov    $0xa,%esi
call   10b0 <listen@plt>
cmp    $0x0,%rax
jne    12b5 <start+0xc5>
lea    0xd59(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
jmp    12c3 <start+0xd3>
lea    0xd51(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
movl   $0x4,-0x43c(%rbp)
mov    -0x1c(%rbp),%edi
lea    -0x438(%rbp),%rsi
lea    -0x43c(%rbp),%rdx
call   10f0 <accept@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%edi
lea    -0x420(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
lea    -0x420(%rbp),%rdi
lea    -0x462(%rbp),%rsi
call   10e0 <strtok@plt>
mov    %rax,-0x460(%rbp)
lea    -0x462(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <strtok@plt>
mov    %rax,-0x450(%rbp)
lea    -0x462(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   10e0 <strtok@plt>
mov    %rax,-0x458(%rbp)
mov    -0x460(%rbp),%rsi
lea    0xcc2(%rip),%rdi
mov    $0x0,%al
call   1070 <printf@plt>
mov    -0x460(%rbp),%rdi
lea    0xcba(%rip),%rsi
call   10a0 <strcmp@plt>
cmp    $0x0,%eax
jne    1391 <start+0x1a1>
mov    -0x8(%rbp),%rdi
mov    -0x450(%rbp),%rsi
mov    -0x458(%rbp),%rdx
call   1040 <forwardPaths@plt>
jmp    13a8 <start+0x1b8>
mov    -0x8(%rbp),%rdi
mov    -0x450(%rbp),%rsi
mov    -0x458(%rbp),%rdx
call   10c0 <removeRules@plt>
mov    -0x20(%rbp),%edi
mov    -0x460(%rbp),%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1060 <send@plt>
jmp    12cd <start+0xdd>

x86 assembly (clang, -O2):
<start>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x438,%rsp
mov    %rsi,%r14
mov    %rdi,%rbp
movw   $0x2d,0x6(%rsp)
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
mov    0x2daa(%rip),%rax
mov    (%rax),%esi
xor    %edx,%edx
call   1120 <socket@plt>
mov    %eax,%ebx
mov    0x2da8(%rip),%rax
mov    (%rax),%eax
mov    %eax,0x2c(%rsp)
mov    %r14,%rdi
call   1110 <atoi@plt>
mov    %eax,%edi
call   1060 <htons@plt>
mov    %eax,0x28(%rsp)
mov    %rbp,0x10(%rsp)
mov    %rbp,%rdi
call   10a0 <inet_addr@plt>
mov    %eax,0x24(%rsp)
xor    %esi,%esi
mov    $0x4,%edx
call   1090 <memset@plt>
lea    0x20(%rsp),%rsi
mov    %ebx,%edi
mov    $0x10,%edx
call   10e0 <bind@plt>
mov    %ebx,0x8(%rsp)
mov    %ebx,%edi
mov    $0xa,%esi
call   10c0 <listen@plt>
test   %rax,%rax
lea    0xd74(%rip),%rax
lea    0xd67(%rip),%rdi
cmove  %rax,%rdi
call   1040 <puts@plt>
movl   $0x4,0xc(%rsp)
lea    0x30(%rsp),%rbx
lea    0x6(%rsp),%rbp
jmp    12f2 <start+0xf2>
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   10d0 <removeRules@plt>
mov    %r14d,%edi
mov    %r15,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1070 <send@plt>
mov    0x8(%rsp),%edi
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
call   1100 <accept@plt>
mov    %eax,%r14d
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x200,%edx
xor    %ecx,%ecx
call   1030 <recv@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   10f0 <strtok@plt>
mov    %rax,%r15
xor    %edi,%edi
mov    %rbp,%rsi
call   10f0 <strtok@plt>
mov    %rax,%r12
xor    %edi,%edi
mov    %rbp,%rsi
call   10f0 <strtok@plt>
mov    %rax,%r13
lea    0xcb8(%rip),%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r15,%rdi
lea    0xcb1(%rip),%rsi
call   10b0 <strcmp@plt>
test   %eax,%eax
jne    12d0 <start+0xd0>
mov    0x10(%rsp),%rdi
mov    %r12,%rsi
mov    %r13,%rdx
call   1050 <forwardPaths@plt>
jmp    12e0 <start+0xe0>

LLVM IR (-O0):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@__const.start.s = [2 x i8] c"-\00"
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str = [11 x i8] c"Listening\0A\00"
@.str.1 = [7 x i8] c"Error\0A\00"
@.str.2 = [13 x i8] c"TYPE IS: %s\0A\00"
@.str.3 = [2 x i8] c"A\00"
define i32 @start(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca [1024 x i8]
%10 = alloca %struct.sockaddr_in
%11 = alloca %struct.sockaddr_storage
%12 = alloca i32
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i8*
%17 = alloca [2 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%18 = bitcast [2 x i8]* %17 to i8*
%19 = load i32, i32* @PF_INET
%20 = load i32, i32* @SOCK_STREAM
%21 = call i32 @socket(i32 %19, i32 %20, i32 0)
store i32 %21, i32* %7
%22 = load i32, i32* @AF_INET
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 3
store i32 %22, i32* %23
%24 = load i8*, i8** %5
%25 = call i32 @atoi(i8* %24)
%26 = call i32 @htons(i32 %25)
%27 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 2
store i32 %26, i32* %27
%28 = load i8*, i8** %4
%29 = call i32 @inet_addr(i8* %28)
%30 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 1
%31 = getelementptr inbounds %struct.TYPE_2__, %struct.TYPE_2__* %30, i32 0, i32 0
store i32 %29, i32* %31
%32 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %10, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i32 @memset(i32 %33, i8 signext 0, i32 4)
%35 = load i32, i32* %7
%36 = bitcast %struct.sockaddr_in* %10 to %struct.sockaddr*
%37 = call i32 @bind(i32 %35, %struct.sockaddr* %36, i32 16)
%38 = load i32, i32* %7
%39 = call i64 @listen(i32 %38, i32 10)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %3
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
br label %45
43: ; preds = %3
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %45
45: ; preds = %43, %41
store i32 4, i32* %12
br label %46
46: ; preds = %45, %75
%47 = load i32, i32* %7
%48 = bitcast %struct.sockaddr_storage* %11 to %struct.sockaddr*
%49 = call i32 @accept(i32 %47, %struct.sockaddr* %48, i32* %12)
store i32 %49, i32* %8
%50 = load i32, i32* %8
%51 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%52 = call i32 @recv(i32 %50, i8* %51, i32 512, i32 0)
%53 = getelementptr inbounds [1024 x i8], [1024 x i8]* %9, i64 0, i64 0
%54 = getelementptr inbounds [2 x i8], [2 x i8]* %17, i64 0, i64 0
%55 = call i8* @strtok(i8* %53, i8* %54)
store i8* %55, i8** %16
%56 = getelementptr inbounds [2 x i8], [2 x i8]* %17, i64 0, i64 0
%57 = call i8* @strtok(i8* null, i8* %56)
store i8* %57, i8** %14
%58 = getelementptr inbounds [2 x i8], [2 x i8]* %17, i64 0, i64 0
%59 = call i8* @strtok(i8* null, i8* %58)
store i8* %59, i8** %15
%60 = load i8*, i8** %16
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %60)
%62 = load i8*, i8** %16
%63 = call i32 @strcmp(i8* %62, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%64 = icmp ne i32 %63, 0
br i1 %64, label %70, label %65
65: ; preds = %46
%66 = load i8*, i8** %4
%67 = load i8*, i8** %14
%68 = load i8*, i8** %15
%69 = call i32 @forwardPaths(i8* %66, i8* %67, i8* %68)
br label %75
70: ; preds = %46
%71 = load i8*, i8** %4
%72 = load i8*, i8** %14
%73 = load i8*, i8** %15
%74 = call i32 @removeRules(i8* %71, i8* %72, i8* %73)
br label %75
75: ; preds = %70, %65
%76 = load i32, i32* %8
%77 = load i8*, i8** %16
%78 = call i32 @send(i32 %76, i8* %77, i32 512, i32 0)
br label %46
}

LLVM IR (-O2):
%struct.sockaddr_in = type { i32, %struct.TYPE_2__, i32, i32 }
%struct.TYPE_2__ = type { i32 }
%struct.sockaddr_storage = type { i32 }
%struct.sockaddr = type { i32 }
@PF_INET = global i32 0
@SOCK_STREAM = global i32 0
@AF_INET = global i32 0
@.str.2 = [13 x i8] c"TYPE IS: %s\0A\00"
@.str.3 = [2 x i8] c"A\00"
@str = [6 x i8] c"Error\00"
@str.4 = [10 x i8] c"Listening\00"
define i32 @start(i8* %0, i8* nocapture %1, i8* nocapture readnone %2) {
%4 = alloca [1024 x i8]
%5 = alloca %struct.sockaddr_in
%6 = alloca %struct.sockaddr_storage
%7 = alloca i32
%8 = alloca i16
%9 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%10 = bitcast %struct.sockaddr_in* %5 to i8*
%11 = bitcast %struct.sockaddr_storage* %6 to i8*
%12 = bitcast i32* %7 to i8*
%13 = bitcast i16* %8 to i8*
store i16 45, i16* %8
%14 = load i32, i32* @PF_INET
%15 = load i32, i32* @SOCK_STREAM
%16 = tail call i32 @socket(i32 %14, i32 %15, i32 0)
%17 = load i32, i32* @AF_INET
%18 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 3
store i32 %17, i32* %18
%19 = tail call i32 @atoi(i8* %1)
%20 = tail call i32 @htons(i32 %19)
%21 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 2
store i32 %20, i32* %21
%22 = tail call i32 @inet_addr(i8* %0)
%23 = getelementptr inbounds %struct.sockaddr_in, %struct.sockaddr_in* %5, i64 0, i32 1, i32 0
store i32 %22, i32* %23
%24 = tail call i32 @memset(i32 undef, i8 signext 0, i32 4)
%25 = bitcast %struct.sockaddr_in* %5 to %struct.sockaddr*
%26 = call i32 @bind(i32 %16, %struct.sockaddr* %25, i32 16)
%27 = call i64 @listen(i32 %16, i32 10)
%28 = icmp eq i64 %27, 0
%29 = select i1 %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @str, i64 0, i64 0)
%30 = call i32 @puts(i8* dereferenceable(1) %29)
store i32 4, i32* %7
%31 = bitcast %struct.sockaddr_storage* %6 to %struct.sockaddr*
br label %32
32: ; preds = %45, %3
%33 = call i32 @accept(i32 %16, %struct.sockaddr* %31, i32* %7)
%34 = call i32 @recv(i32 %33, i8* %9, i32 512, i32 0)
%35 = call i8* @strtok(i8* %9, i8* %13)
%36 = call i8* @strtok(i8* null, i8* %13)
%37 = call i8* @strtok(i8* null, i8* %13)
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), i8* %35)
%39 = call i32 @strcmp(i8* dereferenceable(1) %35, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i32 %39, 0
br i1 %40, label %41, label %43
41: ; preds = %32
%42 = call i32 @forwardPaths(i8* %0, i8* %36, i8* %37)
br label %45
43: ; preds = %32
%44 = call i32 @removeRules(i8* %0, i8* %36, i8* %37)
br label %45
45: ; preds = %43, %41
%46 = call i32 @send(i32 %33, i8* %35, i32 512, i32 0)
br label %32
}