#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 */
int /*<<< orphan*/ delete_pcp_rule_chains(char *, char *, char *);
int /*<<< orphan*/ flush_pcp_rule_chains(char *, char *, char *);
int /*<<< orphan*/ remove_jump_pcp_rule_chains(char *, char *, char *);
scalar_t__ snprintf(char *, int, char *, int);
bool remove_pcp_port_forwarding_chain(int index) {
  char chain_preroute[256] = {'\0'};
  char chain_postroute[256] = {'\0'};
  char chain_mangle[256] = {'\0'};
  if (snprintf(chain_preroute, 256, "PCP_NAT_PREROUTE_RULE_%d", index) <= 0 ||
      snprintf(chain_postroute, 256, "PCP_NAT_POSTROUTE_RULE_%d", index) <= 0 ||
      snprintf(chain_mangle, 256, "PCP_MANGLE_RULE_%d", index) <= 0) {
    return false;
  }
  if (!remove_jump_pcp_rule_chains(chain_preroute, chain_postroute,
                                   chain_mangle)) {
    return false;
  }
  if (!flush_pcp_rule_chains(chain_preroute, chain_postroute, chain_mangle)) {
    return false;
  }
  if (!delete_pcp_rule_chains(chain_preroute, chain_postroute, chain_mangle)) {
    return false;
  }
  return true;
}


x86 assembly (clang, -O0):
<remove_pcp_port_forwarding_chain>:
push   %rbp
mov    %rsp,%rbp
sub    $0x310,%rsp
mov    %edi,-0x8(%rbp)
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x210(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x310(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1060 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x100,%esi
lea    0xe53(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jle    1206 <remove_pcp_port_forwarding_chain+0xb6>
lea    -0x210(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x100,%esi
lea    0xe47(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jle    1206 <remove_pcp_port_forwarding_chain+0xb6>
lea    -0x310(%rbp),%rdi
mov    -0x8(%rbp),%ecx
mov    $0x100,%esi
lea    0xe3c(%rip),%rdx
call   1050 <snprintf@plt>
cmp    $0x0,%rax
jg     1212 <remove_pcp_port_forwarding_chain+0xc2>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <remove_pcp_port_forwarding_chain+0x156>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
lea    -0x310(%rbp),%rdx
call   1040 <remove_jump_pcp_rule_chains@plt>
cmp    $0x0,%eax
jne    1241 <remove_pcp_port_forwarding_chain+0xf1>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <remove_pcp_port_forwarding_chain+0x156>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
lea    -0x310(%rbp),%rdx
call   1030 <flush_pcp_rule_chains@plt>
cmp    $0x0,%eax
jne    1270 <remove_pcp_port_forwarding_chain+0x120>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <remove_pcp_port_forwarding_chain+0x156>
lea    -0x110(%rbp),%rdi
lea    -0x210(%rbp),%rsi
lea    -0x310(%rbp),%rdx
call   1070 <delete_pcp_rule_chains@plt>
cmp    $0x0,%eax
jne    129f <remove_pcp_port_forwarding_chain+0x14f>
movl   $0x0,-0x4(%rbp)
jmp    12a6 <remove_pcp_port_forwarding_chain+0x156>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x310,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<remove_pcp_port_forwarding_chain>:
push   %rbp
push   %rbx
sub    $0x308,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x2f0(%rsp)
movaps %xmm0,0x2e0(%rsp)
movaps %xmm0,0x2d0(%rsp)
movaps %xmm0,0x2c0(%rsp)
movaps %xmm0,0x2b0(%rsp)
movaps %xmm0,0x2a0(%rsp)
movaps %xmm0,0x290(%rsp)
movaps %xmm0,0x280(%rsp)
movaps %xmm0,0x270(%rsp)
movaps %xmm0,0x260(%rsp)
movaps %xmm0,0x250(%rsp)
movaps %xmm0,0x240(%rsp)
movaps %xmm0,0x230(%rsp)
movaps %xmm0,0x220(%rsp)
movaps %xmm0,0x210(%rsp)
movaps %xmm0,0x200(%rsp)
movaps %xmm0,0x1f0(%rsp)
movaps %xmm0,0x1e0(%rsp)
movaps %xmm0,0x1d0(%rsp)
movaps %xmm0,0x1c0(%rsp)
movaps %xmm0,0x1b0(%rsp)
movaps %xmm0,0x1a0(%rsp)
movaps %xmm0,0x190(%rsp)
movaps %xmm0,0x180(%rsp)
movaps %xmm0,0x170(%rsp)
movaps %xmm0,0x160(%rsp)
movaps %xmm0,0x150(%rsp)
movaps %xmm0,0x140(%rsp)
movaps %xmm0,0x130(%rsp)
movaps %xmm0,0x120(%rsp)
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
lea    0xd44(%rip),%rdx
lea    0x200(%rsp),%rdi
mov    $0x100,%esi
mov    %ebx,%ecx
call   1050 <snprintf@plt>
xor    %ebp,%ebp
test   %rax,%rax
jle    136e <remove_pcp_port_forwarding_chain+0x22e>
lea    0xd37(%rip),%rdx
lea    0x100(%rsp),%rdi
mov    $0x100,%esi
mov    %ebx,%ecx
call   1050 <snprintf@plt>
test   %rax,%rax
jle    136e <remove_pcp_port_forwarding_chain+0x22e>
lea    0xd31(%rip),%rdx
mov    %rsp,%rdi
mov    $0x100,%esi
mov    %ebx,%ecx
call   1050 <snprintf@plt>
test   %rax,%rax
jle    136e <remove_pcp_port_forwarding_chain+0x22e>
lea    0x200(%rsp),%rdi
lea    0x100(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <remove_jump_pcp_rule_chains@plt>
test   %eax,%eax
je     136e <remove_pcp_port_forwarding_chain+0x22e>
lea    0x200(%rsp),%rdi
lea    0x100(%rsp),%rsi
mov    %rsp,%rdx
call   1030 <flush_pcp_rule_chains@plt>
test   %eax,%eax
je     136e <remove_pcp_port_forwarding_chain+0x22e>
lea    0x200(%rsp),%rdi
lea    0x100(%rsp),%rsi
mov    %rsp,%rdx
call   1060 <delete_pcp_rule_chains@plt>
xor    %ebp,%ebp
test   %eax,%eax
setne  %bpl
mov    %ebp,%eax
add    $0x308,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"PCP_NAT_PREROUTE_RULE_%d\00"
@.str.1 = [26 x i8] c"PCP_NAT_POSTROUTE_RULE_%d\00"
@.str.2 = [19 x i8] c"PCP_MANGLE_RULE_%d\00"
define i32 @remove_pcp_port_forwarding_chain(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca [256 x i8]
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
store i32 %0, i32* %3
%7 = bitcast [256 x i8]* %4 to i8*
%8 = bitcast [256 x i8]* %5 to i8*
%9 = bitcast [256 x i8]* %6 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%11 = load i32, i32* %3
%12 = call i64 @snprintf(i8* %10, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = icmp sle i64 %12, 0
br i1 %13, label %24, label %14
14: ; preds = %1
%15 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%16 = load i32, i32* %3
%17 = call i64 @snprintf(i8* %15, i32 256, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp sle i64 %17, 0
br i1 %18, label %24, label %19
19: ; preds = %14
%20 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%21 = load i32, i32* %3
%22 = call i64 @snprintf(i8* %20, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = icmp sle i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %19, %14, %1
store i32 0, i32* %2
br label %47
25: ; preds = %19
%26 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%29 = call i32 @remove_jump_pcp_rule_chains(i8* %26, i8* %27, i8* %28)
%30 = icmp ne i32 %29, 0
br i1 %30, label %32, label %31
31: ; preds = %25
store i32 0, i32* %2
br label %47
32: ; preds = %25
%33 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%35 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%36 = call i32 @flush_pcp_rule_chains(i8* %33, i8* %34, i8* %35)
%37 = icmp ne i32 %36, 0
br i1 %37, label %39, label %38
38: ; preds = %32
store i32 0, i32* %2
br label %47
39: ; preds = %32
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%42 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%43 = call i32 @delete_pcp_rule_chains(i8* %40, i8* %41, i8* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %46, label %45
45: ; preds = %39
store i32 0, i32* %2
br label %47
46: ; preds = %39
store i32 1, i32* %2
br label %47
47: ; preds = %46, %45, %38, %31, %24
%48 = load i32, i32* %2
ret i32 %48
}

LLVM IR (-O2):
@.str = [25 x i8] c"PCP_NAT_PREROUTE_RULE_%d\00"
@.str.1 = [26 x i8] c"PCP_NAT_POSTROUTE_RULE_%d\00"
@.str.2 = [19 x i8] c"PCP_MANGLE_RULE_%d\00"
define i32 @remove_pcp_port_forwarding_chain(i32 %0) {
%2 = alloca [256 x i8]
%3 = alloca [256 x i8]
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%8 = call i64 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i32 %0)
%9 = icmp slt i64 %8, 1
br i1 %9, label %26, label %10
10: ; preds = %1
%11 = call i64 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.1, i64 0, i64 0), i32 %0)
%12 = icmp slt i64 %11, 1
br i1 %12, label %26, label %13
13: ; preds = %10
%14 = call i64 @snprintf(i8* %7, i32 256, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i32 %0)
%15 = icmp slt i64 %14, 1
br i1 %15, label %26, label %16
16: ; preds = %13
%17 = call i32 @remove_jump_pcp_rule_chains(i8* %5, i8* %6, i8* %7)
%18 = icmp eq i32 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %16
%20 = call i32 @flush_pcp_rule_chains(i8* %5, i8* %6, i8* %7)
%21 = icmp eq i32 %20, 0
br i1 %21, label %26, label %22
22: ; preds = %19
%23 = call i32 @delete_pcp_rule_chains(i8* %5, i8* %6, i8* %7)
%24 = icmp ne i32 %23, 0
%25 = zext i1 %24 to i32
br label %26
26: ; preds = %22, %19, %16, %1, %10, %13
%27 = phi i32 [ 0, %13 ], [ 0, %10 ], [ 0, %1 ], [ 0, %16 ], [ 0, %19 ], [ %25, %22 ]
ret i32 %27
}