#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 dummy;
};

/* Variables and functions */
int /*<<< orphan*/ SIOCSIFHWADDR;
int /*<<< orphan*/ SIOCSIFHWBROADCAST;
int /*<<< orphan*/ close(int);
int get_ctl_fd();
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ perror(char *);
int set_address(struct ifreq *ifr, int brd) {
  int s;
  s = get_ctl_fd();
  if (s < 0)
    return -1;
  if (ioctl(s, brd ? SIOCSIFHWBROADCAST : SIOCSIFHWADDR, ifr) < 0) {
    perror(brd ? "SIOCSIFHWBROADCAST" : "SIOCSIFHWADDR");
    close(s);
    return -1;
  }
  close(s);
  return 0;
}


x86 assembly (clang, -O0):
<set_address>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    $0x0,%al
call   1060 <get_ctl_fd@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jge    116f <set_address+0x2f>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f5 <set_address+0xb5>
mov    -0x18(%rbp),%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     1190 <set_address+0x50>
mov    0x2e52(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
jmp    119c <set_address+0x5c>
mov    0x2e51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x20(%rbp),%esi
mov    -0x10(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    11e6 <set_address+0xa6>
mov    -0x14(%rbp),%ecx
lea    0xe54(%rip),%rdi
lea    0xe3a(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdi
call   1050 <perror@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f5 <set_address+0xb5>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_address>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%r14d
mov    %rdi,%rbp
xor    %eax,%eax
call   1060 <get_ctl_fd@plt>
test   %eax,%eax
js     1165 <set_address+0x25>
mov    %eax,%ebx
test   %r14d,%r14d
jne    116c <set_address+0x2c>
mov    0x2e85(%rip),%rax
jmp    1173 <set_address+0x33>
mov    $0xffffffff,%ebp
jmp    118d <set_address+0x4d>
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %rbp,%rdx
call   1030 <ioctl@plt>
xor    %ebp,%ebp
test   %rax,%rax
js     1194 <set_address+0x54>
mov    %ebx,%edi
call   1040 <close@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
test   %r14d,%r14d
lea    0xe75(%rip),%rax
lea    0xe5b(%rip),%rdi
cmove  %rax,%rdi
call   1050 <perror@plt>
mov    $0xffffffff,%ebp
jmp    1186 <set_address+0x46>

LLVM IR (-O0):
%struct.ifreq = type { i32 }
@SIOCSIFHWBROADCAST = global i32 0
@SIOCSIFHWADDR = global i32 0
@.str = [19 x i8] c"SIOCSIFHWBROADCAST\00"
@.str.1 = [14 x i8] c"SIOCSIFHWADDR\00"
define i32 @set_address(%struct.ifreq* %0, i32 %1) {
%3 = alloca i32
%4 = alloca %struct.ifreq*
%5 = alloca i32
%6 = alloca i32
store %struct.ifreq* %0, %struct.ifreq** %4
store i32 %1, i32* %5
%7 = call i32 (...) @get_ctl_fd()
store i32 %7, i32* %6
%8 = load i32, i32* %6
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %35
11: ; preds = %2
%12 = load i32, i32* %6
%13 = load i32, i32* %5
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = load i32, i32* @SIOCSIFHWBROADCAST
br label %19
17: ; preds = %11
%18 = load i32, i32* @SIOCSIFHWADDR
br label %19
19: ; preds = %17, %15
%20 = phi i32 [ %16, %15 ], [ %18, %17 ]
%21 = load %struct.ifreq*, %struct.ifreq** %4
%22 = call i64 @ioctl(i32 %12, i32 %20, %struct.ifreq* %21)
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %32
24: ; preds = %19
%25 = load i32, i32* %5
%26 = icmp ne i32 %25, 0
%27 = zext i1 %26 to i64
%28 = select i1 %26, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0)
%29 = call i32 @perror(i8* %28)
%30 = load i32, i32* %6
%31 = call i32 @close(i32 %30)
store i32 -1, i32* %3
br label %35
32: ; preds = %19
%33 = load i32, i32* %6
%34 = call i32 @close(i32 %33)
store i32 0, i32* %3
br label %35
35: ; preds = %32, %24, %10
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
%struct.ifreq = type { i32 }
@SIOCSIFHWBROADCAST = global i32 0
@SIOCSIFHWADDR = global i32 0
@.str = [19 x i8] c"SIOCSIFHWBROADCAST\00"
@.str.1 = [14 x i8] c"SIOCSIFHWADDR\00"
define i32 @set_address(%struct.ifreq* %0, i32 %1) {
%3 = tail call i32 (...) @get_ctl_fd()
%4 = icmp slt i32 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %2
%6 = icmp eq i32 %1, 0
%7 = load i32, i32* @SIOCSIFHWBROADCAST
%8 = load i32, i32* @SIOCSIFHWADDR
%9 = select i1 %6, i32 %8, i32 %7
%10 = tail call i64 @ioctl(i32 %3, i32 %9, %struct.ifreq* %0)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %5
%13 = select i1 %6, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0)
%14 = tail call i32 @perror(i8* %13)
br label %15
15: ; preds = %5, %12
%16 = phi i32 [ -1, %12 ], [ 0, %5 ]
%17 = tail call i32 @close(i32 %3)
br label %18
18: ; preds = %15, %2
%19 = phi i32 [ -1, %2 ], [ %16, %15 ]
ret i32 %19
}