#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*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ LOG_ALERT;
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *, char *, int);
int system(char *);
void add_nat(char *ip) {
  char cmd[512];
  int ret = 0;
  snprintf(cmd, sizeof(cmd) - 1,
           "/sbin/iptables -t nat -I POSTROUTING 1 -o eth0 -s "
           "%s/255.255.255.255 -j MASQUERADE",
           ip);
  ret = system(cmd);
  if (ret != 0)
    syslog(LOG_ALERT, "PB CMD NAT -> %s ---- ret=%d", cmd, ret);
  printf("cmd=%s  ---- ret=%d (==0==good)\n", cmd, ret);
}


x86 assembly (clang, -O0):
<add_nat>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x214(%rbp)
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1ff,%esi
lea    0xe90(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x210(%rbp),%rdi
call   1030 <system@plt>
mov    %eax,-0x214(%rbp)
cmpl   $0x0,-0x214(%rbp)
je     11b6 <add_nat+0x76>
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
lea    -0x210(%rbp),%rdx
mov    -0x214(%rbp),%ecx
lea    0xea2(%rip),%rsi
call   1060 <syslog@plt>
lea    -0x210(%rbp),%rsi
mov    -0x214(%rbp),%edx
lea    0xea6(%rip),%rdi
call   1040 <printf@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_nat>:
push   %rbx
sub    $0x200,%rsp
mov    %rdi,%rcx
lea    0xeae(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x1ff,%esi
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <system@plt>
mov    %eax,%ebx
test   %eax,%eax
je     118a <add_nat+0x4a>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
lea    0xed3(%rip),%rsi
mov    %rsp,%rdx
mov    %ebx,%ecx
call   1060 <syslog@plt>
lea    0xedf(%rip),%rdi
mov    %rsp,%rsi
mov    %ebx,%edx
call   1040 <printf@plt>
add    $0x200,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [83 x i8] c"/sbin/iptables -t nat -I POSTROUTING 1 -o eth0 -s %s/255.255.255.255 -j MASQUERADE\00"
@LOG_ALERT = global i32 0
@.str.1 = [29 x i8] c"PB CMD NAT -> %s ---- ret=%d\00"
@.str.2 = [33 x i8] c"cmd=%s ---- ret=%d (==0==good)\0A\00"
define void @add_nat(i8* %0) {
%2 = alloca i8*
%3 = alloca [512 x i8]
%4 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %4
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = load i8*, i8** %2
%7 = call i32 @snprintf(i8* %5, i32 511, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* %6)
%8 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%9 = call i32 @system(i8* %8)
store i32 %9, i32* %4
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %1
%13 = load i32, i32* @LOG_ALERT
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* %4
%16 = call i32 @syslog(i32 %13, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %14, i32 %15)
br label %17
17: ; preds = %12, %1
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%19 = load i32, i32* %4
%20 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %18, i32 %19)
ret void
}

LLVM IR (-O2):
@.str = [83 x i8] c"/sbin/iptables -t nat -I POSTROUTING 1 -o eth0 -s %s/255.255.255.255 -j MASQUERADE\00"
@LOG_ALERT = global i32 0
@.str.1 = [29 x i8] c"PB CMD NAT -> %s ---- ret=%d\00"
@.str.2 = [33 x i8] c"cmd=%s ---- ret=%d (==0==good)\0A\00"
define void @add_nat(i8* %0) {
%2 = alloca [512 x i8]
%3 = getelementptr inbounds [512 x i8], [512 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 511, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i32 @system(i8* %3)
%6 = icmp eq i32 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %1
%8 = load i32, i32* @LOG_ALERT
%9 = call i32 @syslog(i32 %8, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %3, i32 %5)
br label %10
10: ; preds = %7, %1
%11 = call i32 @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 %5)
ret void
}