#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 */
struct ifreq {
  char *ifr_name;
  int ifr_ifindex;
};

/* Variables and functions */
int IFNAMSIZ;
int /*<<< orphan*/ err(int, char *, char const *, char const *);
int /*<<< orphan*/ errx(int, char *, ...);
int if_nametoindex(char const *);
scalar_t__ ioctl(int, int, struct ifreq *);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void add_to_bridge(int fd, const char *if_name, const char *br_name) {
  int ifidx;
  struct ifreq ifr;
  if (!*br_name)
    errx(1, "must specify bridge name");
  ifidx = if_nametoindex(if_name);
  if (!ifidx)
    errx(1, "interface %s does not exist!", if_name);
  strncpy(ifr.ifr_name, br_name, IFNAMSIZ);
  ifr.ifr_name[IFNAMSIZ - 1] = '\0';
  ifr.ifr_ifindex = ifidx;
  if (ioctl(fd, 0x89a2, &ifr) < 0)
    err(1, "can't add %s to bridge %s", if_name, br_name);
}


x86 assembly (clang, -O0):
<add_to_bridge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1183 <add_to_bridge+0x33>
mov    $0x1,%edi
lea    0xe84(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    -0x10(%rbp),%rdi
call   1060 <if_nametoindex@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11b0 <add_to_bridge+0x60>
mov    -0x10(%rbp),%rdx
mov    $0x1,%edi
lea    0xe70(%rip),%rsi
mov    $0x0,%al
call   1040 <errx@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    0x2e21(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x30(%rbp),%rax
mov    0x2e0f(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x89a2,%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    1217 <add_to_bridge+0xc7>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%edi
lea    0xe24(%rip),%rsi
call   1070 <err@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_bridge>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
cmpb   $0x0,(%rdx)
jne    1152 <add_to_bridge+0x22>
lea    0xeba(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <errx@plt>
mov    %r14,%rdi
call   1050 <if_nametoindex@plt>
test   %eax,%eax
jne    1174 <add_to_bridge+0x44>
lea    0xeb4(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <errx@plt>
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rsi
call   1030 <strncpy@plt>

LLVM IR (-O0):
%struct.ifreq = type { i8*, i32 }
@.str = [25 x i8] c"must specify bridge name\00"
@.str.1 = [29 x i8] c"interface %s does not exist!\00"
@IFNAMSIZ = global i32 0
@.str.2 = [26 x i8] c"can't add %s to bridge %s\00"
define void @add_to_bridge(i32 %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca %struct.ifreq
store i32 %0, i32* %4
store i8* %1, i8** %5
store i8* %2, i8** %6
%9 = load i8*, i8** %6
%10 = load i8, i8* %9
%11 = icmp ne i8 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %3
%13 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %3
%15 = load i8*, i8** %5
%16 = call i32 @if_nametoindex(i8* %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = icmp ne i32 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %20)
br label %22
22: ; preds = %19, %14
%23 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%24 = load i8*, i8** %23
%25 = load i8*, i8** %6
%26 = load i32, i32* @IFNAMSIZ
%27 = call i32 @strncpy(i8* %24, i8* %25, i32 %26)
%28 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%29 = load i8*, i8** %28
%30 = load i32, i32* @IFNAMSIZ
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 0, i8* %33
%34 = load i32, i32* %7
%35 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
store i32 %34, i32* %35
%36 = load i32, i32* %4
%37 = call i64 @ioctl(i32 %36, i32 35234, %struct.ifreq* %8)
%38 = icmp slt i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %22
%40 = load i8*, i8** %5
%41 = load i8*, i8** %6
%42 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %40, i8* %41)
br label %43
43: ; preds = %39, %22
ret void
}

LLVM IR (-O2):
@.str = [25 x i8] c"must specify bridge name\00"
@.str.1 = [29 x i8] c"interface %s does not exist!\00"
@IFNAMSIZ = global i32 0
define void @add_to_bridge(i32 %0, i8* %1, i8* %2) {
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @if_nametoindex(i8* %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0), i8* %1)
br label %13
13: ; preds = %11, %8
%14 = load i32, i32* @IFNAMSIZ
%15 = tail call i32 @strncpy(i8* undef, i8* %2, i32 %14)
unreachable
}