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

/* Variables and functions */
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char const *,
                            size_t, char *, char *, char *);
size_t iptables_insert_nfqueue_rule_to_chain_at_index(const char *chain_name,
                                                      size_t ix_pos,
                                                      size_t use_xlock) {
  char cmd[100];
  if (use_xlock)
    snprintf(cmd, 100, "%s %s %s %zu %s %s %s", "iptables", "-w -I", chain_name,
             ix_pos, "-j", "NFQUEUE", "--queue-num 5");
  else
    snprintf(cmd, 100, "%s %s %s %zu %s %s %s", "iptables", "-I", chain_name,
             ix_pos, "-j", "NFQUEUE", "--queue-num 5");
  FILE *in;
  extern FILE *popen();
  if (!(in = popen(cmd, "r"))) {
    return 1;
  }
  pclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<iptables_insert_nfqueue_rule_to_chain_at_index>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
sub    $0xb8,%rsp
mov    %rdi,-0x18(%rbp)
mov    %rsi,-0x20(%rbp)
mov    %rdx,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11ae <iptables_insert_nfqueue_rule_to_chain_at_index+0x7e>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%r9
mov    -0x20(%rbp),%rbx
mov    $0x64,%esi
lea    0xe92(%rip),%rdx
lea    0xea1(%rip),%rcx
lea    0xea3(%rip),%r8
lea    0xea2(%rip),%r11
lea    0xe9e(%rip),%r10
lea    0xe9f(%rip),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1040 <snprintf@plt>
jmp    1204 <iptables_insert_nfqueue_rule_to_chain_at_index+0xd4>
lea    -0x90(%rbp),%rdi
mov    -0x18(%rbp),%r9
mov    -0x20(%rbp),%rbx
mov    $0x64,%esi
lea    0xe37(%rip),%rdx
lea    0xe46(%rip),%rcx
lea    0xe4b(%rip),%r8
lea    0xe47(%rip),%r11
lea    0xe43(%rip),%r10
lea    0xe44(%rip),%rax
mov    %rbx,(%rsp)
mov    %r11,0x8(%rsp)
mov    %r10,0x10(%rsp)
mov    %rax,0x18(%rsp)
call   1040 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe2c(%rip),%rsi
mov    $0x0,%al
call   1050 <popen@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    1237 <iptables_insert_nfqueue_rule_to_chain_at_index+0x107>
movq   $0x1,-0x10(%rbp)
jmp    124b <iptables_insert_nfqueue_rule_to_chain_at_index+0x11b>
mov    -0x98(%rbp),%rdi
call   1030 <pclose@plt>
movq   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%rax
add    $0xb8,%rsp
pop    %rbx
pop    %rbp
ret

x86 assembly (clang, -O2):
<iptables_insert_nfqueue_rule_to_chain_at_index>:
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%rax
mov    %rdi,%r9
test   %rdx,%rdx
lea    0xedb(%rip),%rcx
lea    0xed1(%rip),%r8
cmove  %rcx,%r8
lea    0xed7(%rip),%r10
lea    0xec8(%rip),%r11
lea    0xebe(%rip),%r14
lea    0xe92(%rip),%rdx
lea    0xea1(%rip),%rcx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
push   %r10
push   %r11
push   %r14
push   %rax
call   1040 <snprintf@plt>
add    $0x20,%rsp
lea    0xea7(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <popen@plt>
test   %rax,%rax
je     11b2 <iptables_insert_nfqueue_rule_to_chain_at_index+0x82>
mov    %rax,%rdi
call   1030 <pclose@plt>
xor    %eax,%eax
jmp    11b7 <iptables_insert_nfqueue_rule_to_chain_at_index+0x87>
mov    $0x1,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [22 x i8] c"%s %s %s %zu %s %s %s\00"
@.str.1 = [9 x i8] c"iptables\00"
@.str.2 = [6 x i8] c"-w -I\00"
@.str.3 = [3 x i8] c"-j\00"
@.str.4 = [8 x i8] c"NFQUEUE\00"
@.str.5 = [14 x i8] c"--queue-num 5\00"
@.str.6 = [3 x i8] c"-I\00"
@.str.7 = [2 x i8] c"r\00"
define i64 @iptables_insert_nfqueue_rule_to_chain_at_index(i8* %0, i64 %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
%8 = alloca [100 x i8]
%9 = alloca i32*
store i8* %0, i8** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
%10 = load i64, i64* %7
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%14 = load i8*, i8** %5
%15 = load i64, i64* %6
%16 = call i32 @snprintf(i8* %13, i32 100, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %14, i64 %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %22
17: ; preds = %3
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%19 = load i8*, i8** %5
%20 = load i64, i64* %6
%21 = call i32 @snprintf(i8* %18, i32 100, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %19, i64 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %22
22: ; preds = %17, %12
%23 = getelementptr inbounds [100 x i8], [100 x i8]* %8, i64 0, i64 0
%24 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %23, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %24, i32** %9
%25 = icmp ne i32* %24, null
br i1 %25, label %27, label %26
26: ; preds = %22
store i64 1, i64* %4
br label %30
27: ; preds = %22
%28 = load i32*, i32** %9
%29 = call i32 @pclose(i32* %28)
store i64 0, i64* %4
br label %30
30: ; preds = %27, %26
%31 = load i64, i64* %4
ret i64 %31
}

LLVM IR (-O2):
@.str = [22 x i8] c"%s %s %s %zu %s %s %s\00"
@.str.1 = [9 x i8] c"iptables\00"
@.str.2 = [6 x i8] c"-w -I\00"
@.str.3 = [3 x i8] c"-j\00"
@.str.4 = [8 x i8] c"NFQUEUE\00"
@.str.5 = [14 x i8] c"--queue-num 5\00"
@.str.6 = [3 x i8] c"-I\00"
@.str.7 = [2 x i8] c"r\00"
define i64 @iptables_insert_nfqueue_rule_to_chain_at_index(i8* %0, i64 %1, i64 %2) {
%4 = alloca [100 x i8]
%5 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%6 = icmp eq i64 %2, 0
%7 = select i1 %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0)
%8 = call i32 @snprintf(i8* %5, i32 100, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%9 = call i32* (i8*, i8*, ...) bitcast (i32* (...)* @popen to i32* (i8*, i8*, ...)*)(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %13, label %11
11: ; preds = %3
%12 = call i32 @pclose(i32* %9)
br label %13
13: ; preds = %3, %11
%14 = phi i64 [ 0, %11 ], [ 1, %3 ]
ret i64 %14
}