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

/* Variables and functions */
int /*<<< orphan*/ EINVAL;
int _ioctl(int, char, int);
int /*<<< orphan*/ errno;
int tcgetattr(int, struct termios *);
int write(int, int /*<<< orphan*/ *, int);
int tcflow(int fd, int action) {
  struct termios t;
  switch (action) {
  case 0:
  case 1:
    return _ioctl(fd, (('T' << 8) | 6), action);
  case 2:
    if (tcgetattr(fd, &t) == -1)
      return -1;
    if (tcgetattr(fd, &t) == -1)
      return -1;
    if (write(fd, &t.c_cc[12], 1) == 1)
      return 0;
    else
      return -1;
  case 3:
    if (tcgetattr(fd, &t) == -1)
      return -1;
    if (tcgetattr(fd, &t) == -1)
      return -1;
    if (write(fd, &t.c_cc[11], 1) == 1)
      return 0;
    else
      return -1;
  default:
    errno = EINVAL;
    return -1;
  }
}


x86 assembly (clang, -O0):
<tcflow>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x1c(%rbp)
sub    $0x2,%eax
jb     1174 <tcflow+0x44>
jmp    1152 <tcflow+0x22>
mov    -0x1c(%rbp),%eax
sub    $0x2,%eax
je     118c <tcflow+0x5c>
jmp    1163 <tcflow+0x33>
mov    -0x1c(%rbp),%eax
sub    $0x3,%eax
je     1204 <tcflow+0xd4>
jmp    127c <tcflow+0x14c>
mov    -0x8(%rbp),%edi
mov    -0xc(%rbp),%edx
mov    $0x6,%esi
call   1040 <_ioctl@plt>
mov    %eax,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    11ad <tcflow+0x7d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    11ce <tcflow+0x9e>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
add    $0x30,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    11f8 <tcflow+0xc8>
movl   $0x0,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1225 <tcflow+0xf5>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
mov    -0x8(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
jne    1246 <tcflow+0x116>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
mov    -0x8(%rbp),%edi
mov    -0x18(%rbp),%rsi
add    $0x2c,%rsi
mov    $0x1,%edx
call   1030 <write@plt>
cmp    $0x1,%eax
jne    1270 <tcflow+0x140>
movl   $0x0,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
movl   $0xffffffff,-0x4(%rbp)
jmp    1295 <tcflow+0x165>
mov    0x2d55(%rip),%rax
mov    (%rax),%ecx
mov    0x2d54(%rip),%rax
mov    %ecx,(%rax)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tcflow>:
push   %rbp
push   %rbx
push   %rax
mov    %esi,%edx
mov    %edi,%ebx
cmp    $0x2,%esi
jb     1178 <tcflow+0x48>
je     118a <tcflow+0x5a>
cmp    $0x3,%edx
jne    11ce <tcflow+0x9e>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1050 <tcgetattr@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11e5 <tcflow+0xb5>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     11e5 <tcflow+0xb5>
mov    (%rsp),%rsi
add    $0x2c,%rsi
jmp    11b5 <tcflow+0x85>
mov    %ebx,%edi
mov    $0x6,%esi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <_ioctl@plt>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1050 <tcgetattr@plt>
mov    $0xffffffff,%ebp
cmp    $0xffffffff,%eax
je     11e5 <tcflow+0xb5>
mov    %rsp,%rsi
mov    %ebx,%edi
call   1050 <tcgetattr@plt>
cmp    $0xffffffff,%eax
je     11e5 <tcflow+0xb5>
mov    (%rsp),%rsi
add    $0x30,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
cmp    $0x1,%eax
setne  %bpl
neg    %ebp
jmp    11e5 <tcflow+0xb5>
mov    0x2e03(%rip),%rax
mov    (%rax),%eax
mov    0x2e02(%rip),%rcx
mov    %eax,(%rcx)
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.termios = type { i32* }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tcflow(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.termios
store i32 %0, i32* %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
switch i32 %7, label %50 [
i32 0, label %8
i32 1, label %8
i32 2, label %12
i32 3, label %31
]
8: ; preds = %2, %2
%9 = load i32, i32* %4
%10 = load i32, i32* %5
%11 = call i32 @_ioctl(i32 %9, i8 signext 6, i32 %10)
store i32 %11, i32* %3
br label %52
12: ; preds = %2
%13 = load i32, i32* %4
%14 = call i32 @tcgetattr(i32 %13, %struct.termios* %6)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %12
store i32 -1, i32* %3
br label %52
17: ; preds = %12
%18 = load i32, i32* %4
%19 = call i32 @tcgetattr(i32 %18, %struct.termios* %6)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %22
21: ; preds = %17
store i32 -1, i32* %3
br label %52
22: ; preds = %17
%23 = load i32, i32* %4
%24 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%25 = load i32*, i32** %24
%26 = getelementptr inbounds i32, i32* %25, i64 12
%27 = call i32 @write(i32 %23, i32* %26, i32 1)
%28 = icmp eq i32 %27, 1
br i1 %28, label %29, label %30
29: ; preds = %22
store i32 0, i32* %3
br label %52
30: ; preds = %22
store i32 -1, i32* %3
br label %52
31: ; preds = %2
%32 = load i32, i32* %4
%33 = call i32 @tcgetattr(i32 %32, %struct.termios* %6)
%34 = icmp eq i32 %33, -1
br i1 %34, label %35, label %36
35: ; preds = %31
store i32 -1, i32* %3
br label %52
36: ; preds = %31
%37 = load i32, i32* %4
%38 = call i32 @tcgetattr(i32 %37, %struct.termios* %6)
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %41
40: ; preds = %36
store i32 -1, i32* %3
br label %52
41: ; preds = %36
%42 = load i32, i32* %4
%43 = getelementptr inbounds %struct.termios, %struct.termios* %6, i32 0, i32 0
%44 = load i32*, i32** %43
%45 = getelementptr inbounds i32, i32* %44, i64 11
%46 = call i32 @write(i32 %42, i32* %45, i32 1)
%47 = icmp eq i32 %46, 1
br i1 %47, label %48, label %49
48: ; preds = %41
store i32 0, i32* %3
br label %52
49: ; preds = %41
store i32 -1, i32* %3
br label %52
50: ; preds = %2
%51 = load i32, i32* @EINVAL
store i32 %51, i32* @errno
store i32 -1, i32* %3
br label %52
52: ; preds = %50, %49, %48, %40, %35, %30, %29, %21, %16, %8
%53 = load i32, i32* %3
ret i32 %53
}

LLVM IR (-O2):
%struct.termios = type { i32* }
@EINVAL = global i32 0
@errno = global i32 0
define i32 @tcflow(i32 %0, i32 %1) {
%3 = alloca %struct.termios
%4 = bitcast %struct.termios* %3 to i8*
switch i32 %1, label %33 [
i32 0, label %5
i32 1, label %5
i32 2, label %7
i32 3, label %20
]
5: ; preds = %2, %2
%6 = tail call i32 @_ioctl(i32 %0, i8 signext 6, i32 %1)
br label %35
7: ; preds = %2
%8 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%9 = icmp eq i32 %8, -1
br i1 %9, label %35, label %10
10: ; preds = %7
%11 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %35, label %13
13: ; preds = %10
%14 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%15 = load i32*, i32** %14
%16 = getelementptr inbounds i32, i32* %15, i64 12
%17 = call i32 @write(i32 %0, i32* %16, i32 1)
%18 = icmp ne i32 %17, 1
%19 = sext i1 %18 to i32
br label %35
20: ; preds = %2
%21 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%22 = icmp eq i32 %21, -1
br i1 %22, label %35, label %23
23: ; preds = %20
%24 = call i32 @tcgetattr(i32 %0, %struct.termios* %3)
%25 = icmp eq i32 %24, -1
br i1 %25, label %35, label %26
26: ; preds = %23
%27 = getelementptr inbounds %struct.termios, %struct.termios* %3, i64 0, i32 0
%28 = load i32*, i32** %27
%29 = getelementptr inbounds i32, i32* %28, i64 11
%30 = call i32 @write(i32 %0, i32* %29, i32 1)
%31 = icmp ne i32 %30, 1
%32 = sext i1 %31 to i32
br label %35
33: ; preds = %2
%34 = load i32, i32* @EINVAL
store i32 %34, i32* @errno
br label %35
35: ; preds = %26, %23, %20, %13, %10, %7, %33, %5
%36 = phi i32 [ -1, %33 ], [ %6, %5 ], [ -1, %7 ], [ -1, %10 ], [ %19, %13 ], [ -1, %20 ], [ -1, %23 ], [ %32, %26 ]
ret i32 %36
}