int main() {
  char lanip[sizeof("111.111.111.111")] = {0};
  char lanIfName[16] = {0};
  unsigned int ip = getIPByIfname("br-lan");
  if (0 == ip) {
    ip = getIPByIfname("br0");
    if (0 == ip) {
      printf("%s %d %s "
             "The lan ifname is error."
             "\n",
             "/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/"
             "2022-01-22/02-19-57/repos/hxw804781317/MT7620N/refs/heads/master/"
             "package/program/DIY_Firewall/src/ctrlFirewall/ctrlFirewall.c",
             21, __FUNCTION__);
      return -1;
    }
    strncpy(lanIfName, "br0", sizeof(lanIfName));
  }
  strncpy(lanIfName, "br-lan", sizeof(lanIfName));
  inet_ntoa_(ip, lanip);
  iptablesCommand("iptables -t nat -N "
                  "local_server");
  iptablesCommand("iptables -t nat -F "
                  "local_server");
  iptablesCommand("iptables -t nat -A "
                  "local_server"
                  " -p tcp -m multiport --dport 80,8080 -j DNAT --to %s:80",
                  lanip);
  iptablesCommand("iptables -t nat -A "
                  "local_server"
                  " -p tcp -m multiport --dport 443 -j DNAT --to %s:443",
                  lanip);
  iptablesCommand("iptables -t nat -I PREROUTING 1 -i %s -j "
                  "local_server",
                  lanIfName);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x20(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1060 <memset@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1070 <getIPByIfname@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
jne    1209 <main+0xa9>
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1070 <getIPByIfname@plt>
mov    %eax,-0x34(%rbp)
xor    %eax,%eax
cmp    -0x34(%rbp),%eax
jne    11f4 <main+0x94>
lea    0xe3d(%rip),%rdi
lea    0xe59(%rip),%rsi
mov    $0x15,%edx
lea    0xf0b(%rip),%rcx
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1285 <main+0x125>
lea    -0x30(%rbp),%rdi
lea    0xe08(%rip),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
lea    -0x30(%rbp),%rdi
lea    0xdec(%rip),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    -0x34(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x0,%al
call   1080 <inet_ntoa_@plt>
lea    0xebe(%rip),%rdi
mov    $0x0,%al
call   1040 <iptablesCommand@plt>
lea    0xed0(%rip),%rdi
mov    $0x0,%al
call   1040 <iptablesCommand@plt>
lea    -0x20(%rbp),%rsi
lea    0xede(%rip),%rdi
mov    $0x0,%al
call   1040 <iptablesCommand@plt>
lea    -0x20(%rbp),%rsi
lea    0xf23(%rip),%rdi
mov    $0x0,%al
call   1040 <iptablesCommand@plt>
lea    -0x30(%rbp),%rsi
lea    0xf65(%rip),%rdi
mov    $0x0,%al
call   1040 <iptablesCommand@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x28,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
lea    0xeab(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1050 <getIPByIfname@plt>
test   %eax,%eax
jne    1174 <main+0x34>
lea    0xe9e(%rip),%rdi
xor    %eax,%eax
call   1050 <getIPByIfname@plt>
test   %eax,%eax
je     11e8 <main+0xa8>
movups 0x1097(%rip),%xmm0
movaps %xmm0,(%rsp)
lea    0x10(%rsp),%rbx
mov    %eax,%edi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <inet_ntoa_@plt>
lea    0xf5a(%rip),%rdi
xor    %eax,%eax
call   1030 <iptablesCommand@plt>
lea    0xf6c(%rip),%rdi
xor    %eax,%eax
call   1030 <iptablesCommand@plt>
lea    0xf7e(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <iptablesCommand@plt>
lea    0xfc4(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <iptablesCommand@plt>
lea    0x1007(%rip),%rdi
mov    %rsp,%rsi
xor    %eax,%eax
call   1030 <iptablesCommand@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe1c(%rip),%rdi
lea    0xe38(%rip),%rsi
lea    0xeef(%rip),%rcx
mov    $0x15,%edx
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0xffffffff,%ebp
jmp    11df <main+0x9f>

LLVM IR (-O0):
@.str = [7 x i8] c"br-lan\00"
@.str.1 = [4 x i8] c"br0\00"
@.str.2 = [35 x i8] c"%s %d %s The lan ifname is error.\0A\00"
@.str.3 = [190 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hxw804781317/MT7620N/refs/heads/master/package/program/DIY_Firewall/src/ctrlFirewall/ctrlFirewall.c\00"
@__FUNCTION__.main = [5 x i8] c"main\00"
@.str.4 = [32 x i8] c"iptables -t nat -N local_server\00"
@.str.5 = [32 x i8] c"iptables -t nat -F local_server\00"
@.str.6 = [87 x i8] c"iptables -t nat -A local_server -p tcp -m multiport --dport 80,8080 -j DNAT --to %s:80\00"
@.str.7 = [84 x i8] c"iptables -t nat -A local_server -p tcp -m multiport --dport 443 -j DNAT --to %s:443\00"
@.str.8 = [54 x i8] c"iptables -t nat -I PREROUTING 1 -i %s -j local_server\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [16 x i8]
%3 = alloca [16 x i8]
%4 = alloca i32
store i32 0, i32* %1
%5 = bitcast [16 x i8]* %2 to i8*
%6 = bitcast [16 x i8]* %3 to i8*
%7 = call i32 (i8*, ...) bitcast (i32 (...)* @getIPByIfname to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp eq i32 0, %8
br i1 %9, label %10, label %19
10: ; preds = %0
%11 = call i32 (i8*, ...) bitcast (i32 (...)* @getIPByIfname to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
store i32 %11, i32* %4
%12 = load i32, i32* %4
%13 = icmp eq i32 0, %12
br i1 %13, label %14, label %16
14: ; preds = %10
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([190 x i8], [190 x i8]* @.str.3, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__FUNCTION__.main, i64 0, i64 0))
store i32 -1, i32* %1
br label %33
16: ; preds = %10
%17 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%18 = call i8* @strncpy(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i64 16)
br label %19
19: ; preds = %16, %0
%20 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%21 = call i8* @strncpy(i8* %20, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i64 16)
%22 = load i32, i32* %4
%23 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%24 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @inet_ntoa_ to i32 (i32, i8*, ...)*)(i32 %22, i8* %23)
%25 = call i32 (i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, ...)*)(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 (i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, ...)*)(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%28 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.6, i64 0, i64 0), i8* %27)
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%30 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.7, i64 0, i64 0), i8* %29)
%31 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%32 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i8* %31)
store i32 0, i32* %1
br label %33
33: ; preds = %19, %14
%34 = load i32, i32* %1
ret i32 %34
}

LLVM IR (-O2):
@.str = [7 x i8] c"br-lan\00"
@.str.1 = [4 x i8] c"br0\00"
@.str.2 = [35 x i8] c"%s %d %s The lan ifname is error.\0A\00"
@.str.3 = [190 x i8] c"/scratch/repos/new/home/jordi_armengol_estape/c-scraper/outputs/2022-01-22/02-19-57/repos/hxw804781317/MT7620N/refs/heads/master/package/program/DIY_Firewall/src/ctrlFirewall/ctrlFirewall.c\00"
@__FUNCTION__.main = [5 x i8] c"main\00"
@.str.4 = [32 x i8] c"iptables -t nat -N local_server\00"
@.str.5 = [32 x i8] c"iptables -t nat -F local_server\00"
@.str.6 = [87 x i8] c"iptables -t nat -A local_server -p tcp -m multiport --dport 80,8080 -j DNAT --to %s:80\00"
@.str.7 = [84 x i8] c"iptables -t nat -A local_server -p tcp -m multiport --dport 443 -j DNAT --to %s:443\00"
@.str.8 = [54 x i8] c"iptables -t nat -I PREROUTING 1 -i %s -j local_server\00"
@str = [17 x i8] c"br-lan\00\00\00\00\00\00\00\00\00\00\00"
define i32 @main() {
%1 = alloca [16 x i8]
%2 = alloca [16 x i8]
%3 = getelementptr inbounds [16 x i8], [16 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %2, i64 0, i64 0
%5 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getIPByIfname to i32 (i8*, ...)*)(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = tail call i32 (i8*, ...) bitcast (i32 (...)* @getIPByIfname to i32 (i8*, ...)*)(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %12
10: ; preds = %7
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([190 x i8], [190 x i8]* @.str.3, i64 0, i64 0), i32 21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @__FUNCTION__.main, i64 0, i64 0))
br label %20
12: ; preds = %7, %0
%13 = phi i32 [ %5, %0 ], [ %8, %7 ]
%14 = call i32 (i32, i8*, ...) bitcast (i32 (...)* @inet_ntoa_ to i32 (i32, i8*, ...)*)(i32 %13, i8* %3)
%15 = call i32 (i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, ...)*)(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.4, i64 0, i64 0))
%16 = call i32 (i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, ...)*)(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([87 x i8], [87 x i8]* @.str.6, i64 0, i64 0), i8* %3)
%18 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([84 x i8], [84 x i8]* @.str.7, i64 0, i64 0), i8* %3)
%19 = call i32 (i8*, i8*, ...) bitcast (i32 (...)* @iptablesCommand to i32 (i8*, i8*, ...)*)(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.8, i64 0, i64 0), i8* %4)
br label %20
20: ; preds = %12, %10
%21 = phi i32 [ -1, %10 ], [ 0, %12 ]
ret i32 %21
}