#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 *,
                            char *, char const *, char *);
size_t iptables_add_drop_rule_to_chain(const char *chain_name,
                                       const char *the_ip, size_t use_xlock) {
  char cmd[100];
  if (use_xlock)
    snprintf(cmd, 100, "%s %s %s %s %s %s", "iptables", "-w -A", chain_name,
             "-s", the_ip, "-j DROP");
  else
    snprintf(cmd, 100, "%s %s %s %s %s %s", "iptables", "-A", chain_name, "-s",
             the_ip, "-j DROP");
  FILE *in;
  extern FILE *popen();
  if (!(in = popen(cmd, "r"))) {
    return 1;
  }
  pclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<iptables_add_drop_rule_to_chain>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11a1 <iptables_add_drop_rule_to_chain+0x71>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%r9
mov    -0x18(%rbp),%r10
mov    $0x64,%esi
lea    0xe93(%rip),%rdx
lea    0xe9e(%rip),%rcx
lea    0xea0(%rip),%r8
lea    0xe9f(%rip),%r11
lea    0xe9b(%rip),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <snprintf@plt>
jmp    11eb <iptables_add_drop_rule_to_chain+0xbb>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%r9
mov    -0x18(%rbp),%r10
mov    $0x64,%esi
lea    0xe44(%rip),%rdx
lea    0xe4f(%rip),%rcx
lea    0xe54(%rip),%r8
lea    0xe50(%rip),%r11
lea    0xe4c(%rip),%rax
mov    %r11,(%rsp)
mov    %r10,0x8(%rsp)
mov    %rax,0x10(%rsp)
call   1040 <snprintf@plt>
lea    -0x90(%rbp),%rdi
lea    0xe33(%rip),%rsi
mov    $0x0,%al
call   1050 <popen@plt>
mov    %rax,-0x98(%rbp)
cmp    $0x0,%rax
jne    121e <iptables_add_drop_rule_to_chain+0xee>
movq   $0x1,-0x8(%rbp)
jmp    1232 <iptables_add_drop_rule_to_chain+0x102>
mov    -0x98(%rbp),%rdi
call   1030 <pclose@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iptables_add_drop_rule_to_chain>:
push   %rbx
sub    $0x70,%rsp
mov    %rsi,%rax
mov    %rdi,%r9
test   %rdx,%rdx
lea    0xed9(%rip),%rcx
lea    0xecf(%rip),%r8
cmove  %rcx,%r8
sub    $0x8,%rsp
lea    0xec9(%rip),%r10
lea    0xebf(%rip),%r11
lea    0xe97(%rip),%rdx
lea    0xea2(%rip),%rcx
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
push   %r10
push   %rax
push   %r11
call   1040 <snprintf@plt>
add    $0x20,%rsp
lea    0xe9a(%rip),%rsi
mov    %rbx,%rdi
xor    %eax,%eax
call   1050 <popen@plt>
test   %rax,%rax
je     11ad <iptables_add_drop_rule_to_chain+0x7d>
mov    %rax,%rdi
call   1030 <pclose@plt>
xor    %eax,%eax
jmp    11b2 <iptables_add_drop_rule_to_chain+0x82>
mov    $0x1,%eax
add    $0x70,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [18 x i8] c"%s %s %s %s %s %s\00"
@.str.1 = [9 x i8] c"iptables\00"
@.str.2 = [6 x i8] c"-w -A\00"
@.str.3 = [3 x i8] c"-s\00"
@.str.4 = [8 x i8] c"-j DROP\00"
@.str.5 = [3 x i8] c"-A\00"
@.str.6 = [2 x i8] c"r\00"
define i64 @iptables_add_drop_rule_to_chain(i8* %0, i8* %1, i64 %2) {
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i64
%8 = alloca [100 x i8]
%9 = alloca i32*
store i8* %0, i8** %5
store i8* %1, i8** %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 i8*, i8** %6
%16 = call i32 @snprintf(i8* %13, i32 100, i8* getelementptr inbounds ([18 x i8], [18 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, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, 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 i8*, i8** %6
%21 = call i32 @snprintf(i8* %18, i32 100, i8* getelementptr inbounds ([18 x i8], [18 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.5, i64 0, i64 0), i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, 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.6, 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 = [18 x i8] c"%s %s %s %s %s %s\00"
@.str.1 = [9 x i8] c"iptables\00"
@.str.2 = [6 x i8] c"-w -A\00"
@.str.3 = [3 x i8] c"-s\00"
@.str.4 = [8 x i8] c"-j DROP\00"
@.str.5 = [3 x i8] c"-A\00"
@.str.6 = [2 x i8] c"r\00"
define i64 @iptables_add_drop_rule_to_chain(i8* %0, i8* %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.5, 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 ([18 x i8], [18 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, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, 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.6, 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
}