#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 */
#define EBUSY 130
#define ELOOP 129
#define ENODEV 128
int br_add_interface(char const *, char const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcmp(char *const, char *);
char *strerror(int);
int /*<<< orphan*/ wait_to_forward_state(char const *, char const *);
int br_cmd_addif(int argc, char *const *argv) {
  const char *brname;
  int err;
  int waitarg = 0;
  argc -= 2;
  brname = *++argv;
  if (!strcmp(*(argv + argc), "wait")) {
    waitarg = 1;
    argc -= 1;
  }
  while (argc-- > 0) {
    const char *ifname = *++argv;
    err = br_add_interface(brname, ifname);
    switch (err) {
    case 0:
      if (waitarg && wait_to_forward_state(brname, ifname))
        break;
      continue;
    case ENODEV:
      fprintf(stderr, "interface %s does not exist!\n", ifname);
      break;
    case EBUSY:
      fprintf(stderr,
              "device %s is already a member of a bridge; "
              "can't enslave it to bridge %s.\n",
              ifname, brname);
      break;
    case ELOOP:
      fprintf(stderr,
              "device %s is a bridge device itself; "
              "can't enslave a bridge device to a bridge device.\n",
              ifname);
      break;
    default:
      fprintf(stderr, "can't add %s to bridge %s: %s\n", ifname, brname,
              strerror(err));
    }
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<br_cmd_addif>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x2,%eax
mov    %eax,-0x8(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x8(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe67(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%eax
jne    11b7 <br_cmd_addif+0x67>
movl   $0x1,-0x20(%rbp)
mov    -0x8(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11bc <br_cmd_addif+0x6c>
mov    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    131d <br_cmd_addif+0x1cd>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <br_add_interface@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     1243 <br_cmd_addif+0xf3>
jmp    120a <br_cmd_addif+0xba>
mov    -0x2c(%rbp),%eax
sub    $0x80,%eax
je     126d <br_cmd_addif+0x11d>
jmp    121d <br_cmd_addif+0xcd>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
je     12b1 <br_cmd_addif+0x161>
jmp    1230 <br_cmd_addif+0xe0>
mov    -0x2c(%rbp),%eax
sub    $0x82,%eax
je     128d <br_cmd_addif+0x13d>
jmp    12d1 <br_cmd_addif+0x181>
cmpl   $0x0,-0x20(%rbp)
je     1268 <br_cmd_addif+0x118>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1060 <wait_to_forward_state@plt>
cmp    $0x0,%eax
je     1268 <br_cmd_addif+0x118>
jmp    1311 <br_cmd_addif+0x1c1>
jmp    11bc <br_cmd_addif+0x6c>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xd84(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1311 <br_cmd_addif+0x1c1>
mov    0x2d4c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xd7e(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1311 <br_cmd_addif+0x1c1>
mov    0x2d28(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xda9(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
jmp    1311 <br_cmd_addif+0x1c1>
mov    0x2d08(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x1c(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
lea    0xdbc(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1324 <br_cmd_addif+0x1d4>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<br_cmd_addif>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbp
mov    0x8(%rsi),%r14
movslq %edi,%rbx
mov    -0x8(%rsi,%rbx,8),%rdi
lea    0xe8f(%rip),%rsi
call   1040 <strcmp@plt>
mov    %eax,%r12d
cmp    $0x1,%eax
mov    $0xfffffffd,%eax
sbb    $0xffffffff,%eax
xor    %r15d,%r15d
add    %eax,%ebx
jle    126d <br_cmd_addif+0x11d>
add    $0x1,%ebx
add    $0x10,%rbp
jmp    11b0 <br_cmd_addif+0x60>
nopl   0x0(%rax,%rax,1)
add    $0xffffffff,%ebx
add    $0x8,%rbp
cmp    $0x1,%ebx
jbe    126d <br_cmd_addif+0x11d>
mov    0x0(%rbp),%r13
mov    %r14,%rdi
mov    %r13,%rsi
call   1030 <br_add_interface@plt>
test   %eax,%eax
jne    11dc <br_cmd_addif+0x8c>
test   %r12d,%r12d
jne    11a0 <br_cmd_addif+0x50>
mov    %r14,%rdi
mov    %r13,%rsi
call   1060 <wait_to_forward_state@plt>
test   %eax,%eax
je     11a0 <br_cmd_addif+0x50>
jmp    1267 <br_cmd_addif+0x117>
cmp    $0x80,%eax
je     1210 <br_cmd_addif+0xc0>
cmp    $0x81,%eax
je     1222 <br_cmd_addif+0xd2>
cmp    $0x82,%eax
jne    123e <br_cmd_addif+0xee>
mov    0x2de8(%rip),%rax
mov    (%rax),%edi
lea    0xe22(%rip),%rsi
mov    %r13,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1267 <br_cmd_addif+0x117>
mov    0x2dc9(%rip),%rax
mov    (%rax),%edi
lea    0xde5(%rip),%rsi
jmp    1232 <br_cmd_addif+0xe2>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xe3c(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1267 <br_cmd_addif+0x117>
mov    0x2d9b(%rip),%rcx
mov    (%rcx),%ebp
mov    %eax,%edi
call   1070 <strerror@plt>
lea    0xe71(%rip),%rsi
mov    %ebp,%edi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"wait\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"interface %s does not exist!\0A\00"
@.str.2 = [75 x i8] c"device %s is already a member of a bridge; can't enslave it to bridge %s.\0A\00"
@.str.3 = [88 x i8] c"device %s is a bridge device itself; can't enslave a bridge device to a bridge device.\0A\00"
@.str.4 = [31 x i8] c"can't add %s to bridge %s: %s\0A\00"
define i32 @br_cmd_addif(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
%10 = load i32, i32* %4
%11 = sub nsw i32 %10, 2
store i32 %11, i32* %4
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i32 1
store i8** %13, i8*** %5
%14 = load i8*, i8** %13
store i8* %14, i8** %6
%15 = load i8**, i8*** %5
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8*, i8** %15, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @strcmp(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%21 = icmp ne i32 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %2
store i32 1, i32* %8
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 1
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %2
br label %26
26: ; preds = %47, %25
%27 = load i32, i32* %4
%28 = add nsw i32 %27, -1
store i32 %28, i32* %4
%29 = icmp sgt i32 %27, 0
br i1 %29, label %30, label %69
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i32 1
store i8** %32, i8*** %5
%33 = load i8*, i8** %32
store i8* %33, i8** %9
%34 = load i8*, i8** %6
%35 = load i8*, i8** %9
%36 = call i32 @br_add_interface(i8* %34, i8* %35)
store i32 %36, i32* %7
%37 = load i32, i32* %7
switch i32 %37, label %61 [
i32 0, label %38
i32 128, label %48
i32 130, label %52
i32 129, label %57
]
38: ; preds = %30
%39 = load i32, i32* %8
%40 = icmp ne i32 %39, 0
br i1 %40, label %41, label %47
41: ; preds = %38
%42 = load i8*, i8** %6
%43 = load i8*, i8** %9
%44 = call i32 @wait_to_forward_state(i8* %42, i8* %43)
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %47
46: ; preds = %41
br label %68
47: ; preds = %41, %38
br label %26
48: ; preds = %30
%49 = load i32, i32* @stderr
%50 = load i8*, i8** %9
%51 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %50)
br label %68
52: ; preds = %30
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %9
%55 = load i8*, i8** %6
%56 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i8* %54, i8* %55)
br label %68
57: ; preds = %30
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %9
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %59)
br label %68
61: ; preds = %30
%62 = load i32, i32* @stderr
%63 = load i8*, i8** %9
%64 = load i8*, i8** %6
%65 = load i32, i32* %7
%66 = call i8* @strerror(i32 %65)
%67 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %62, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %63, i8* %64, i8* %66)
br label %68
68: ; preds = %61, %57, %52, %48, %46
store i32 1, i32* %3
br label %70
69: ; preds = %26
store i32 0, i32* %3
br label %70
70: ; preds = %69, %68
%71 = load i32, i32* %3
ret i32 %71
}

LLVM IR (-O2):
@.str = [5 x i8] c"wait\00"
@stderr = global i32 0
@.str.1 = [30 x i8] c"interface %s does not exist!\0A\00"
@.str.2 = [75 x i8] c"device %s is already a member of a bridge; can't enslave it to bridge %s.\0A\00"
@.str.3 = [88 x i8] c"device %s is a bridge device itself; can't enslave a bridge device to a bridge device.\0A\00"
@.str.4 = [31 x i8] c"can't add %s to bridge %s: %s\0A\00"
define i32 @br_cmd_addif(i32 %0, i8** nocapture %1) {
%3 = add nsw i32 %0, -2
%4 = getelementptr inbounds i8*, i8** %1, i64 1
%5 = load i8*, i8** %4
%6 = sext i32 %3 to i64
%7 = getelementptr inbounds i8*, i8** %4, i64 %6
%8 = load i8*, i8** %7
%9 = tail call i32 @strcmp(i8* dereferenceable(1) %8, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
%11 = add nsw i32 %0, -3
%12 = select i1 %10, i32 %11, i32 %3
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %40
14: ; preds = %2, %38
%15 = phi i32 [ %17, %38 ], [ %12, %2 ]
%16 = phi i8** [ %18, %38 ], [ %4, %2 ]
%17 = add nsw i32 %15, -1
%18 = getelementptr inbounds i8*, i8** %16, i64 1
%19 = load i8*, i8** %18
%20 = tail call i32 @br_add_interface(i8* %5, i8* %19)
switch i32 %20, label %34 [
i32 0, label %21
i32 128, label %25
i32 130, label %28
i32 129, label %31
]
21: ; preds = %14
br i1 %10, label %22, label %38
22: ; preds = %21
%23 = tail call i32 @wait_to_forward_state(i8* %5, i8* %19)
%24 = icmp eq i32 %23, 0
br i1 %24, label %38, label %40
25: ; preds = %14
%26 = load i32, i32* @stderr
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %40
28: ; preds = %14
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i8* %19, i8* %5)
br label %40
31: ; preds = %14
%32 = load i32, i32* @stderr
%33 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %19)
br label %40
34: ; preds = %14
%35 = load i32, i32* @stderr
%36 = tail call i8* @strerror(i32 %20)
%37 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %19, i8* %5, i8* %36)
br label %40
38: ; preds = %21, %22
%39 = icmp ugt i32 %15, 1
br i1 %39, label %14, label %40
40: ; preds = %38, %22, %2, %25, %28, %31, %34
%41 = phi i32 [ 1, %34 ], [ 1, %31 ], [ 1, %28 ], [ 1, %25 ], [ 0, %2 ], [ 0, %38 ], [ 1, %22 ]
ret i32 %41
}