#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 atoi(int /*<<< orphan*/);
int /*<<< orphan*/ nvram_safe_get(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
scalar_t__ vap_already_in_bridge(int, int, int);
int wait_for_bridge_setup(int radio, int mode) {
  int max_wait = 20;
  int vap_num = 0;
  int i = 0;
  if (0 == mode) {
    vap_num = atoi(nvram_safe_get("wlv_rule_num"));
  }
  while (max_wait > 0) {
    if (0 == mode) {
      for (; i < vap_num; i++) {
        if (vap_already_in_bridge(radio, i, mode)) {
          printf("VAP has been added into bridge successfully\n");
          continue;
        } else {
          printf("VAP has not been added into bridge\n");
          break;
        }
      }
      if (i == vap_num) {
        printf("All the VAPs have been added into bridge successfully\n");
        break;
      }
    } else {
      if (vap_already_in_bridge(radio, 0, mode)) {
        printf("VAP has been added into bridge successfully\n");
        break;
      } else {
        printf("VAP has not been added into bridge\n");
        break;
      }
    }
    sleep(2);
    max_wait = max_wait - 2;
  }
  if (max_wait <= 0) {
    return -1;
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<wait_for_bridge_setup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x14,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    1194 <wait_for_bridge_setup+0x44>
lea    0xe7b(%rip),%rdi
call   1050 <nvram_safe_get@plt>
mov    %eax,%edi
call   1060 <atoi@plt>
mov    %eax,-0x14(%rbp)
jmp    1199 <wait_for_bridge_setup+0x49>
cmpl   $0x0,-0x10(%rbp)
jle    127a <wait_for_bridge_setup+0x12a>
xor    %eax,%eax
cmp    -0xc(%rbp),%eax
jne    1229 <wait_for_bridge_setup+0xd9>
jmp    11b3 <wait_for_bridge_setup+0x63>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1207 <wait_for_bridge_setup+0xb7>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <vap_already_in_bridge@plt>
cmp    $0x0,%rax
je     11e8 <wait_for_bridge_setup+0x98>
lea    0xe2f(%rip),%rdi
call   1040 <printf@plt>
jmp    11f9 <wait_for_bridge_setup+0xa9>
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
jmp    1207 <wait_for_bridge_setup+0xb7>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11b3 <wait_for_bridge_setup+0x63>
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jne    1224 <wait_for_bridge_setup+0xd4>
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
jmp    127a <wait_for_bridge_setup+0x12a>
jmp    1262 <wait_for_bridge_setup+0x112>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1030 <vap_already_in_bridge@plt>
cmp    $0x0,%rax
je     1251 <wait_for_bridge_setup+0x101>
lea    0xdc6(%rip),%rdi
call   1040 <printf@plt>
jmp    127a <wait_for_bridge_setup+0x12a>
lea    0xde2(%rip),%rdi
call   1040 <printf@plt>
jmp    127a <wait_for_bridge_setup+0x12a>
mov    $0x2,%edi
call   1070 <sleep@plt>
mov    -0x10(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x10(%rbp)
jmp    1199 <wait_for_bridge_setup+0x49>
cmpl   $0x0,-0x10(%rbp)
jg     1290 <wait_for_bridge_setup+0x140>
movl   $0xffffffff,-0x4(%rbp)
jmp    1297 <wait_for_bridge_setup+0x147>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wait_for_bridge_setup>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r12d
xor    %ebx,%ebx
mov    $0x0,%r13d
test   %esi,%esi
jne    1183 <wait_for_bridge_setup+0x33>
lea    0xe8c(%rip),%rdi
call   1050 <nvram_safe_get@plt>
mov    %eax,%edi
call   1060 <atoi@plt>
mov    %eax,%r13d
mov    $0x14,%r15d
lea    0xed6(%rip),%rbp
test   %r14d,%r14d
jne    1222 <wait_for_bridge_setup+0xd2>
cmp    %r13d,%ebx
jge    11dc <wait_for_bridge_setup+0x8c>
xchg   %ax,%ax
mov    %r12d,%edi
mov    %ebx,%esi
xor    %edx,%edx
call   1030 <vap_already_in_bridge@plt>
test   %rax,%rax
je     11d0 <wait_for_bridge_setup+0x80>
mov    %rbp,%rdi
call   1040 <puts@plt>
add    $0x1,%ebx
cmp    %ebx,%r13d
jne    11a0 <wait_for_bridge_setup+0x50>
jmp    11fd <wait_for_bridge_setup+0xad>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
lea    0xe6c(%rip),%rdi
call   1040 <puts@plt>
cmp    %r13d,%ebx
je     11fd <wait_for_bridge_setup+0xad>
mov    $0x2,%edi
call   1070 <sleep@plt>
lea    -0x2(%r15),%eax
cmp    $0x2,%r15d
mov    %eax,%r15d
ja     1190 <wait_for_bridge_setup+0x40>
xor    %r15d,%r15d
jmp    1209 <wait_for_bridge_setup+0xb9>
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
test   %r15d,%r15d
setle  %al
neg    %eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %r12d,%edi
xor    %esi,%esi
mov    %r14d,%edx
call   1030 <vap_already_in_bridge@plt>
test   %rax,%rax
lea    0xe0a(%rip),%rax
cmove  %rax,%rbp
mov    $0x14,%r15d
mov    %rbp,%rdi
jmp    1204 <wait_for_bridge_setup+0xb4>

LLVM IR (-O0):
@.str = [13 x i8] c"wlv_rule_num\00"
@.str.1 = [45 x i8] c"VAP has been added into bridge successfully\0A\00"
@.str.2 = [36 x i8] c"VAP has not been added into bridge\0A\00"
@.str.3 = [55 x i8] c"All the VAPs have been added into bridge successfully\0A\00"
define i32 @wait_for_bridge_setup(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 20, i32* %6
store i32 0, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %5
%10 = icmp eq i32 0, %9
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = call i32 @nvram_safe_get(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @atoi(i32 %12)
store i32 %13, i32* %7
br label %14
14: ; preds = %11, %2
br label %15
15: ; preds = %55, %14
%16 = load i32, i32* %6
%17 = icmp sgt i32 %16, 0
br i1 %17, label %18, label %59
18: ; preds = %15
%19 = load i32, i32* %5
%20 = icmp eq i32 0, %19
br i1 %20, label %21, label %46
21: ; preds = %18
br label %22
22: ; preds = %36, %21
%23 = load i32, i32* %8
%24 = load i32, i32* %7
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = load i32, i32* %4
%28 = load i32, i32* %8
%29 = load i32, i32* %5
%30 = call i64 @vap_already_in_bridge(i32 %27, i32 %28, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %26
%33 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %36
34: ; preds = %26
%35 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %39
36: ; preds = %32
%37 = load i32, i32* %8
%38 = add nsw i32 %37, 1
store i32 %38, i32* %8
br label %22
39: ; preds = %34, %22
%40 = load i32, i32* %8
%41 = load i32, i32* %7
%42 = icmp eq i32 %40, %41
br i1 %42, label %43, label %45
43: ; preds = %39
%44 = call i32 @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.3, i64 0, i64 0))
br label %59
45: ; preds = %39
br label %55
46: ; preds = %18
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = call i64 @vap_already_in_bridge(i32 %47, i32 0, i32 %48)
%50 = icmp ne i64 %49, 0
br i1 %50, label %51, label %53
51: ; preds = %46
%52 = call i32 @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.1, i64 0, i64 0))
br label %59
53: ; preds = %46
%54 = call i32 @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0))
br label %59
55: ; preds = %45
%56 = call i32 @sleep(i32 2)
%57 = load i32, i32* %6
%58 = sub nsw i32 %57, 2
store i32 %58, i32* %6
br label %15
59: ; preds = %53, %51, %43, %15
%60 = load i32, i32* %6
%61 = icmp sle i32 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %59
store i32 -1, i32* %3
br label %64
63: ; preds = %59
store i32 0, i32* %3
br label %64
64: ; preds = %63, %62
%65 = load i32, i32* %3
ret i32 %65
}

LLVM IR (-O2):
@.str = [13 x i8] c"wlv_rule_num\00"
@str.5 = [54 x i8] c"All the VAPs have been added into bridge successfully\00"
@str.6 = [35 x i8] c"VAP has not been added into bridge\00"
@str.7 = [44 x i8] c"VAP has been added into bridge successfully\00"
define i32 @wait_for_bridge_setup(i32 %0, i32 %1) {
%3 = icmp eq i32 %1, 0
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = tail call i32 @nvram_safe_get(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @atoi(i32 %5)
br label %7
7: ; preds = %4, %2
%8 = phi i32 [ %6, %4 ], [ 0, %2 ]
br label %9
9: ; preds = %7, %31
%10 = phi i32 [ 0, %7 ], [ %25, %31 ]
%11 = phi i32 [ 20, %7 ], [ %33, %31 ]
br i1 %3, label %12, label %27
12: ; preds = %9
%13 = icmp slt i32 %10, %8
br i1 %13, label %14, label %24
14: ; preds = %12, %18
%15 = phi i32 [ %20, %18 ], [ %10, %12 ]
%16 = tail call i64 @vap_already_in_bridge(i32 %0, i32 %15, i32 0)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([44 x i8], [44 x i8]* @str.7, i64 0, i64 0))
%20 = add nsw i32 %15, 1
%21 = icmp eq i32 %20, %8
br i1 %21, label %35, label %14
22: ; preds = %14
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0))
br label %24
24: ; preds = %12, %22
%25 = phi i32 [ %15, %22 ], [ %10, %12 ]
%26 = icmp eq i32 %25, %8
br i1 %26, label %35, label %31
27: ; preds = %9
%28 = tail call i64 @vap_already_in_bridge(i32 %0, i32 0, i32 %1)
%29 = icmp eq i64 %28, 0
%30 = select i1 %29, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @str.6, i64 0, i64 0), i8* getelementptr inbounds ([44 x i8], [44 x i8]* @str.7, i64 0, i64 0)
br label %35
31: ; preds = %24
%32 = tail call i32 @sleep(i32 2)
%33 = add nsw i32 %11, -2
%34 = icmp ugt i32 %11, 2
br i1 %34, label %9, label %39
35: ; preds = %24, %18, %27
%36 = phi i8* [ %30, %27 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @str.5, i64 0, i64 0), %18 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @str.5, i64 0, i64 0), %24 ]
%37 = phi i32 [ 20, %27 ], [ %11, %18 ], [ %11, %24 ]
%38 = tail call i32 @puts(i8* dereferenceable(1) %36)
br label %39
39: ; preds = %31, %35
%40 = phi i32 [ %37, %35 ], [ 0, %31 ]
%41 = icmp slt i32 %40, 1
%42 = sext i1 %41 to i32
ret i32 %42
}