#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;
  int /*<<< orphan*/ c_lflag;
};

/* Variables and functions */
int /*<<< orphan*/ ICANON;
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ tcgetattr(int /*<<< orphan*/, struct termios *);
int /*<<< orphan*/ tcsetattr(int /*<<< orphan*/, int /*<<< orphan*/,
                             struct termios *);
int main(int argc, char *argv[]) {
  int fd;
  struct termios t;
  char buf[5] = {0};
  tcgetattr(0, &t);
  t.c_lflag &= ~(ICANON);
  t.c_cc[VMIN] = 0;
  tcsetattr(0, TCSANOW, &t);
  tcgetattr(0, &t);
  printf("VMIN:%d, VTIME:%d\n", t.c_cc[VMIN], t.c_cc[VTIME]);
  read(0, buf, 4);
  printf("buffer: %s\n", buf);
  return 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)
lea    -0x2d(%rbp),%rdi
xor    %esi,%esi
mov    $0x5,%edx
call   1040 <memset@plt>
xor    %edi,%edi
lea    -0x28(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    -0x20(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e42(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e39(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
lea    -0x28(%rbp),%rdx
call   1070 <tcsetattr@plt>
xor    %edi,%edi
lea    -0x28(%rbp),%rsi
call   1060 <tcgetattr@plt>
mov    -0x28(%rbp),%rax
mov    0x2e0e(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,4),%esi
mov    -0x28(%rbp),%rax
mov    0x2ded(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x2d(%rbp),%rsi
xor    %edi,%edi
mov    $0x4,%edx
call   1050 <read@plt>
lea    -0x2d(%rbp),%rsi
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movb   $0x0,0x4(%rsp)
movl   $0x0,(%rsp)
lea    0x8(%rsp),%rbx
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <tcgetattr@plt>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
not    %eax
and    %eax,0x10(%rsp)
mov    0x8(%rsp),%rax
mov    0x2e63(%rip),%r14
mov    (%r14),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
xor    %edi,%edi
mov    %rbx,%rdx
call   1060 <tcsetattr@plt>
xor    %edi,%edi
mov    %rbx,%rsi
call   1050 <tcgetattr@plt>
mov    0x8(%rsp),%rax
mov    (%r14),%rcx
mov    (%rax,%rcx,4),%esi
mov    0x2e1a(%rip),%rcx
mov    (%rcx),%rcx
mov    (%rax,%rcx,4),%edx
lea    0xe3d(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    %rsp,%rbx
xor    %edi,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
call   1040 <read@plt>
lea    0xe30(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.termios = type { i32*, i32 }
@ICANON = global i32 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@.str = [19 x i8] c"VMIN:%d, VTIME:%d\0A\00"
@VTIME = global i64 0
@.str.1 = [12 x i8] c"buffer: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.termios
%8 = alloca [5 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [5 x i8]* %8 to i8*
%10 = call i32 @tcgetattr(i32 0, %struct.termios* %7)
%11 = load i32, i32* @ICANON
%12 = xor i32 %11, -1
%13 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 1
%14 = load i32, i32* %13
%15 = and i32 %14, %12
store i32 %15, i32* %13
%16 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%17 = load i32*, i32** %16
%18 = load i64, i64* @VMIN
%19 = getelementptr inbounds i32, i32* %17, i64 %18
store i32 0, i32* %19
%20 = load i32, i32* @TCSANOW
%21 = call i32 @tcsetattr(i32 0, i32 %20, %struct.termios* %7)
%22 = call i32 @tcgetattr(i32 0, %struct.termios* %7)
%23 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%24 = load i32*, i32** %23
%25 = load i64, i64* @VMIN
%26 = getelementptr inbounds i32, i32* %24, i64 %25
%27 = load i32, i32* %26
%28 = getelementptr inbounds %struct.termios, %struct.termios* %7, i32 0, i32 0
%29 = load i32*, i32** %28
%30 = load i64, i64* @VTIME
%31 = getelementptr inbounds i32, i32* %29, i64 %30
%32 = load i32, i32* %31
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %27, i32 %32)
%34 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%35 = call i32 @read(i32 0, i8* %34, i32 4)
%36 = getelementptr inbounds [5 x i8], [5 x i8]* %8, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %36)
ret i32 0
}

LLVM IR (-O2):
%struct.termios = type { i32*, i32 }
@ICANON = global i32 0
@VMIN = global i64 0
@TCSANOW = global i32 0
@.str = [19 x i8] c"VMIN:%d, VTIME:%d\0A\00"
@VTIME = global i64 0
@.str.1 = [12 x i8] c"buffer: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca %struct.termios
%4 = alloca [5 x i8]
%5 = bitcast %struct.termios* %3 to i8*
%6 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%7 = call i32 @tcgetattr(i32 0, %struct.termios* %3)
%8 = load i32, i32* @ICANON
%9 = xor i32 %8, -1
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 1
%11 = load i32, i32* %10
%12 = and i32 %11, %9
store i32 %12, i32* %10
%13 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%14 = load i32*, i32** %13
%15 = load i64, i64* @VMIN
%16 = getelementptr inbounds i32, i32* %14, i64 %15
store i32 0, i32* %16
%17 = load i32, i32* @TCSANOW
%18 = call i32 @tcsetattr(i32 0, i32 %17, %struct.termios* %3)
%19 = call i32 @tcgetattr(i32 0, %struct.termios* %3)
%20 = load i32*, i32** %13
%21 = load i64, i64* @VMIN
%22 = getelementptr inbounds i32, i32* %20, i64 %21
%23 = load i32, i32* %22
%24 = load i64, i64* @VTIME
%25 = getelementptr inbounds i32, i32* %20, i64 %24
%26 = load i32, i32* %25
%27 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %23, i32 %26)
%28 = call i32 @read(i32 0, i8* %6, i32 4)
%29 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %6)
ret i32 0
}