#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 */

/* Variables and functions */
int EINVAL;
int IFF_UP;
int device_get_flags(char *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
int device_up(char *ifname) {
  if (!ifname)
    return -EINVAL;
  if (!strncmp("any", ifname, strlen("any")))
    return 1;
  return (device_get_flags(ifname) & IFF_UP) == IFF_UP;
}


x86 assembly (clang, -O0):
<device_up>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <device_up+0x2a>
xor    %eax,%eax
mov    0x2e88(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11bb <device_up+0x8b>
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
lea    0xe97(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x18(%rbp),%rsi
mov    %eax,%edx
lea    0xe85(%rip),%rdi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1195 <device_up+0x65>
movl   $0x1,-0x4(%rbp)
jmp    11bb <device_up+0x8b>
mov    -0x10(%rbp),%rdi
call   1050 <device_get_flags@plt>
mov    0x2e43(%rip),%rcx
and    (%rcx),%eax
mov    0x2e3a(%rip),%rcx
cmp    (%rcx),%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<device_up>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1178 <device_up+0x48>
mov    %rdi,%rbx
lea    0xebd(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     1185 <device_up+0x55>
mov    %rbx,%rdi
call   1050 <device_get_flags@plt>
mov    %eax,%ecx
mov    0x2e7b(%rip),%rdx
not    %ecx
xor    %eax,%eax
test   %ecx,(%rdx)
sete   %al
jmp    118a <device_up+0x5a>
mov    0x2e59(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    118a <device_up+0x5a>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@EINVAL = global i32 0
@.str = [4 x i8] c"any\00"
@IFF_UP = global i32 0
define i32 @device_up(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
store i8* %0, i8** %3
%4 = load i8*, i8** %3
%5 = icmp ne i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %1
%7 = load i32, i32* @EINVAL
%8 = sub nsw i32 0, %7
store i32 %8, i32* %2
br label %23
9: ; preds = %1
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %10, i32 %11)
%13 = icmp ne i32 %12, 0
br i1 %13, label %15, label %14
14: ; preds = %9
store i32 1, i32* %2
br label %23
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32 @device_get_flags(i8* %16)
%18 = load i32, i32* @IFF_UP
%19 = and i32 %17, %18
%20 = load i32, i32* @IFF_UP
%21 = icmp eq i32 %19, %20
%22 = zext i1 %21 to i32
store i32 %22, i32* %2
br label %23
23: ; preds = %15, %14, %6
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str = [4 x i8] c"any\00"
@IFF_UP = global i32 0
define i32 @device_up(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %3, label %6
3: ; preds = %1
%4 = load i32, i32* @EINVAL
%5 = sub nsw i32 0, %4
br label %16
6: ; preds = %1
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%8 = tail call i32 @strncmp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %16, label %10
10: ; preds = %6
%11 = tail call i32 @device_get_flags(i8* %0)
%12 = load i32, i32* @IFF_UP
%13 = and i32 %12, %11
%14 = icmp eq i32 %13, %12
%15 = zext i1 %14 to i32
br label %16
16: ; preds = %6, %10, %3
%17 = phi i32 [ %15, %10 ], [ %5, %3 ], [ 1, %6 ]
ret i32 %17
}