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

/* Variables and functions */
size_t atoi(char *);
int /*<<< orphan*/ free(char *);
scalar_t__ iptables_list_chain_with_line_numbers(char const *, char *, size_t,
                                                 size_t);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ *strstr(char *, char const *);
char *strtok_r(char *, char const *, char **);
size_t iptables_find_rule_in_chain_two_criteria(const char *chain_name,
                                                const char *criteria_one,
                                                const char *criteria_two,
                                                size_t use_xlock) {
  char *token;
  char *token_save;
  const char *s = "\n";
  if (chain_name && criteria_one && criteria_two) {
    size_t d_buf_sz = 524288;
    char *results = (char *)malloc(d_buf_sz + 1);
    *results = 0;
    size_t x;
    if (iptables_list_chain_with_line_numbers(chain_name, results, d_buf_sz,
                                              use_xlock) == 0) {
      token = strtok_r(results, s, &token_save);
      x = 0;
      while (token != NULL) {
        x = atoi(token);
        if (x > 0) {
          if ((strstr(token, criteria_one) != NULL) &&
              (strstr(token, criteria_two) != NULL)) {
            free(results);
            return x;
          }
        }
        token = strtok_r(NULL, s, &token_save);
      }
    }
    free(results);
  }
  return 0;
}


x86 assembly (clang, -O0):
<iptables_find_rule_in_chain_two_criteria>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
lea    0xe81(%rip),%rax
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1294 <iptables_find_rule_in_chain_two_criteria+0x134>
cmpq   $0x0,-0x18(%rbp)
je     1294 <iptables_find_rule_in_chain_two_criteria+0x134>
cmpq   $0x0,-0x20(%rbp)
je     1294 <iptables_find_rule_in_chain_two_criteria+0x134>
movq   $0x80000,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
add    $0x1,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    -0x50(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
mov    -0x50(%rbp),%rsi
mov    -0x48(%rbp),%rdx
mov    -0x28(%rbp),%rcx
call   1070 <iptables_list_chain_with_line_numbers@plt>
cmp    $0x0,%rax
jne    128b <iptables_find_rule_in_chain_two_criteria+0x12b>
mov    -0x50(%rbp),%rdi
mov    -0x40(%rbp),%rsi
lea    -0x38(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
movq   $0x0,-0x58(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1286 <iptables_find_rule_in_chain_two_criteria+0x126>
mov    -0x30(%rbp),%rdi
call   1060 <atoi@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jbe    126c <iptables_find_rule_in_chain_two_criteria+0x10c>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1267 <iptables_find_rule_in_chain_two_criteria+0x107>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1267 <iptables_find_rule_in_chain_two_criteria+0x107>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
mov    -0x58(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    129c <iptables_find_rule_in_chain_two_criteria+0x13c>
jmp    126c <iptables_find_rule_in_chain_two_criteria+0x10c>
mov    -0x40(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
lea    -0x38(%rbp),%rdx
call   1040 <strtok_r@plt>
mov    %rax,-0x30(%rbp)
jmp    1200 <iptables_find_rule_in_chain_two_criteria+0xa0>
jmp    128b <iptables_find_rule_in_chain_two_criteria+0x12b>
mov    -0x50(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iptables_find_rule_in_chain_two_criteria>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %r13d,%r13d
test   %rdi,%rdi
je     11c6 <iptables_find_rule_in_chain_two_criteria+0x66>
mov    %rsi,%r14
test   %rsi,%rsi
je     11c6 <iptables_find_rule_in_chain_two_criteria+0x66>
test   %rdx,%rdx
je     11c6 <iptables_find_rule_in_chain_two_criteria+0x66>
mov    %rcx,%r15
mov    %rdi,%rbp
mov    %rdx,%r12
mov    $0x80001,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
movb   $0x0,(%rax)
mov    $0x80000,%edx
mov    %rbp,%rdi
mov    %rax,%rsi
mov    %r15,%rcx
call   1070 <iptables_list_chain_with_line_numbers@plt>
test   %rax,%rax
mov    %rbx,0x8(%rsp)
je     11d8 <iptables_find_rule_in_chain_two_criteria+0x78>
xor    %r13d,%r13d
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe21(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %rbx,%rdi
call   1040 <strtok_r@plt>
test   %rax,%rax
je     11b9 <iptables_find_rule_in_chain_two_criteria+0x59>
mov    %rax,%r15
xor    %r13d,%r13d
lea    0x10(%rsp),%rbp
mov    %r12,%rbx
jmp    1229 <iptables_find_rule_in_chain_two_criteria+0xc9>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %edi,%edi
lea    0xde7(%rip),%rsi
mov    %rbp,%rdx
call   1040 <strtok_r@plt>
mov    %rax,%r15
test   %rax,%rax
je     11bc <iptables_find_rule_in_chain_two_criteria+0x5c>
mov    %r15,%rdi
call   1060 <atoi@plt>
test   %rax,%rax
je     1210 <iptables_find_rule_in_chain_two_criteria+0xb0>
mov    %rax,%r12
mov    %r15,%rdi
mov    %r14,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     1210 <iptables_find_rule_in_chain_two_criteria+0xb0>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     1210 <iptables_find_rule_in_chain_two_criteria+0xb0>
mov    %r12,%r13
jmp    11bc <iptables_find_rule_in_chain_two_criteria+0x5c>

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i64 @iptables_find_rule_in_chain_two_criteria(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i64
%14 = alloca i8*
%15 = alloca i64
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i64 %3, i64* %9
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %12
%16 = load i8*, i8** %6
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %70
18: ; preds = %4
%19 = load i8*, i8** %7
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %70
21: ; preds = %18
%22 = load i8*, i8** %8
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %70
24: ; preds = %21
store i64 524288, i64* %13
%25 = load i64, i64* %13
%26 = add i64 %25, 1
%27 = call i64 @malloc(i64 %26)
%28 = inttoptr i64 %27 to i8*
store i8* %28, i8** %14
%29 = load i8*, i8** %14
store i8 0, i8* %29
%30 = load i8*, i8** %6
%31 = load i8*, i8** %14
%32 = load i64, i64* %13
%33 = load i64, i64* %9
%34 = call i64 @iptables_list_chain_with_line_numbers(i8* %30, i8* %31, i64 %32, i64 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %36, label %67
36: ; preds = %24
%37 = load i8*, i8** %14
%38 = load i8*, i8** %12
%39 = call i8* @strtok_r(i8* %37, i8* %38, i8** %11)
store i8* %39, i8** %10
store i64 0, i64* %15
br label %40
40: ; preds = %63, %36
%41 = load i8*, i8** %10
%42 = icmp ne i8* %41, null
br i1 %42, label %43, label %66
43: ; preds = %40
%44 = load i8*, i8** %10
%45 = call i64 @atoi(i8* %44)
store i64 %45, i64* %15
%46 = load i64, i64* %15
%47 = icmp ugt i64 %46, 0
br i1 %47, label %48, label %63
48: ; preds = %43
%49 = load i8*, i8** %10
%50 = load i8*, i8** %7
%51 = call i32* @strstr(i8* %49, i8* %50)
%52 = icmp ne i32* %51, null
br i1 %52, label %53, label %62
53: ; preds = %48
%54 = load i8*, i8** %10
%55 = load i8*, i8** %8
%56 = call i32* @strstr(i8* %54, i8* %55)
%57 = icmp ne i32* %56, null
br i1 %57, label %58, label %62
58: ; preds = %53
%59 = load i8*, i8** %14
%60 = call i32 @free(i8* %59)
%61 = load i64, i64* %15
store i64 %61, i64* %5
br label %71
62: ; preds = %53, %48
br label %63
63: ; preds = %62, %43
%64 = load i8*, i8** %12
%65 = call i8* @strtok_r(i8* null, i8* %64, i8** %11)
store i8* %65, i8** %10
br label %40
66: ; preds = %40
br label %67
67: ; preds = %66, %24
%68 = load i8*, i8** %14
%69 = call i32 @free(i8* %68)
br label %70
70: ; preds = %67, %21, %18, %4
store i64 0, i64* %5
br label %71
71: ; preds = %70, %58
%72 = load i64, i64* %5
ret i64 %72
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i64 @iptables_find_rule_in_chain_two_criteria(i8* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
%7 = icmp ne i8* %0, null
%8 = icmp ne i8* %1, null
%9 = and i1 %7, %8
%10 = icmp ne i8* %2, null
%11 = and i1 %9, %10
br i1 %11, label %12, label %36
12: ; preds = %4
%13 = tail call i64 @malloc(i64 524289)
%14 = inttoptr i64 %13 to i8*
store i8 0, i8* %14
%15 = tail call i64 @iptables_list_chain_with_line_numbers(i8* %0, i8* %14, i64 524288, i64 %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %33
17: ; preds = %12
%18 = call i8* @strtok_r(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%19 = icmp eq i8* %18, null
br i1 %19, label %33, label %20
20: ; preds = %17, %30
%21 = phi i8* [ %31, %30 ], [ %18, %17 ]
%22 = call i64 @atoi(i8* %21)
%23 = icmp eq i64 %22, 0
br i1 %23, label %30, label %24
24: ; preds = %20
%25 = call i32* @strstr(i8* %21, i8* %1)
%26 = icmp eq i32* %25, null
br i1 %26, label %30, label %27
27: ; preds = %24
%28 = call i32* @strstr(i8* %21, i8* %2)
%29 = icmp eq i32* %28, null
br i1 %29, label %30, label %33
30: ; preds = %24, %27, %20
%31 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %5)
%32 = icmp eq i8* %31, null
br i1 %32, label %33, label %20
33: ; preds = %27, %30, %12, %17
%34 = phi i64 [ 0, %17 ], [ 0, %12 ], [ 0, %30 ], [ %22, %27 ]
%35 = call i32 @free(i8* %14)
br label %36
36: ; preds = %33, %4
%37 = phi i64 [ 0, %4 ], [ %34, %33 ]
ret i64 %37
}