#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;
};

/* Variables and functions */
int /*<<< orphan*/ TCSANOW;
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ tcgetattr(int, struct termios *);
scalar_t__ tcsetattr(int, int /*<<< orphan*/, struct termios *);
void set_mincount(int fd, int mcount) {
  struct termios tty;
  if (tcgetattr(fd, &tty) < 0) {
    printf("Error tcgetattr: %s\n", strerror(errno));
    return;
  }
  tty.c_cc[VMIN] = mcount ? 1 : 0;
  tty.c_cc[VTIME] = 5;
  if (tcsetattr(fd, TCSANOW, &tty) < 0)
    printf("Error tcsetattr: %s\n", strerror(errno));
}


x86 assembly (clang, -O0):
<set_mincount>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
jge    1186 <set_mincount+0x46>
mov    0x2e65(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe84(%rip),%rdi
call   1030 <printf@plt>
jmp    11f8 <set_mincount+0xb8>
mov    -0x8(%rbp),%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
mov    -0x10(%rbp),%rax
mov    0x2e3f(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x2e16(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
mov    -0x4(%rbp),%edi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
lea    -0x10(%rbp),%rdx
call   1050 <tcsetattr@plt>
cmp    $0x0,%rax
jge    11f8 <set_mincount+0xb8>
mov    0x2dee(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rax,%rsi
lea    0xe22(%rip),%rdi
call   1030 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_mincount>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%ebp
mov    %edi,%ebx
mov    %rsp,%rsi
call   1040 <tcgetattr@plt>
test   %rax,%rax
js     119e <set_mincount+0x5e>
xor    %eax,%eax
test   %ebp,%ebp
setne  %al
mov    (%rsp),%rcx
mov    0x2e7a(%rip),%rdx
mov    (%rdx),%rdx
mov    %eax,(%rcx,%rdx,4)
mov    0x2e55(%rip),%rax
mov    (%rax),%rax
movl   $0x5,(%rcx,%rax,4)
mov    0x2e64(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rdx
mov    %ebx,%edi
call   1050 <tcsetattr@plt>
test   %rax,%rax
jns    11be <set_mincount+0x7e>
lea    0xe79(%rip),%rbx
jmp    11a5 <set_mincount+0x65>
lea    0xe5b(%rip),%rbx
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1060 <strerror@plt>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32* }
@.str = [21 x i8] c"Error tcgetattr: %s\0A\00"
@errno = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [21 x i8] c"Error tcsetattr: %s\0A\00"
define void @set_mincount(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca %struct.termios
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i64 @tcgetattr(i32 %6, %struct.termios* %5)
%8 = icmp slt i64 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @errno
%11 = call i8* @strerror(i32 %10)
%12 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %11)
br label %34
13: ; preds = %2
%14 = load i32, i32* %4
%15 = icmp ne i32 %14, 0
%16 = zext i1 %15 to i64
%17 = select i1 %15, i32 1, i32 0
%18 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%19 = load i32*, i32** %18
%20 = load i64, i64* @VMIN
%21 = getelementptr inbounds i32, i32* %19, i64 %20
store i32 %17, i32* %21
%22 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%23 = load i32*, i32** %22
%24 = load i64, i64* @VTIME
%25 = getelementptr inbounds i32, i32* %23, i64 %24
store i32 5, i32* %25
%26 = load i32, i32* %3
%27 = load i32, i32* @TCSANOW
%28 = call i64 @tcsetattr(i32 %26, i32 %27, %struct.termios* %5)
%29 = icmp slt i64 %28, 0
br i1 %29, label %30, label %34
30: ; preds = %13
%31 = load i32, i32* @errno
%32 = call i8* @strerror(i32 %31)
%33 = call i32 @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i8* %32)
br label %34
34: ; preds = %9, %30, %13
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32* }
@.str = [21 x i8] c"Error tcgetattr: %s\0A\00"
@errno = global i32 0
@VMIN = global i64 0
@VTIME = global i64 0
@TCSANOW = global i32 0
@.str.1 = [21 x i8] c"Error tcsetattr: %s\0A\00"
define void @set_mincount(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i64 @tcgetattr(i32 %0, %struct.termios* %3)
%6 = icmp slt i64 %5, 0
br i1 %6, label %19, label %7
7: ; preds = %2
%8 = icmp ne i32 %1, 0
%9 = zext i1 %8 to i32
%10 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%11 = load i32*, i32** %10
%12 = load i64, i64* @VMIN
%13 = getelementptr inbounds i32, i32* %11, i64 %12
store i32 %9, i32* %13
%14 = load i64, i64* @VTIME
%15 = getelementptr inbounds i32, i32* %11, i64 %14
store i32 5, i32* %15
%16 = load i32, i32* @TCSANOW
%17 = call i64 @tcsetattr(i32 %0, i32 %16, %struct.termios* %3)
%18 = icmp slt i64 %17, 0
br i1 %18, label %19, label %24
19: ; preds = %7, %2
%20 = phi i8* [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), %7 ]
%21 = load i32, i32* @errno
%22 = call i8* @strerror(i32 %21)
%23 = call i32 @printf(i8* %20, i8* %22)
br label %24
24: ; preds = %19, %7
ret void
}