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

/* Variables and functions */
int /*<<< orphan*/ IFNAMSIZ;
int /*<<< orphan*/ LOG_WARNING;
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
int /*<<< orphan*/ SOCK_STREAM;
int /*<<< orphan*/ close(int);
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int socket(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ strncpy(int /*<<< orphan*/, char *, int /*<<< orphan*/);
int /*<<< orphan*/ syslog(int /*<<< orphan*/, char *);
int modify_flags(char *dev, int set, int clear) {
  struct ifreq ifr;
  int sockfd;
  sockfd = socket(23, SOCK_STREAM, 0);
  if (sockfd < 0) {
    syslog(LOG_WARNING, "socket(AF_IRDA): %m");
    return (-1);
  }
  strncpy(ifr.ifr_name, dev, IFNAMSIZ);
  if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
    syslog(LOG_WARNING, "ioctl(SIOCGIFFLAGS): %m");
    close(sockfd);
    return -1;
  }
  ifr.ifr_flags |= set;
  ifr.ifr_flags &= ~clear;
  strncpy(ifr.ifr_name, dev, IFNAMSIZ);
  if (ioctl(sockfd, SIOCSIFFLAGS, &ifr) < 0) {
    syslog(LOG_WARNING, "ioctl(SIOCSIFFLAGS): %m");
    close(sockfd);
    return -1;
  }
  close(sockfd);
  return 0;
}


x86 assembly (clang, -O0):
<modify_flags>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %edx,-0x18(%rbp)
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
mov    $0x17,%edi
xor    %edx,%edx
call   1070 <socket@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11a5 <modify_flags+0x55>
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1060 <syslog@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1283 <modify_flags+0x133>
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2e15(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2e14(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1202 <modify_flags+0xb2>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
lea    0xe2b(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1283 <modify_flags+0x133>
mov    -0x14(%rbp),%eax
or     -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    0x2da3(%rip),%rax
mov    (%rax),%edx
call   1030 <strncpy@plt>
mov    -0x24(%rbp),%edi
mov    0x2dc2(%rip),%rax
mov    (%rax),%esi
lea    -0x20(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    1274 <modify_flags+0x124>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
call   1060 <syslog@plt>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1283 <modify_flags+0x133>
mov    -0x24(%rbp),%edi
call   1050 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<modify_flags>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%ebp
mov    %esi,%r15d
mov    %rdi,%r14
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
mov    $0x17,%edi
xor    %edx,%edx
call   1070 <socket@plt>
test   %eax,%eax
js     11ef <modify_flags+0x9f>
mov    %eax,%ebx
mov    0x2e42(%rip),%r12
mov    (%r12),%edx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2e3f(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1206 <modify_flags+0xb6>
or     0x8(%rsp),%r15d
not    %ebp
and    %r15d,%ebp
mov    %ebp,0x8(%rsp)
mov    0xc(%rsp),%edi
mov    (%r12),%edx
mov    %r14,%rsi
call   1030 <strncpy@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebx,%edi
call   1040 <ioctl@plt>
test   %rax,%rax
js     1218 <modify_flags+0xc8>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
jmp    1239 <modify_flags+0xe9>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
lea    0xe01(%rip),%rsi
call   1060 <syslog@plt>
jmp    1234 <modify_flags+0xe4>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
lea    0xdfe(%rip),%rsi
jmp    1228 <modify_flags+0xd8>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe04(%rip),%rsi
call   1060 <syslog@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.ifreq = type { i32, i32 }
@SOCK_STREAM = global i32 0
@LOG_WARNING = global i32 0
@.str = [20 x i8] c"socket(AF_IRDA): %m\00"
@IFNAMSIZ = global i32 0
@SIOCGIFFLAGS = global i32 0
@.str.1 = [24 x i8] c"ioctl(SIOCGIFFLAGS): %m\00"
@SIOCSIFFLAGS = global i32 0
@.str.2 = [24 x i8] c"ioctl(SIOCSIFFLAGS): %m\00"
define i32 @modify_flags(i8* %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca %struct.ifreq
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
%10 = load i32, i32* @SOCK_STREAM
%11 = call i32 @socket(i32 23, i32 %10, i32 0)
store i32 %11, i32* %9
%12 = load i32, i32* %9
%13 = icmp slt i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %3
%15 = load i32, i32* @LOG_WARNING
%16 = call i32 @syslog(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %59
17: ; preds = %3
%18 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%19 = load i32, i32* %18
%20 = load i8*, i8** %5
%21 = load i32, i32* @IFNAMSIZ
%22 = call i32 @strncpy(i32 %19, i8* %20, i32 %21)
%23 = load i32, i32* %9
%24 = load i32, i32* @SIOCGIFFLAGS
%25 = call i64 @ioctl(i32 %23, i32 %24, %struct.ifreq* %8)
%26 = icmp slt i64 %25, 0
br i1 %26, label %27, label %32
27: ; preds = %17
%28 = load i32, i32* @LOG_WARNING
%29 = call i32 @syslog(i32 %28, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%30 = load i32, i32* %9
%31 = call i32 @close(i32 %30)
store i32 -1, i32* %4
br label %59
32: ; preds = %17
%33 = load i32, i32* %6
%34 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%35 = load i32, i32* %34
%36 = or i32 %35, %33
store i32 %36, i32* %34
%37 = load i32, i32* %7
%38 = xor i32 %37, -1
%39 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%40 = load i32, i32* %39
%41 = and i32 %40, %38
store i32 %41, i32* %39
%42 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%43 = load i32, i32* %42
%44 = load i8*, i8** %5
%45 = load i32, i32* @IFNAMSIZ
%46 = call i32 @strncpy(i32 %43, i8* %44, i32 %45)
%47 = load i32, i32* %9
%48 = load i32, i32* @SIOCSIFFLAGS
%49 = call i64 @ioctl(i32 %47, i32 %48, %struct.ifreq* %8)
%50 = icmp slt i64 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %32
%52 = load i32, i32* @LOG_WARNING
%53 = call i32 @syslog(i32 %52, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32, i32* %9
%55 = call i32 @close(i32 %54)
store i32 -1, i32* %4
br label %59
56: ; preds = %32
%57 = load i32, i32* %9
%58 = call i32 @close(i32 %57)
store i32 0, i32* %4
br label %59
59: ; preds = %56, %51, %27, %14
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
%struct.ifreq = type { i32, i32 }
@SOCK_STREAM = global i32 0
@LOG_WARNING = global i32 0
@.str = [20 x i8] c"socket(AF_IRDA): %m\00"
@IFNAMSIZ = global i32 0
@SIOCGIFFLAGS = global i32 0
@.str.1 = [24 x i8] c"ioctl(SIOCGIFFLAGS): %m\00"
@SIOCSIFFLAGS = global i32 0
@.str.2 = [24 x i8] c"ioctl(SIOCSIFFLAGS): %m\00"
define i32 @modify_flags(i8* %0, i32 %1, i32 %2) {
%4 = alloca %struct.ifreq
%5 = bitcast %struct.ifreq* %4 to i8*
%6 = load i32, i32* @SOCK_STREAM
%7 = tail call i32 @socket(i32 23, i32 %6, i32 0)
%8 = icmp slt i32 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %3
%10 = load i32, i32* @LOG_WARNING
%11 = tail call i32 @syslog(i32 %10, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %41
12: ; preds = %3
%13 = load i32, i32* @IFNAMSIZ
%14 = tail call i32 @strncpy(i32 undef, i8* %0, i32 %13)
%15 = load i32, i32* @SIOCGIFFLAGS
%16 = call i64 @ioctl(i32 %7, i32 %15, %struct.ifreq* %4)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %22
18: ; preds = %12
%19 = load i32, i32* @LOG_WARNING
%20 = call i32 @syslog(i32 %19, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @close(i32 %7)
br label %41
22: ; preds = %12
%23 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 1
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %4, i64 0, i32 0
%25 = load i32, i32* %24
%26 = or i32 %25, %1
%27 = xor i32 %2, -1
%28 = and i32 %26, %27
store i32 %28, i32* %24
%29 = load i32, i32* %23
%30 = load i32, i32* @IFNAMSIZ
%31 = call i32 @strncpy(i32 %29, i8* %0, i32 %30)
%32 = load i32, i32* @SIOCSIFFLAGS
%33 = call i64 @ioctl(i32 %7, i32 %32, %struct.ifreq* %4)
%34 = icmp slt i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %22
%36 = load i32, i32* @LOG_WARNING
%37 = call i32 @syslog(i32 %36, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%38 = call i32 @close(i32 %7)
br label %41
39: ; preds = %22
%40 = call i32 @close(i32 %7)
br label %41
41: ; preds = %39, %35, %18, %9
%42 = phi i32 [ -1, %9 ], [ -1, %18 ], [ -1, %35 ], [ 0, %39 ]
ret i32 %42
}