#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 termios {
  int *c_cc;
  scalar_t__ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getchar();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
int main() {
  struct termios term, bkp;
  if (tcgetattr(1, &term)) {
    perror("failed to get termios\n");
    exit(1);
  }
  bkp = term;
  term.c_lflag = 0;
  term.c_cc[VTIME] = 0;
  term.c_cc[VMIN] = 1;
  if (tcsetattr(1, TCSANOW, &term)) {
    perror("Failed to set termios\n");
    exit(1);
  }
  puts("[2J");
  puts("[0m");
  puts("[0;0H");
  printf("hello world!!!!\n");
  puts("[32m");
  puts("GREEEEEEENNN");
  printf("%c[33m%s", 0x1b, "YELLOW");
  int i;
  for (i = 0; i < 10; ++i)
    puts("hehe");
  puts("enter to exit");
  fputs("[0;0H", stdout);
  getchar();
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1,%edi
lea    -0x18(%rbp),%rsi
call   1070 <tcgetattr@plt>
cmp    $0x0,%rax
je     11bd <main+0x3d>
lea    0xe52(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x18(%rbp),%rax
mov    0x2de8(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x18(%rbp),%rax
mov    0x2deb(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2de2(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    -0x18(%rbp),%rdx
call   1080 <tcsetattr@plt>
cmp    $0x0,%rax
je     1236 <main+0xb6>
lea    0xdf0(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
lea    0xdf1(%rip),%rdi
call   1030 <puts@plt>
lea    0xdea(%rip),%rdi
call   1030 <puts@plt>
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
lea    0xdde(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde1(%rip),%rdi
call   1030 <puts@plt>
lea    0xddb(%rip),%rdi
call   1030 <puts@plt>
lea    0xddc(%rip),%rdi
mov    $0x1b,%esi
lea    0xdd9(%rip),%rdx
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x2c(%rbp)
cmpl   $0xa,-0x2c(%rbp)
jge    12c5 <main+0x145>
lea    0xdc1(%rip),%rdi
call   1030 <puts@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    12a1 <main+0x121>
lea    0xdac(%rip),%rdi
call   1030 <puts@plt>
mov    0x2cf8(%rip),%rax
mov    (%rax),%esi
lea    0xd57(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x0,%al
call   1060 <getchar@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
lea    0x8(%rsp),%rsi
mov    $0x1,%edi
call   1070 <tcgetattr@plt>
test   %rax,%rax
jne    12da <main+0x15a>
movq   $0x0,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2e14(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e1b(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x1,(%rax,%rcx,4)
mov    0x2e12(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    $0x1,%edi
call   1080 <tcsetattr@plt>
test   %rax,%rax
jne    12e3 <main+0x163>
lea    0xe37(%rip),%rdi
call   1030 <puts@plt>
lea    0xe30(%rip),%rdi
call   1030 <puts@plt>
lea    0xe29(%rip),%r14
mov    %r14,%rdi
call   1030 <puts@plt>
lea    0xe57(%rip),%rdi
call   1030 <puts@plt>
lea    0xe15(%rip),%rdi
call   1030 <puts@plt>
lea    0xe0f(%rip),%rdi
call   1030 <puts@plt>
lea    0xe10(%rip),%rdi
lea    0xe12(%rip),%rdx
mov    $0x1b,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe06(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
lea    0xdb4(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d11(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1050 <fputs@plt>
xor    %eax,%eax
call   1060 <getchar@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret
lea    0xd1f(%rip),%rdi
jmp    12ea <main+0x16a>
lea    0xd2d(%rip),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.termios = type { i32*, i64 }
@.str = [23 x i8] c"failed to get termios\0A\00"
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@.str.1 = [23 x i8] c"Failed to set termios\0A\00"
@.str.2 = [5 x i8] c"\1B[2J\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@.str.4 = [7 x i8] c"\1B[0;0H\00"
@.str.5 = [17 x i8] c"hello world!!!!\0A\00"
@.str.6 = [6 x i8] c"\1B[32m\00"
@.str.7 = [13 x i8] c"GREEEEEEENNN\00"
@.str.8 = [9 x i8] c"%c[33m%s\00"
@.str.9 = [7 x i8] c"YELLOW\00"
@.str.10 = [5 x i8] c"hehe\00"
@.str.11 = [14 x i8] c"enter to exit\00"
@stdout = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca %struct.termios
%3 = alloca %struct.termios
%4 = alloca i32
store i32 0, i32* %1
%5 = call i64 @tcgetattr(i32 1, %struct.termios* %2)
%6 = icmp ne i64 %5, 0
br i1 %6, label %7, label %10
7: ; preds = %0
%8 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = bitcast %struct.termios* %3 to i8*
%12 = bitcast %struct.termios* %2 to i8*
%13 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 1
store i64 0, i64* %13
%14 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%15 = load i32*, i32** %14
%16 = load i64, i64* @VTIME
%17 = getelementptr inbounds i32, i32* %15, i64 %16
store i32 0, i32* %17
%18 = getelementptr inbounds %struct.termios, %struct.termios* %2, i32 0, i32 0
%19 = load i32*, i32** %18
%20 = load i64, i64* @VMIN
%21 = getelementptr inbounds i32, i32* %19, i64 %20
store i32 1, i32* %21
%22 = load i32, i32* @TCSANOW
%23 = call i64 @tcsetattr(i32 1, i32 %22, %struct.termios* %2)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %28
25: ; preds = %10
%26 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %10
%29 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%30 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @puts(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
%33 = call i32 @puts(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%34 = call i32 @puts(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %4
br label %36
36: ; preds = %41, %28
%37 = load i32, i32* %4
%38 = icmp slt i32 %37, 10
br i1 %38, label %39, label %44
39: ; preds = %36
%40 = call i32 @puts(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
br label %41
41: ; preds = %39
%42 = load i32, i32* %4
%43 = add nsw i32 %42, 1
store i32 %43, i32* %4
br label %36
44: ; preds = %36
%45 = call i32 @puts(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%46 = load i32, i32* @stdout
%47 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %46)
%48 = call i32 (...) @getchar()
%49 = load i32, i32* %1
ret i32 %49
}

LLVM IR (-O2):
%struct.termios = type { i32*, i64 }
@.str = [23 x i8] c"failed to get termios\0A\00"
@VTIME = global i64 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@.str.1 = [23 x i8] c"Failed to set termios\0A\00"
@.str.2 = [5 x i8] c"\1B[2J\00"
@.str.3 = [5 x i8] c"\1B[0m\00"
@.str.4 = [7 x i8] c"\1B[0;0H\00"
@.str.6 = [6 x i8] c"\1B[32m\00"
@.str.7 = [13 x i8] c"GREEEEEEENNN\00"
@.str.8 = [9 x i8] c"%c[33m%s\00"
@.str.9 = [7 x i8] c"YELLOW\00"
@.str.10 = [5 x i8] c"hehe\00"
@.str.11 = [14 x i8] c"enter to exit\00"
@stdout = global i32 0
@str = [16 x i8] c"hello world!!!!\00"
define i32 @main() {
%1 = alloca %struct.termios
%2 = bitcast %struct.termios* %1 to i8*
%3 = call i64 @tcgetattr(i32 1, %struct.termios* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @exit(i32 1)
unreachable
8: ; preds = %0
%9 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 1
store i64 0, i64* %9
%10 = getelementptr inbounds %struct.termios, %struct.termios* %1, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = load i64, i64* @VTIME
%13 = getelementptr inbounds i32, i32* %11, i64 %12
store i32 0, i32* %13
%14 = load i64, i64* @VMIN
%15 = getelementptr inbounds i32, i32* %11, i64 %14
store i32 1, i32* %15
%16 = load i32, i32* @TCSANOW
%17 = call i64 @tcsetattr(i32 1, i32 %16, %struct.termios* %1)
%18 = icmp eq i64 %17, 0
br i1 %18, label %22, label %19
19: ; preds = %8
%20 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %8
%23 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%25 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0))
%26 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0))
%28 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.8, i64 0, i64 0), i32 27, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%30 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%32 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%33 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%36 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%38 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0))
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.11, i64 0, i64 0))
%41 = load i32, i32* @stdout
%42 = call i32 @fputs(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i32 %41)
%43 = call i32 (...) @getchar()
ret i32 0
}