#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*/ if_nametoindex(char const *);
int /*<<< orphan*/ stderr;
char *strerror(int);
int br_cmd_addif(int argc, char *const *argv) {
  const char *brname;
  int err;
  argc -= 2;
  brname = *++argv;
  while (argc-- > 0) {
    const char *ifname = *++argv;
    err = br_add_interface(brname, ifname);
    switch (err) {
    case 0:
      continue;
    case ENODEV:
      if (if_nametoindex(ifname) == 0)
        fprintf(stderr, "interface %s does not exist!\n", ifname);
      else
        fprintf(stderr, "bridge %s does not exist!\n", brname);
      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)
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    -0x8(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x8(%rbp)
cmp    $0x0,%eax
jle    12dd <br_cmd_addif+0x19d>
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     11f6 <br_cmd_addif+0xb6>
jmp    11bd <br_cmd_addif+0x7d>
mov    -0x2c(%rbp),%eax
sub    $0x80,%eax
je     11fb <br_cmd_addif+0xbb>
jmp    11d0 <br_cmd_addif+0x90>
mov    -0x2c(%rbp),%eax
sub    $0x81,%eax
je     1271 <br_cmd_addif+0x131>
jmp    11e3 <br_cmd_addif+0xa3>
mov    -0x2c(%rbp),%eax
sub    $0x82,%eax
je     124d <br_cmd_addif+0x10d>
jmp    1291 <br_cmd_addif+0x151>
jmp    116f <br_cmd_addif+0x2f>
mov    -0x28(%rbp),%rdi
call   1050 <if_nametoindex@plt>
cmp    $0x0,%eax
jne    122d <br_cmd_addif+0xed>
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xddf(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1248 <br_cmd_addif+0x108>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12d1 <br_cmd_addif+0x191>
mov    0x2d8c(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdd4(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12d1 <br_cmd_addif+0x191>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xdff(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    12d1 <br_cmd_addif+0x191>
mov    0x2d48(%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   1060 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
lea    0xe12(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12e4 <br_cmd_addif+0x1a4>
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   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
add    $0xfffffffe,%ebp
mov    0x8(%rsi),%r14
add    $0x10,%rbx
nopw   0x0(%rax,%rax,1)
test   %ebp,%ebp
jle    11b3 <br_cmd_addif+0x73>
add    $0xffffffff,%ebp
mov    (%rbx),%r15
mov    %r14,%rdi
mov    %r15,%rsi
call   1030 <br_add_interface@plt>
add    $0x8,%rbx
test   %eax,%eax
je     1160 <br_cmd_addif+0x20>
cmp    $0x82,%eax
je     11b7 <br_cmd_addif+0x77>
cmp    $0x81,%eax
je     11d6 <br_cmd_addif+0x96>
cmp    $0x80,%eax
jne    11e8 <br_cmd_addif+0xa8>
mov    %r15,%rdi
call   1050 <if_nametoindex@plt>
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%edi
test   %eax,%eax
je     1213 <br_cmd_addif+0xd3>
lea    0xe70(%rip),%rsi
mov    %r14,%rdx
jmp    121d <br_cmd_addif+0xdd>
xor    %eax,%eax
jmp    1229 <br_cmd_addif+0xe9>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
lea    0xe72(%rip),%rsi
mov    %r15,%rdx
mov    %r14,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1224 <br_cmd_addif+0xe4>
mov    0x2e03(%rip),%rax
mov    (%rax),%edi
lea    0xe9e(%rip),%rsi
jmp    121a <br_cmd_addif+0xda>
mov    0x2df1(%rip),%rcx
mov    (%rcx),%ebx
mov    %eax,%edi
call   1060 <strerror@plt>
lea    0xedd(%rip),%rsi
mov    %ebx,%edi
mov    %r15,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1224 <br_cmd_addif+0xe4>
lea    0xde6(%rip),%rsi
mov    %r15,%rdx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"interface %s does not exist!\0A\00"
@.str.1 = [27 x i8] c"bridge %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 i8*
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = sub nsw i32 %9, 2
store i32 %10, i32* %4
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i32 1
store i8** %12, i8*** %5
%13 = load i8*, i8** %12
store i8* %13, i8** %6
br label %14
14: ; preds = %26, %2
%15 = load i32, i32* %4
%16 = add nsw i32 %15, -1
store i32 %16, i32* %4
%17 = icmp sgt i32 %15, 0
br i1 %17, label %18, label %57
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i32 1
store i8** %20, i8*** %5
%21 = load i8*, i8** %20
store i8* %21, i8** %8
%22 = load i8*, i8** %6
%23 = load i8*, i8** %8
%24 = call i32 @br_add_interface(i8* %22, i8* %23)
store i32 %24, i32* %7
%25 = load i32, i32* %7
switch i32 %25, label %49 [
i32 0, label %26
i32 128, label %27
i32 130, label %40
i32 129, label %45
]
26: ; preds = %18
br label %14
27: ; preds = %18
%28 = load i8*, i8** %8
%29 = call i32 @if_nametoindex(i8* %28)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %35
31: ; preds = %27
%32 = load i32, i32* @stderr
%33 = load i8*, i8** %8
%34 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %39
35: ; preds = %27
%36 = load i32, i32* @stderr
%37 = load i8*, i8** %6
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %39
39: ; preds = %35, %31
br label %56
40: ; preds = %18
%41 = load i32, i32* @stderr
%42 = load i8*, i8** %8
%43 = load i8*, i8** %6
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i8* %42, i8* %43)
br label %56
45: ; preds = %18
%46 = load i32, i32* @stderr
%47 = load i8*, i8** %8
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %47)
br label %56
49: ; preds = %18
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %8
%52 = load i8*, i8** %6
%53 = load i32, i32* %7
%54 = call i8* @strerror(i32 %53)
%55 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %51, i8* %52, i8* %54)
br label %56
56: ; preds = %49, %45, %40, %39
store i32 1, i32* %3
br label %58
57: ; preds = %14
store i32 0, i32* %3
br label %58
58: ; preds = %57, %56
%59 = load i32, i32* %3
ret i32 %59
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"interface %s does not exist!\0A\00"
@.str.1 = [27 x i8] c"bridge %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
br label %6
6: ; preds = %10, %2
%7 = phi i8** [ %4, %2 ], [ %12, %10 ]
%8 = phi i32 [ %3, %2 ], [ %11, %10 ]
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %6
%11 = add nsw i32 %8, -1
%12 = getelementptr inbounds i8*, i8** %7, i64 1
%13 = load i8*, i8** %12
%14 = tail call i32 @br_add_interface(i8* %5, i8* %13)
switch i32 %14, label %29 [
i32 0, label %6
i32 128, label %15
i32 130, label %23
i32 129, label %26
]
15: ; preds = %10
%16 = tail call i32 @if_nametoindex(i8* %13)
%17 = icmp eq i32 %16, 0
%18 = load i32, i32* @stderr
br i1 %17, label %19, label %21
19: ; preds = %15
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %33
21: ; preds = %15
%22 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i8* %5)
br label %33
23: ; preds = %10
%24 = load i32, i32* @stderr
%25 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([75 x i8], [75 x i8]* @.str.2, i64 0, i64 0), i8* %13, i8* %5)
br label %33
26: ; preds = %10
%27 = load i32, i32* @stderr
%28 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.3, i64 0, i64 0), i8* %13)
br label %33
29: ; preds = %10
%30 = load i32, i32* @stderr
%31 = tail call i8* @strerror(i32 %14)
%32 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i8* %13, i8* %5, i8* %31)
br label %33
33: ; preds = %6, %19, %21, %29, %26, %23
%34 = phi i32 [ 1, %23 ], [ 1, %26 ], [ 1, %29 ], [ 1, %21 ], [ 1, %19 ], [ 0, %6 ]
ret i32 %34
}