#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_RUNNING;
int IFF_UP;
int device_get_flags(char const *);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char const *, int /*<<< orphan*/);
int device_up_and_running(const char *ifname) {
  if (!ifname)
    return -EINVAL;
  if (!strncmp("any", ifname, strlen("any")))
    return 1;
  return (device_get_flags(ifname) & (IFF_UP | IFF_RUNNING)) ==
         (IFF_UP | IFF_RUNNING);
}


x86 assembly (clang, -O0):
<device_up_and_running>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115a <device_up_and_running+0x2a>
xor    %eax,%eax
mov    0x2e80(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11d1 <device_up_and_running+0xa1>
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_and_running+0x65>
movl   $0x1,-0x4(%rbp)
jmp    11d1 <device_up_and_running+0xa1>
mov    -0x10(%rbp),%rdi
call   1050 <device_get_flags@plt>
mov    0x2e3b(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e3a(%rip),%rdx
or     (%rdx),%ecx
and    %ecx,%eax
mov    0x2e27(%rip),%rcx
mov    (%rcx),%ecx
mov    0x2e26(%rip),%rdx
or     (%rdx),%ecx
cmp    %ecx,%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_and_running>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     1183 <device_up_and_running+0x53>
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     1190 <device_up_and_running+0x60>
mov    %rbx,%rdi
call   1050 <device_get_flags@plt>
mov    %eax,%ecx
mov    0x2e73(%rip),%rax
mov    0x2e74(%rip),%rdx
mov    (%rdx),%edx
or     (%rax),%edx
not    %ecx
xor    %eax,%eax
test   %ecx,%edx
sete   %al
jmp    1195 <device_up_and_running+0x65>
mov    0x2e46(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%eax
jmp    1195 <device_up_and_running+0x65>
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
@IFF_RUNNING = global i32 0
define i32 @device_up_and_running(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 %27
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 %27
15: ; preds = %9
%16 = load i8*, i8** %3
%17 = call i32 @device_get_flags(i8* %16)
%18 = load i32, i32* @IFF_UP
%19 = load i32, i32* @IFF_RUNNING
%20 = or i32 %18, %19
%21 = and i32 %17, %20
%22 = load i32, i32* @IFF_UP
%23 = load i32, i32* @IFF_RUNNING
%24 = or i32 %22, %23
%25 = icmp eq i32 %21, %24
%26 = zext i1 %25 to i32
store i32 %26, i32* %2
br label %27
27: ; preds = %15, %14, %6
%28 = load i32, i32* %2
ret i32 %28
}

LLVM IR (-O2):
@EINVAL = global i32 0
@.str = [4 x i8] c"any\00"
@IFF_UP = global i32 0
@IFF_RUNNING = global i32 0
define i32 @device_up_and_running(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 %18
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 %18, label %10
10: ; preds = %6
%11 = tail call i32 @device_get_flags(i8* %0)
%12 = load i32, i32* @IFF_UP
%13 = load i32, i32* @IFF_RUNNING
%14 = or i32 %13, %12
%15 = and i32 %14, %11
%16 = icmp eq i32 %15, %14
%17 = zext i1 %16 to i32
br label %18
18: ; preds = %6, %10, %3
%19 = phi i32 [ %17, %10 ], [ %5, %3 ], [ 1, %6 ]
ret i32 %19
}