#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;
  short ifr_flags;
};

/* Variables and functions */
int /*<<< orphan*/ SIOCGIFFLAGS;
int /*<<< orphan*/ SIOCSIFFLAGS;
scalar_t__ ioctl(int, int /*<<< orphan*/, struct ifreq *);
int /*<<< orphan*/ strncpy(char *, char *, int);
int set_flag(int skfd, char *ifname, short flag) {
  struct ifreq ifr;
  strncpy(ifr.ifr_name, ifname, 16);
  ifr.ifr_name[16] = '\0';
  if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) {
    return (-1);
  }
  ifr.ifr_flags |= flag;
  if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) {
    return (-1);
  }
  return (1);
}


x86 assembly (clang, -O0):
<set_flag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dx,%ax
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %ax,-0x12(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x10,%edx
call   1030 <strncpy@plt>
mov    -0x28(%rbp),%rax
movb   $0x0,0x10(%rax)
mov    -0x8(%rbp),%edi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    117b <set_flag+0x5b>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <set_flag+0x9b>
movswl -0x12(%rbp),%ecx
movswl -0x20(%rbp),%eax
or     %ecx,%eax
mov    %ax,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    0x2e65(%rip),%rax
mov    (%rax),%esi
lea    -0x28(%rbp),%rdx
call   1040 <ioctl@plt>
cmp    $0x0,%rax
jge    11b4 <set_flag+0x94>
movl   $0xffffffff,-0x4(%rbp)
jmp    11bb <set_flag+0x9b>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_flag>:
push   %rax
mov    $0x10,%edx
call   1030 <strncpy@plt>

LLVM IR (-O0):
%struct.ifreq = type { i8*, i16 }
@SIOCGIFFLAGS = global i32 0
@SIOCSIFFLAGS = global i32 0
define i32 @set_flag(i32 %0, i8* %1, i16 signext %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i16
%8 = alloca %struct.ifreq
store i32 %0, i32* %5
store i8* %1, i8** %6
store i16 %2, i16* %7
%9 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%10 = load i8*, i8** %9
%11 = load i8*, i8** %6
%12 = call i32 @strncpy(i8* %10, i8* %11, i32 16)
%13 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 0
%14 = load i8*, i8** %13
%15 = getelementptr inbounds i8, i8* %14, i64 16
store i8 0, i8* %15
%16 = load i32, i32* %5
%17 = load i32, i32* @SIOCGIFFLAGS
%18 = call i64 @ioctl(i32 %16, i32 %17, %struct.ifreq* %8)
%19 = icmp slt i64 %18, 0
br i1 %19, label %20, label %21
20: ; preds = %3
store i32 -1, i32* %4
br label %35
21: ; preds = %3
%22 = load i16, i16* %7
%23 = sext i16 %22 to i32
%24 = getelementptr inbounds %struct.ifreq, %struct.ifreq* %8, i32 0, i32 1
%25 = load i16, i16* %24
%26 = sext i16 %25 to i32
%27 = or i32 %26, %23
%28 = trunc i32 %27 to i16
store i16 %28, i16* %24
%29 = load i32, i32* %5
%30 = load i32, i32* @SIOCSIFFLAGS
%31 = call i64 @ioctl(i32 %29, i32 %30, %struct.ifreq* %8)
%32 = icmp slt i64 %31, 0
br i1 %32, label %33, label %34
33: ; preds = %21
store i32 -1, i32* %4
br label %35
34: ; preds = %21
store i32 1, i32* %4
br label %35
35: ; preds = %34, %33, %20
%36 = load i32, i32* %4
ret i32 %36
}

LLVM IR (-O2):
@SIOCGIFFLAGS = global i32 0
@SIOCSIFFLAGS = global i32 0
define i32 @set_flag(i32 %0, i8* %1, i16 signext %2) {
%4 = tail call i32 @strncpy(i8* undef, i8* %1, i32 16)
unreachable
}