#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 */

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int N_PPS;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ TIOCSETD;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int ioctl(int, int /*<<< orphan*/, int *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ pause();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ usage(char *);
int main(int argc, char *argv[]) {
  int fd;
  int ldisc = N_PPS;
  int ret;
  if (argc < 2)
    usage(argv[0]);
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    perror("open");
    exit(EXIT_FAILURE);
  }
  ret = ioctl(fd, TIOCSETD, &ldisc);
  if (ret < 0) {
    perror("ioctl(TIOCSETD)");
    exit(EXIT_FAILURE);
  }
  pause();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    1198 <main+0x38>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1050 <usage@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e41(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d5 <main+0x75>
lea    0xe3e(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e02(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
lea    -0x18(%rbp),%rdx
call   1030 <ioctl@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    1211 <main+0xb1>
lea    0xe07(%rip),%rdi
call   1070 <perror@plt>
mov    0x2dc6(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1040 <pause@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x2e59(%rip),%rax
mov    (%rax),%eax
mov    %eax,0xc(%rsp)
cmp    $0x1,%edi
jg     1182 <main+0x22>
mov    (%rbx),%rdi
call   1050 <usage@plt>
mov    0x8(%rbx),%rdi
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11c0 <main+0x60>
mov    0x2e39(%rip),%rcx
mov    (%rcx),%esi
lea    0xc(%rsp),%rdx
mov    %eax,%edi
call   1030 <ioctl@plt>
test   %eax,%eax
js     11c9 <main+0x69>
xor    %eax,%eax
call   1040 <pause@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe39(%rip),%rdi
jmp    11d0 <main+0x70>
lea    0xe35(%rip),%rdi
call   1070 <perror@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@N_PPS = global i32 0
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@TIOCSETD = global i32 0
@.str.1 = [16 x i8] c"ioctl(TIOCSETD)\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* @N_PPS
store i32 %9, i32* %7
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %12, label %17
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 0
%15 = load i8*, i8** %14
%16 = call i32 @usage(i8* %15)
br label %17
17: ; preds = %12, %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = load i32, i32* @O_RDWR
%22 = call i32 @open(i8* %20, i32 %21)
store i32 %22, i32* %6
%23 = load i32, i32* %6
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %29
25: ; preds = %17
%26 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %17
%30 = load i32, i32* %6
%31 = load i32, i32* @TIOCSETD
%32 = call i32 @ioctl(i32 %30, i32 %31, i32* %7)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = icmp slt i32 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %29
%36 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%37 = load i32, i32* @EXIT_FAILURE
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %29
%40 = call i32 (...) @pause()
ret i32 0
}

LLVM IR (-O2):
@N_PPS = global i32 0
@O_RDWR = global i32 0
@.str = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@TIOCSETD = global i32 0
@.str.1 = [16 x i8] c"ioctl(TIOCSETD)\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @N_PPS
store i32 %5, i32* %3
%6 = icmp slt i32 %0, 2
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i8*, i8** %1
%9 = tail call i32 @usage(i8* %8)
br label %10
10: ; preds = %7, %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = tail call i32 @open(i8* %12, i32 %13)
%15 = icmp slt i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %10
%17 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = tail call i32 @exit(i32 %18)
unreachable
20: ; preds = %10
%21 = load i32, i32* @TIOCSETD
%22 = call i32 @ioctl(i32 %14, i32 %21, i32* %3)
%23 = icmp slt i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = call i32 @perror(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %20
%29 = call i32 (...) @pause()
ret i32 0
}