#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ VT_ACTIVATE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ error(char *);
scalar_t__ ioctl(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
void setconsole(int console) {
  int fd = open("/dev/tty1", O_RDWR);
  if (fd == -1) {
    error("error open /dev/tty\n");
    return;
  }
  if (ioctl(fd, VT_ACTIVATE, console)) {
    error("error VT_ACTIVATE\n");
  }
  close(fd);
}


x86 assembly (clang, -O0):
<setconsole>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
lea    0xea5(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0xffffffff,-0x8(%rbp)
jne    117e <setconsole+0x3e>
lea    0xe96(%rip),%rdi
call   1050 <error@plt>
jmp    11b0 <setconsole+0x70>
mov    -0x8(%rbp),%edi
mov    0x2e58(%rip),%rax
mov    (%rax),%esi
mov    -0x4(%rbp),%edx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
je     11a8 <setconsole+0x68>
lea    0xe7c(%rip),%rdi
call   1050 <error@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<setconsole>:
push   %rbp
push   %rbx
push   %rax
mov    %edi,%ebp
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
lea    0xeab(%rip),%rdi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1191 <setconsole+0x51>
mov    %eax,%ebx
mov    0x2e78(%rip),%rax
mov    (%rax),%esi
mov    %ebx,%edi
mov    %ebp,%edx
call   1030 <ioctl@plt>
test   %rax,%rax
je     1184 <setconsole+0x44>
lea    0xea0(%rip),%rdi
call   1050 <error@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <close@plt>
lea    0xe72(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <error@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/tty1\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"error open /dev/tty\0A\00"
@VT_ACTIVATE = global i32 0
@.str.2 = [19 x i8] c"error VT_ACTIVATE\0A\00"
define void @setconsole(i32 %0) {
%2 = alloca i32
%3 = alloca i32
store i32 %0, i32* %2
%4 = load i32, i32* @O_RDWR
%5 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %3
%6 = load i32, i32* %3
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %10
8: ; preds = %1
%9 = call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %21
10: ; preds = %1
%11 = load i32, i32* %3
%12 = load i32, i32* @VT_ACTIVATE
%13 = load i32, i32* %2
%14 = call i64 @ioctl(i32 %11, i32 %12, i32 %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %10
%17 = call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %18
18: ; preds = %16, %10
%19 = load i32, i32* %3
%20 = call i32 @close(i32 %19)
br label %21
21: ; preds = %18, %8
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/tty1\00"
@O_RDWR = global i32 0
@.str.1 = [21 x i8] c"error open /dev/tty\0A\00"
@VT_ACTIVATE = global i32 0
@.str.2 = [19 x i8] c"error VT_ACTIVATE\0A\00"
define void @setconsole(i32 %0) {
%2 = load i32, i32* @O_RDWR
%3 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp eq i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %1
%6 = tail call i32 @error(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %15
7: ; preds = %1
%8 = load i32, i32* @VT_ACTIVATE
%9 = tail call i64 @ioctl(i32 %3, i32 %8, i32 %0)
%10 = icmp eq i64 %9, 0
br i1 %10, label %13, label %11
11: ; preds = %7
%12 = tail call i32 @error(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0))
br label %13
13: ; preds = %11, %7
%14 = tail call i32 @close(i32 %3)
br label %15
15: ; preds = %13, %5
ret void
}