#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 */
typedef int /*<<< orphan*/ pid_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int sprintf(char *, char *, char *, char *, ...);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ system(char *);
void add_proxy_cmd(char *addr, int portNumber, char *namespace) {
  int cmdlen;
  char *cmd;
  pid_t pid;
  cmd = (char *)malloc(sizeof(char) * 200);
  fprintf(stdout, "%d\n", portNumber);
  memset(cmd, (int)'\0', 200);
  cmdlen = sprintf(cmd,
                   "ip netns exec %s %s -t nat -I PREROUTING -p tcp --dport %d "
                   "-j DNAT --to-destination %s:22 ",
                   namespace, "/sbin/iptables", portNumber, addr);
  fprintf(stdout, "%s\n", cmd);
  system(cmd);
  memset(cmd, (int)'\0', 200);
  cmdlen =
      sprintf(cmd, "ip netns exec %s %s -I FORWARD -p tcp -s %s -j ACCEPT ",
              namespace, "/sbin/iptables", addr);
  fprintf(stdout, "%s\n", cmd);
  system(cmd);
  memset(cmd, (int)'\0', 200);
  cmdlen = sprintf(
      cmd,
      "ip netns exec %s %s -t nat -I POSTROUTING -p tcp -s %s -j MASQUERADE ",
      namespace, "/sbin/iptables", addr);
  fprintf(stdout, "%s\n", cmd);
  system(cmd);
  free(cmd);
}


x86 assembly (clang, -O0):
<add_proxy_cmd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%edi
mov    -0xc(%rbp),%edx
lea    0xe6c(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0xc(%rbp),%r8d
mov    -0x8(%rbp),%r9
lea    0xe42(%rip),%rsi
lea    0xe96(%rip),%rcx
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe87(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <system@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%r8
lea    0xe58(%rip),%rsi
lea    0xe3e(%rip),%rcx
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2dae(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xe2f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <system@plt>
mov    -0x28(%rbp),%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x8(%rbp),%r8
lea    0xe37(%rip),%rsi
lea    0xde6(%rip),%rcx
mov    $0x0,%al
call   1080 <sprintf@plt>
mov    %eax,-0x1c(%rbp)
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <system@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_proxy_cmd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %esi,%ebp
mov    %rdi,%r14
mov    $0xc8,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
mov    %rax,%r13
lea    0xe6d(%rip),%rsi
mov    %ebp,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
lea    0xe52(%rip),%rsi
lea    0xea6(%rip),%r12
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %ebp,%r8d
mov    %r14,%r9
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    %r13,%rbp
mov    0x0(%r13),%edi
lea    0xe91(%rip),%r13
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
lea    0xe6a(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    0x0(%rbp),%edi
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xc8,%edx
call   1050 <memset@plt>
lea    0xe60(%rip),%rsi
mov    %rbx,%rdi
mov    %r15,%rdx
mov    %r12,%rcx
mov    %r14,%r8
xor    %eax,%eax
call   1080 <sprintf@plt>
mov    0x0(%rbp),%edi
mov    %r13,%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <system@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>

LLVM IR (-O0):
@stdout = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [91 x i8] c"ip netns exec %s %s -t nat -I PREROUTING -p tcp --dport %d -j DNAT --to-destination %s:22 \00"
@.str.2 = [15 x i8] c"/sbin/iptables\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [55 x i8] c"ip netns exec %s %s -I FORWARD -p tcp -s %s -j ACCEPT \00"
@.str.5 = [70 x i8] c"ip netns exec %s %s -t nat -I POSTROUTING -p tcp -s %s -j MASQUERADE \00"
define void @add_proxy_cmd(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%10 = call i64 @malloc(i32 200)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %8
%12 = load i32, i32* @stdout
%13 = load i32, i32* %5
%14 = call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %13)
%15 = load i8*, i8** %8
%16 = call i32 @memset(i8* %15, i32 0, i32 200)
%17 = load i8*, i8** %8
%18 = load i8*, i8** %6
%19 = load i32, i32* %5
%20 = load i8*, i8** %4
%21 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([91 x i8], [91 x i8]* @.str.1, i64 0, i64 0), i8* %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %19, i8* %20)
store i32 %21, i32* %7
%22 = load i32, i32* @stdout
%23 = load i8*, i8** %8
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %23)
%25 = load i8*, i8** %8
%26 = call i32 @system(i8* %25)
%27 = load i8*, i8** %8
%28 = call i32 @memset(i8* %27, i32 0, i32 200)
%29 = load i8*, i8** %8
%30 = load i8*, i8** %6
%31 = load i8*, i8** %4
%32 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %29, i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %30, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %31)
store i32 %32, i32* %7
%33 = load i32, i32* @stdout
%34 = load i8*, i8** %8
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %34)
%36 = load i8*, i8** %8
%37 = call i32 @system(i8* %36)
%38 = load i8*, i8** %8
%39 = call i32 @memset(i8* %38, i32 0, i32 200)
%40 = load i8*, i8** %8
%41 = load i8*, i8** %6
%42 = load i8*, i8** %4
%43 = call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* %40, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i8* %41, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %42)
store i32 %43, i32* %7
%44 = load i32, i32* @stdout
%45 = load i8*, i8** %8
%46 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %8
%48 = call i32 @system(i8* %47)
%49 = load i8*, i8** %8
%50 = call i32 @free(i8* %49)
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [4 x i8] c"%d\0A\00"
@.str.1 = [91 x i8] c"ip netns exec %s %s -t nat -I PREROUTING -p tcp --dport %d -j DNAT --to-destination %s:22 \00"
@.str.2 = [15 x i8] c"/sbin/iptables\00"
@.str.3 = [4 x i8] c"%s\0A\00"
@.str.4 = [55 x i8] c"ip netns exec %s %s -I FORWARD -p tcp -s %s -j ACCEPT \00"
@.str.5 = [70 x i8] c"ip netns exec %s %s -t nat -I POSTROUTING -p tcp -s %s -j MASQUERADE \00"
define void @add_proxy_cmd(i8* %0, i32 %1, i8* %2) {
%4 = tail call i64 @malloc(i32 200)
%5 = inttoptr i64 %4 to i8*
%6 = load i32, i32* @stdout
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %1)
%8 = tail call i32 @memset(i8* %5, i32 0, i32 200)
%9 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([91 x i8], [91 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %1, i8* %0)
%10 = load i32, i32* @stdout
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%12 = tail call i32 @system(i8* %5)
%13 = tail call i32 @memset(i8* %5, i32 0, i32 200)
%14 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.4, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%15 = load i32, i32* @stdout
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%17 = tail call i32 @system(i8* %5)
%18 = tail call i32 @memset(i8* %5, i32 0, i32 200)
%19 = tail call i32 (i8*, i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %5, i8* dereferenceable(1) getelementptr inbounds ([70 x i8], [70 x i8]* @.str.5, i64 0, i64 0), i8* %2, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%20 = load i32, i32* @stdout
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%22 = tail call i32 @system(i8* %5)
%23 = tail call i32 @free(i8* %5)
ret void
}