#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 */
size_t VMIN;
size_t VTIME;
int /*<<< orphan*/ memset(struct termios *, int /*<<< orphan*/, int);
scalar_t__ tcgetattr(int, struct termios *);
void set_blocking(int fd, int should_block) {
  struct termios tty;
  memset(&tty, 0, sizeof tty);
  if (tcgetattr(fd, &tty) != 0) {
    return;
  }
  tty.c_cc[VMIN] = should_block ? 1 : 0;
  tty.c_cc[VTIME] = 5;
}


x86 assembly (clang, -O0):
<set_blocking>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    -0x4(%rbp),%edi
lea    -0x10(%rbp),%rsi
call   1040 <tcgetattr@plt>
cmp    $0x0,%rax
je     1159 <set_blocking+0x39>
jmp    118f <set_blocking+0x6f>
mov    -0x8(%rbp),%ecx
xor    %edx,%edx
mov    $0x1,%eax
cmp    $0x0,%ecx
cmovne %eax,%edx
mov    -0x10(%rbp),%rax
mov    0x2e74(%rip),%rcx
mov    (%rcx),%rcx
mov    %edx,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
mov    0x2e53(%rip),%rcx
mov    (%rcx),%rcx
movl   $0x5,(%rax,%rcx,4)
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_blocking>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%r14d
mov    %edi,%ebp
lea    0x8(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1030 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
call   1040 <tcgetattr@plt>
test   %rax,%rax
jne    117b <set_blocking+0x5b>
xor    %eax,%eax
test   %r14d,%r14d
setne  %al
mov    0x8(%rsp),%rcx
mov    0x2e84(%rip),%rdx
mov    (%rdx),%rdx
mov    %eax,(%rcx,%rdx,4)
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
movl   $0x5,(%rcx,%rax,4)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32* }
@VMIN = global i64 0
@VTIME = global i64 0
define void @set_blocking(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 = call i32 @memset(%struct.termios* %5, i32 0, i32 8)
%7 = load i32, i32* %3
%8 = call i64 @tcgetattr(i32 %7, %struct.termios* %5)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
br label %24
11: ; preds = %2
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
%14 = zext i1 %13 to i64
%15 = select i1 %13, i32 1, i32 0
%16 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%17 = load i32*, i32** %16
%18 = load i64, i64* @VMIN
%19 = getelementptr inbounds i32, i32* %17, i64 %18
store i32 %15, i32* %19
%20 = getelementptr inbounds %struct.termios, %struct.termios* %5, i32 0, i32 0
%21 = load i32*, i32** %20
%22 = load i64, i64* @VTIME
%23 = getelementptr inbounds i32, i32* %21, i64 %22
store i32 5, i32* %23
br label %24
24: ; preds = %11, %10
ret void
}

LLVM IR (-O2):
%struct.termios = type { i32* }
@VMIN = global i64 0
@VTIME = global i64 0
define void @set_blocking(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
%5 = call i32 @memset(%struct.termios* %3, i32 0, i32 8)
%6 = call i64 @tcgetattr(i32 %0, %struct.termios* %3)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = icmp ne i32 %1, 0
%10 = zext i1 %9 to i32
%11 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%12 = load i32*, i32** %11
%13 = load i64, i64* @VMIN
%14 = getelementptr inbounds i32, i32* %12, i64 %13
store i32 %10, i32* %14
%15 = load i64, i64* @VTIME
%16 = getelementptr inbounds i32, i32* %12, i64 %15
store i32 5, i32* %16
br label %17
17: ; preds = %2, %8
ret void
}