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

/* Variables and functions */
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ iptables_do_command(char *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ safe_asprintf(char **, char *, char const *, char const *,
                                 ...);
int sscanf(char *, char *, char *);
char *strdup(char const *);
scalar_t__ strstr(char *, char *);
int iptables_fw_destroy_mention(const char *table, const char *chain,
                                const char *mention) {
  FILE *p = NULL;
  char *command = NULL;
  char *command2 = NULL;
  char line[4096];
  char rulenum[10];
  char *victim = strdup(mention);
  int deleted = 0;
  safe_asprintf(&command, "iptables -t %s -L %s -n --line-numbers -v", table,
                chain);
  if ((p = popen(command, "r"))) {
    while (!feof(p) && fgetc(p) != '\n')
      ;
    while (!feof(p) && fgetc(p) != '\n')
      ;
    while (fgets(line, sizeof(line), p)) {
      if (strstr(line, victim)) {
        if (sscanf(line, "%9[0-9]", rulenum) == 1) {
          do {
            printf("Deleting rule %s from %s.%s because it mentions %s",
                   rulenum, table, chain, victim);
            printf("\n");
          } while (0);
          safe_asprintf(&command2, "-t %s -D %s %s", table, chain, rulenum);
          iptables_do_command(command2);
          free(command2);
          deleted = 1;
          break;
        }
      }
    }
    pclose(p);
  }
  free(command);
  free(victim);
  if (deleted) {
    iptables_fw_destroy_mention(table, chain, mention);
  }
  return (deleted);
}


x86 assembly (clang, -O0):
<iptables_fw_destroy_mention>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1050,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   10e0 <strdup@plt>
mov    %rax,-0x1048(%rbp)
movl   $0x0,-0x104c(%rbp)
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x28(%rbp),%rdi
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   10d0 <safe_asprintf@plt>
mov    -0x28(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   10c0 <popen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     13e3 <iptables_fw_destroy_mention+0x213>
jmp    1256 <iptables_fw_destroy_mention+0x86>
mov    -0x20(%rbp),%rdi
call   1090 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x104d(%rbp)
jne    128a <iptables_fw_destroy_mention+0xba>
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x104d(%rbp)
mov    -0x104d(%rbp),%al
test   $0x1,%al
jne    129d <iptables_fw_destroy_mention+0xcd>
jmp    12a2 <iptables_fw_destroy_mention+0xd2>
jmp    1256 <iptables_fw_destroy_mention+0x86>
jmp    12a7 <iptables_fw_destroy_mention+0xd7>
mov    -0x20(%rbp),%rdi
call   1090 <feof@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x104e(%rbp)
jne    12db <iptables_fw_destroy_mention+0x10b>
mov    -0x20(%rbp),%rdi
call   1070 <fgetc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0x104e(%rbp)
mov    -0x104e(%rbp),%al
test   $0x1,%al
jne    12ee <iptables_fw_destroy_mention+0x11e>
jmp    12f3 <iptables_fw_destroy_mention+0x123>
jmp    12a7 <iptables_fw_destroy_mention+0xd7>
jmp    12f8 <iptables_fw_destroy_mention+0x128>
lea    -0x1030(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1000,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     13da <iptables_fw_destroy_mention+0x20a>
lea    -0x1030(%rbp),%rdi
mov    -0x1048(%rbp),%rsi
call   10f0 <strstr@plt>
cmp    $0x0,%rax
je     13d5 <iptables_fw_destroy_mention+0x205>
lea    -0x1030(%rbp),%rdi
lea    -0x103a(%rbp),%rdx
lea    0xce3(%rip),%rsi
call   10a0 <sscanf@plt>
cmp    $0x1,%eax
jne    13d0 <iptables_fw_destroy_mention+0x200>
jmp    135c <iptables_fw_destroy_mention+0x18c>
lea    -0x103a(%rbp),%rsi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
mov    -0x1048(%rbp),%r8
lea    0xcbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xce0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rcx
lea    -0x103a(%rbp),%r8
lea    -0x30(%rbp),%rdi
lea    0xcc1(%rip),%rsi
mov    $0x0,%al
call   10d0 <safe_asprintf@plt>
mov    -0x30(%rbp),%rdi
call   10b0 <iptables_do_command@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x104c(%rbp)
jmp    13da <iptables_fw_destroy_mention+0x20a>
jmp    13d5 <iptables_fw_destroy_mention+0x205>
jmp    12f8 <iptables_fw_destroy_mention+0x128>
mov    -0x20(%rbp),%rdi
call   1060 <pclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1048(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x104c(%rbp)
je     1416 <iptables_fw_destroy_mention+0x246>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <iptables_fw_destroy_mention@plt>
mov    -0x104c(%rbp),%eax
add    $0x1050,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iptables_fw_destroy_mention>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1048,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r12
movq   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
mov    %rdx,%rdi
call   10f0 <strdup@plt>
mov    %rax,%r13
lea    0xde2(%rip),%rsi
xor    %ebp,%ebp
lea    0x10(%rsp),%rdi
mov    %r12,%rdx
mov    %r15,%rcx
xor    %eax,%eax
call   10e0 <safe_asprintf@plt>
mov    0x10(%rsp),%rdi
lea    0xdec(%rip),%rsi
call   10d0 <popen@plt>
test   %rax,%rax
je     1392 <iptables_fw_destroy_mention+0x1b2>
mov    %rax,%rbx
nop
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1270 <iptables_fw_destroy_mention+0x90>
mov    %rbx,%rdi
call   1080 <fgetc@plt>
cmp    $0xa,%al
jne    1250 <iptables_fw_destroy_mention+0x70>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   10a0 <feof@plt>
test   %eax,%eax
jne    1288 <iptables_fw_destroy_mention+0xa8>
mov    %rbx,%rdi
call   1080 <fgetc@plt>
cmp    $0xa,%al
jne    1270 <iptables_fw_destroy_mention+0x90>
lea    0x40(%rsp),%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
xor    %ebp,%ebp
test   %rax,%rax
je     138a <iptables_fw_destroy_mention+0x1aa>
mov    %r12,0x18(%rsp)
mov    %r15,0x20(%rsp)
mov    %r14,0x28(%rsp)
lea    0x40(%rsp),%r14
lea    0xd6c(%rip),%r15
lea    0x36(%rsp),%r12
jmp    12e9 <iptables_fw_destroy_mention+0x109>
nopw   0x0(%rax,%rax,1)
mov    %r14,%rdi
mov    $0x1000,%esi
mov    %rbx,%rdx
call   1090 <fgets@plt>
test   %rax,%rax
je     137b <iptables_fw_destroy_mention+0x19b>
mov    %r14,%rdi
mov    %r13,%rsi
call   1100 <strstr@plt>
test   %rax,%rax
je     12d0 <iptables_fw_destroy_mention+0xf0>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   10b0 <sscanf@plt>
cmp    $0x1,%eax
jne    12d0 <iptables_fw_destroy_mention+0xf0>
lea    0xd21(%rip),%rdi
lea    0x36(%rsp),%rbp
mov    %rbp,%rsi
mov    0x18(%rsp),%r12
mov    %r12,%rdx
mov    0x20(%rsp),%r15
mov    %r15,%rcx
mov    %r13,%r8
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
lea    0xd21(%rip),%rsi
lea    0x8(%rsp),%rdi
mov    %r12,%rdx
mov    %r15,%rcx
mov    %rbp,%r8
xor    %eax,%eax
call   10e0 <safe_asprintf@plt>
mov    0x8(%rsp),%rdi
call   10c0 <iptables_do_command@plt>
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    $0x1,%ebp
mov    0x28(%rsp),%r14
jmp    138a <iptables_fw_destroy_mention+0x1aa>
mov    0x28(%rsp),%r14
mov    0x20(%rsp),%r15
mov    0x18(%rsp),%r12
mov    %rbx,%rdi
call   1070 <pclose@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
je     13b6 <iptables_fw_destroy_mention+0x1d6>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1050 <iptables_fw_destroy_mention@plt>
mov    %ebp,%eax
add    $0x1048,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [42 x i8] c"iptables -t %s -L %s -n --line-numbers -v\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%9[0-9]\00"
@.str.3 = [51 x i8] c"Deleting rule %s from %s.%s because it mentions %s\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [15 x i8] c"-t %s -D %s %s\00"
define i32 @iptables_fw_destroy_mention(i8* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca [4096 x i8]
%11 = alloca [10 x i8]
%12 = alloca i8*
%13 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32* null, i32** %7
store i8* null, i8** %8
store i8* null, i8** %9
%14 = load i8*, i8** %6
%15 = call i8* @strdup(i8* %14)
store i8* %15, i8** %12
store i32 0, i32* %13
%16 = load i8*, i8** %4
%17 = load i8*, i8** %5
%18 = call i32 (i8**, i8*, i8*, i8*, ...) @safe_asprintf(i8** %8, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %16, i8* %17)
%19 = load i8*, i8** %8
%20 = call i32* @popen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %86
22: ; preds = %3
br label %23
23: ; preds = %34, %22
%24 = load i32*, i32** %7
%25 = call i32 @feof(i32* %24)
%26 = icmp ne i32 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %23
%28 = load i32*, i32** %7
%29 = call signext i8 @fgetc(i32* %28)
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 10
br label %32
32: ; preds = %27, %23
%33 = phi i1 [ false, %23 ], [ %31, %27 ]
br i1 %33, label %34, label %35
34: ; preds = %32
br label %23
35: ; preds = %32
br label %36
36: ; preds = %47, %35
%37 = load i32*, i32** %7
%38 = call i32 @feof(i32* %37)
%39 = icmp ne i32 %38, 0
br i1 %39, label %45, label %40
40: ; preds = %36
%41 = load i32*, i32** %7
%42 = call signext i8 @fgetc(i32* %41)
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 10
br label %45
45: ; preds = %40, %36
%46 = phi i1 [ false, %36 ], [ %44, %40 ]
br i1 %46, label %47, label %48
47: ; preds = %45
br label %36
48: ; preds = %45
br label %49
49: ; preds = %82, %48
%50 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%51 = load i32*, i32** %7
%52 = call i64 @fgets(i8* %50, i32 4096, i32* %51)
%53 = icmp ne i64 %52, 0
br i1 %53, label %54, label %83
54: ; preds = %49
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%56 = load i8*, i8** %12
%57 = call i64 @strstr(i8* %55, i8* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %82
59: ; preds = %54
%60 = getelementptr inbounds [4096 x i8], [4096 x i8]* %10, i64 0, i64 0
%61 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%62 = call i32 @sscanf(i8* %60, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %61)
%63 = icmp eq i32 %62, 1
br i1 %63, label %64, label %81
64: ; preds = %59
br label %65
65: ; preds = %64
%66 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%67 = load i8*, i8** %4
%68 = load i8*, i8** %5
%69 = load i8*, i8** %12
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* %66, i8* %67, i8* %68, i8* %69)
%71 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %72
72: ; preds = %65
%73 = load i8*, i8** %4
%74 = load i8*, i8** %5
%75 = getelementptr inbounds [10 x i8], [10 x i8]* %11, i64 0, i64 0
%76 = call i32 (i8**, i8*, i8*, i8*, ...) @safe_asprintf(i8** %9, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %73, i8* %74, i8* %75)
%77 = load i8*, i8** %9
%78 = call i32 @iptables_do_command(i8* %77)
%79 = load i8*, i8** %9
%80 = call i32 @free(i8* %79)
store i32 1, i32* %13
br label %83
81: ; preds = %59
br label %82
82: ; preds = %81, %54
br label %49
83: ; preds = %72, %49
%84 = load i32*, i32** %7
%85 = call i32 @pclose(i32* %84)
br label %86
86: ; preds = %83, %3
%87 = load i8*, i8** %8
%88 = call i32 @free(i8* %87)
%89 = load i8*, i8** %12
%90 = call i32 @free(i8* %89)
%91 = load i32, i32* %13
%92 = icmp ne i32 %91, 0
br i1 %92, label %93, label %98
93: ; preds = %86
%94 = load i8*, i8** %4
%95 = load i8*, i8** %5
%96 = load i8*, i8** %6
%97 = call i32 @iptables_fw_destroy_mention(i8* %94, i8* %95, i8* %96)
br label %98
98: ; preds = %93, %86
%99 = load i32, i32* %13
ret i32 %99
}

LLVM IR (-O2):
@.str = [42 x i8] c"iptables -t %s -L %s -n --line-numbers -v\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [8 x i8] c"%9[0-9]\00"
@.str.3 = [51 x i8] c"Deleting rule %s from %s.%s because it mentions %s\00"
@.str.5 = [15 x i8] c"-t %s -D %s %s\00"
define i32 @iptables_fw_destroy_mention(i8* %0, i8* %1, i8* nocapture %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [4096 x i8]
%7 = alloca [10 x i8]
%8 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%9 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%10 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%11 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%12 = tail call i8* @strdup(i8* %2)
%13 = call i32 (i8**, i8*, i8*, i8*, ...) @safe_asprintf(i8** %4, i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1)
%14 = load i8*, i8** %4
%15 = call i32* @popen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %53, label %17
17: ; preds = %3, %20
%18 = call i32 @feof(i32* %15)
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %17
%21 = call signext i8 @fgetc(i32* %15)
%22 = icmp eq i8 %21, 10
br i1 %22, label %23, label %17
23: ; preds = %17, %20
br label %24
24: ; preds = %23, %27
%25 = call i32 @feof(i32* %15)
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %30
27: ; preds = %24
%28 = call signext i8 @fgetc(i32* %15)
%29 = icmp eq i8 %28, 10
br i1 %29, label %30, label %24
30: ; preds = %24, %27
%31 = call i64 @fgets(i8* %10, i32 4096, i32* %15)
%32 = icmp eq i64 %31, 0
br i1 %32, label %50, label %33
33: ; preds = %30, %47
%34 = call i64 @strstr(i8* %10, i8* %12)
%35 = icmp eq i64 %34, 0
br i1 %35, label %47, label %36
36: ; preds = %33
%37 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%38 = icmp eq i32 %37, 1
br i1 %38, label %39, label %47
39: ; preds = %36
%40 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.3, i64 0, i64 0), i8* %11, i8* %0, i8* %1, i8* %12)
%41 = call i32 @putchar(i32 10)
%42 = call i32 (i8**, i8*, i8*, i8*, ...) @safe_asprintf(i8** %5, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0), i8* %0, i8* %1, i8* %11)
%43 = load i8*, i8** %5
%44 = call i32 @iptables_do_command(i8* %43)
%45 = load i8*, i8** %5
%46 = call i32 @free(i8* %45)
br label %50
47: ; preds = %36, %33
%48 = call i64 @fgets(i8* %10, i32 4096, i32* %15)
%49 = icmp eq i64 %48, 0
br i1 %49, label %50, label %33
50: ; preds = %47, %30, %39
%51 = phi i32 [ 1, %39 ], [ 0, %30 ], [ 0, %47 ]
%52 = call i32 @pclose(i32* %15)
br label %53
53: ; preds = %50, %3
%54 = phi i32 [ %51, %50 ], [ 0, %3 ]
%55 = load i8*, i8** %4
%56 = call i32 @free(i8* %55)
%57 = call i32 @free(i8* %12)
%58 = icmp eq i32 %54, 0
br i1 %58, label %61, label %59
59: ; preds = %53
%60 = call i32 @iptables_fw_destroy_mention(i8* %0, i8* %1, i8* %2)
br label %61
61: ; preds = %59, %53
ret i32 %54
}