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

/* Variables and functions */
scalar_t__ try_vtstate(char *, struct vt_stat *);
bool get_vtstate(struct vt_stat *vtstat) {
  if (try_vtstate("/dev/tty", vtstat))
    return true;
  if (try_vtstate("/dev/tty0", vtstat))
    return true;
  if (try_vtstate("/dev/console", vtstat))
    return true;
  return false;
}


x86 assembly (clang, -O0):
<get_vtstate>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
lea    0xed9(%rip),%rdi
call   1030 <try_vtstate@plt>
cmp    $0x0,%rax
je     1142 <get_vtstate+0x32>
movl   $0x1,-0x4(%rbp)
jmp    1195 <get_vtstate+0x85>
mov    -0x10(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   1030 <try_vtstate@plt>
cmp    $0x0,%rax
je     1168 <get_vtstate+0x58>
movl   $0x1,-0x4(%rbp)
jmp    1195 <get_vtstate+0x85>
mov    -0x10(%rbp),%rsi
lea    0xea0(%rip),%rdi
call   1030 <try_vtstate@plt>
cmp    $0x0,%rax
je     118e <get_vtstate+0x7e>
movl   $0x1,-0x4(%rbp)
jmp    1195 <get_vtstate+0x85>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_vtstate>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xee3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <try_vtstate@plt>
mov    $0x1,%ebp
test   %rax,%rax
jne    115b <get_vtstate+0x4b>
lea    0xed3(%rip),%rdi
mov    %rbx,%rsi
call   1030 <try_vtstate@plt>
test   %rax,%rax
jne    115b <get_vtstate+0x4b>
lea    0xec9(%rip),%rdi
mov    %rbx,%rsi
call   1030 <try_vtstate@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.vt_stat = type { i32 }
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [10 x i8] c"/dev/tty0\00"
@.str.2 = [13 x i8] c"/dev/console\00"
define i32 @get_vtstate(%struct.vt_stat* %0) {
%2 = alloca i32
%3 = alloca %struct.vt_stat*
store %struct.vt_stat* %0, %struct.vt_stat** %3
%4 = load %struct.vt_stat*, %struct.vt_stat** %3
%5 = call i64 @try_vtstate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.vt_stat* %4)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %1
store i32 1, i32* %2
br label %19
8: ; preds = %1
%9 = load %struct.vt_stat*, %struct.vt_stat** %3
%10 = call i64 @try_vtstate(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %struct.vt_stat* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 1, i32* %2
br label %19
13: ; preds = %8
%14 = load %struct.vt_stat*, %struct.vt_stat** %3
%15 = call i64 @try_vtstate(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %struct.vt_stat* %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %13
store i32 1, i32* %2
br label %19
18: ; preds = %13
store i32 0, i32* %2
br label %19
19: ; preds = %18, %17, %12, %7
%20 = load i32, i32* %2
ret i32 %20
}

LLVM IR (-O2):
%struct.vt_stat = type { i32 }
@.str = [9 x i8] c"/dev/tty\00"
@.str.1 = [10 x i8] c"/dev/tty0\00"
@.str.2 = [13 x i8] c"/dev/console\00"
define i32 @get_vtstate(%struct.vt_stat* %0) {
%2 = tail call i64 @try_vtstate(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), %struct.vt_stat* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %11
4: ; preds = %1
%5 = tail call i64 @try_vtstate(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), %struct.vt_stat* %0)
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = tail call i64 @try_vtstate(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0), %struct.vt_stat* %0)
%9 = icmp ne i64 %8, 0
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %7, %4, %1
%12 = phi i32 [ 1, %1 ], [ 1, %4 ], [ %10, %7 ]
ret i32 %12
}