#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*/ STDIN_FILENO;
int /*<<< orphan*/ TIOCLINUX;
char atoi(char *);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ ioctl(int /*<<< orphan*/, int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char **argv) {
  char bytes[2] = {11, 0};
  if (argc == 2)
    bytes[1] = atoi(argv[1]);
  else {
    fprintf(stderr, "%s: need a single arg\n", argv[0]);
    exit(1);
  }
  if (ioctl(STDIN_FILENO, TIOCLINUX, bytes) < 0) {
    fprintf(stderr, "%s: ioctl(stdin, TIOCLINUX): %s\n", argv[0],
            strerror(errno));
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe93(%rip),%ax
mov    %ax,-0x12(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1190 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <atoi@plt>
mov    %al,-0x11(%rbp)
jmp    11b8 <main+0x68>
mov    0x2e49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe5b(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    0x2e08(%rip),%rax
mov    (%rax),%esi
lea    -0x12(%rbp),%rdx
call   1030 <ioctl@plt>
cmp    $0x0,%rax
jge    1224 <main+0xd4>
mov    0x2dfc(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x24(%rbp),%edi
mov    -0x20(%rbp),%rdx
mov    %rax,%rcx
lea    0xe06(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
movw   $0xb,0x6(%rsp)
cmp    $0x2,%edi
jne    11ca <main+0x7a>
mov    0x8(%rbx),%rdi
call   1050 <atoi@plt>
mov    %al,0x7(%rsp)
mov    0x2e52(%rip),%rax
mov    (%rax),%edi
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
lea    0x6(%rsp),%rdx
call   1030 <ioctl@plt>
test   %rax,%rax
jns    11ee <main+0x9e>
mov    0x2e49(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe66(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe23(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@__const.main.bytes = [2 x i8] c"\0B\00"
@stderr = global i32 0
@.str = [23 x i8] c"%s: need a single arg\0A\00"
@STDIN_FILENO = global i32 0
@TIOCLINUX = global i32 0
@.str.1 = [33 x i8] c"%s: ioctl(stdin, TIOCLINUX): %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = bitcast [2 x i8]* %6 to i8*
%8 = load i32, i32* %4
%9 = icmp eq i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call signext i8 @atoi(i8* %13)
%15 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 1
store i8 %14, i8* %15
br label %23
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 0
%20 = load i8*, i8** %19
%21 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 1)
unreachable
23: ; preds = %10
%24 = load i32, i32* @STDIN_FILENO
%25 = load i32, i32* @TIOCLINUX
%26 = getelementptr inbounds [2 x i8], [2 x i8]* %6, i64 0, i64 0
%27 = call i64 @ioctl(i32 %24, i32 %25, i8* %26)
%28 = icmp slt i64 %27, 0
br i1 %28, label %29, label %38
29: ; preds = %23
%30 = load i32, i32* @stderr
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 0
%33 = load i8*, i8** %32
%34 = load i32, i32* @errno
%35 = call i8* @strerror(i32 %34)
%36 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %33, i8* %35)
%37 = call i32 @exit(i32 1)
unreachable
38: ; preds = %23
%39 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [23 x i8] c"%s: need a single arg\0A\00"
@STDIN_FILENO = global i32 0
@TIOCLINUX = global i32 0
@.str.1 = [33 x i8] c"%s: ioctl(stdin, TIOCLINUX): %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i16
%4 = bitcast i16* %3 to i8*
store i16 11, i16* %3
%5 = icmp eq i32 %0, 2
br i1 %5, label %6, label %16
6: ; preds = %2
%7 = bitcast i16* %3 to [2 x i8]*
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call signext i8 @atoi(i8* %9)
%11 = getelementptr inbounds [2 x i8], [2 x i8]* %7, i64 0, i64 1
store i8 %10, i8* %11
%12 = load i32, i32* @STDIN_FILENO
%13 = load i32, i32* @TIOCLINUX
%14 = call i64 @ioctl(i32 %12, i32 %13, i8* %4)
%15 = icmp slt i64 %14, 0
br i1 %15, label %21, label %28
16: ; preds = %2
%17 = load i32, i32* @stderr
%18 = load i8*, i8** %1
%19 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %6
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %1
%24 = load i32, i32* @errno
%25 = call i8* @strerror(i32 %24)
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i8* %23, i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %6
%29 = call i32 @exit(i32 0)
unreachable
}