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

/* Variables and functions */
int /*<<< orphan*/ 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(int /*<<< orphan*/, char const *,
                           int /*<<< orphan*/);
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_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    -0x24(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    0x2e22(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x4(%rbp),%edi
mov    $0x89a2,%esi
lea    -0x28(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0x0,%rax
jge    11ff <add_to_bridge+0xaf>
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%edi
lea    0xe3c(%rip),%rsi
call   1070 <err@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_to_bridge>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %edi,%r15d
cmpb   $0x0,(%rdx)
jne    1178 <add_to_bridge+0x28>
lea    0xe94(%rip),%rsi
mov    $0x1,%edi
xor    %eax,%eax
call   1040 <errx@plt>
mov    %r14,%rdi
call   1060 <if_nametoindex@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    119c <add_to_bridge+0x4c>
lea    0xe8c(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1040 <errx@plt>
mov    0x2e3d(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rsi
call   1030 <strncpy@plt>
mov    %ebp,(%rsp)
mov    %rsp,%rdx
mov    %r15d,%edi
mov    $0x89a2,%esi
call   1050 <ioctl@plt>
test   %rax,%rax
jns    11dc <add_to_bridge+0x8c>
lea    0xe6a(%rip),%rsi
mov    $0x1,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
call   1070 <err@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, 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 1
%24 = load i32, i32* %23
%25 = load i8*, i8** %6
%26 = load i32, i32* @IFNAMSIZ
%27 = call i32 @strncpy(i32 %24, i8* %25, i32 %26)
%28 = load i32, i32* %7
%29 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
store i32 %28, i32* %29
%30 = load i32, i32* %4
%31 = call i64 @ioctl(i32 %30, i32 35234, %struct.ifreq* %8)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %37
33: ; preds = %22
%34 = load i8*, i8** %5
%35 = load i8*, i8** %6
%36 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %34, i8* %35)
br label %37
37: ; preds = %33, %22
ret void
}

LLVM IR (-O2):
%struct.ifreq = type { i32, 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 %struct.ifreq
%5 = bitcast %struct.ifreq* %4 to i8*
%6 = load i8, i8* %2
%7 = icmp eq i8 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = tail call i32 (i32, i8*, ...) @errx(i32 1, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %3
%11 = tail call i32 @if_nametoindex(i8* %1)
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %10
%14 = 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 %15
15: ; preds = %13, %10
%16 = load i32, i32* @IFNAMSIZ
%17 = tail call i32 @strncpy(i32 undef, i8* %2, i32 %16)
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
store i32 %11, i32* %18
%19 = call i64 @ioctl(i32 %0, i32 35234, %struct.ifreq* %4)
%20 = icmp slt i64 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %15
%22 = call i32 @err(i32 1, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i8* %1, i8* %2)
br label %23
23: ; preds = %21, %15
ret void
}