#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_RDONLY;
int /*<<< orphan*/ _IO(int, int);
int /*<<< orphan*/ close(int);
int ioctl(int, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  int fd, retVal;
  if (argc != 2) {
    printf("Syntax: %s <device>\n", argv[0]);
    return 1;
  }
  printf("clear: %s\n", argv[1]);
  fd = open(argv[1], O_RDONLY, 0666);
  if (fd == -1) {
    perror("open");
    return 1;
  }
  retVal = ioctl(fd, _IO(0xCE, 7));
  if (retVal != 0) {
    perror("ioctl");
    close(fd);
    return 1;
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     119f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0xee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe67(%rip),%rdi
call   1030 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e26(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11f3 <main+0x93>
lea    0xe3e(%rip),%rdi
call   1080 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0xee>
mov    -0x14(%rbp),%eax
mov    %eax,-0x1c(%rbp)
mov    $0xce,%edi
mov    $0x7,%esi
call   1040 <_IO@plt>
mov    -0x1c(%rbp),%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     123f <main+0xdf>
lea    0xdff(%rip),%rdi
call   1080 <perror@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x1,-0x4(%rbp)
jmp    124e <main+0xee>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11be <main+0x5e>
mov    0x8(%rbx),%rsi
lea    0xea1(%rip),%rdi
call   1030 <printf@plt>
mov    0x8(%rbx),%rdi
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    $0x1b6,%edx
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11d4 <main+0x74>
mov    %eax,%ebx
mov    $0xce,%edi
mov    $0x7,%esi
call   1040 <_IO@plt>
mov    %ebx,%edi
mov    %eax,%esi
call   1050 <ioctl@plt>
test   %eax,%eax
jne    11e2 <main+0x82>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
mov    (%rbx),%rsi
lea    0xe38(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%eax
pop    %rbx
ret
lea    0xe45(%rip),%rdi
call   1080 <perror@plt>
jmp    11cd <main+0x6d>
lea    0xe3c(%rip),%rdi
call   1080 <perror@plt>
mov    %ebx,%edi
call   1060 <close@plt>
jmp    11cd <main+0x6d>

LLVM IR (-O0):
@.str = [21 x i8] c"Syntax: %s <device>\0A\00"
@.str.1 = [11 x i8] c"clear: %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"ioctl\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %13)
store i32 1, i32* %3
br label %42
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %18)
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32, i32* @O_RDONLY
%24 = call i32 @open(i8* %22, i32 %23, i32 438)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %29
27: ; preds = %15
%28 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %42
29: ; preds = %15
%30 = load i32, i32* %6
%31 = call i32 @_IO(i32 206, i32 7)
%32 = call i32 @ioctl(i32 %30, i32 %31)
store i32 %32, i32* %7
%33 = load i32, i32* %7
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%37 = load i32, i32* %6
%38 = call i32 @close(i32 %37)
store i32 1, i32* %3
br label %42
39: ; preds = %29
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
store i32 0, i32* %3
br label %42
42: ; preds = %39, %35, %27, %10
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [21 x i8] c"Syntax: %s <device>\0A\00"
@.str.1 = [11 x i8] c"clear: %s\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
@.str.3 = [6 x i8] c"ioctl\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %7, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %26
7: ; preds = %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%11 = load i8*, i8** %8
%12 = load i32, i32* @O_RDONLY
%13 = tail call i32 @open(i8* %11, i32 %12, i32 438)
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %17
15: ; preds = %7
%16 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %26
17: ; preds = %7
%18 = tail call i32 @_IO(i32 206, i32 7)
%19 = tail call i32 @ioctl(i32 %13, i32 %18)
%20 = icmp eq i32 %19, 0
br i1 %20, label %24, label %21
21: ; preds = %17
%22 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @close(i32 %13)
br label %26
24: ; preds = %17
%25 = tail call i32 @close(i32 %13)
br label %26
26: ; preds = %24, %21, %15, %4
%27 = phi i32 [ 1, %4 ], [ 1, %15 ], [ 1, %21 ], [ 0, %24 ]
ret i32 %27
}