#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 O_NDELAY;
int O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
scalar_t__ strncmp(char *, char *, int);
scalar_t__ vhangup();
int main(int argc, char **argv) {
  int fd;
  if (argc != 2 || strncmp(argv[1], "/dev/", 5) != 0) {
    fprintf(stderr, "usage: %s /dev/tty<x>\n", argv[0]);
    exit(1);
  }
  if ((fd = open(argv[1], O_RDWR | O_NDELAY)) < 0) {
    fprintf(stderr, "%s: can't open %s: %s\n", argv[0], argv[1],
            strerror(errno));
    exit(2);
  }
  if (vhangup() < 0) {
    fprintf(stderr, "%s: vhangup() failed: %s\n", argv[0], strerror(errno));
    exit(3);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    11b3 <main+0x43>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe61(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     11db <main+0x6b>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfe(%rip),%rax
mov    (%rax),%esi
mov    0x2dd5(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    125d <main+0xed>
mov    0x2dcb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    0x2da0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    %rax,%r8
lea    0xdd1(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   1070 <vhangup@plt>
cmp    $0x0,%rax
jge    12b5 <main+0x145>
mov    0x2d63(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d44(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xd90(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11d1 <main+0x61>
mov    0x8(%rbx),%rdi
lea    0xe79(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    11d1 <main+0x61>
mov    0x8(%rbx),%rdi
mov    0x2e47(%rip),%rax
mov    0x2e20(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
call   1060 <open@plt>
test   %eax,%eax
js     11f5 <main+0x85>
mov    %eax,%ebp
xor    %eax,%eax
call   1070 <vhangup@plt>
test   %rax,%rax
js     1236 <main+0xc6>
mov    %ebp,%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xe22(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1080 <exit@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x8(%rbx),%rbx
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe03(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2d87(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xddd(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x3,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [6 x i8] c"/dev/\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"usage: %s /dev/tty<x>\0A\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.2 = [23 x i8] c"%s: can't open %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [26 x i8] c"%s: vhangup() failed: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %15, label %9
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %22
15: ; preds = %9, %2
%16 = load i32, i32* @stderr
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 0
%19 = load i8*, i8** %18
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = call i32 @exit(i32 1)
unreachable
22: ; preds = %9
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDWR
%27 = load i32, i32* @O_NDELAY
%28 = or i32 %26, %27
%29 = call i32 @open(i8* %25, i32 %28)
store i32 %29, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %43
31: ; preds = %22
%32 = load i32, i32* @stderr
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 0
%35 = load i8*, i8** %34
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 1
%38 = load i8*, i8** %37
%39 = load i32, i32* @errno
%40 = call i8* @strerror(i32 %39)
%41 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %35, i8* %38, i8* %40)
%42 = call i32 @exit(i32 2)
unreachable
43: ; preds = %22
%44 = call i64 (...) @vhangup()
%45 = icmp slt i64 %44, 0
br i1 %45, label %46, label %55
46: ; preds = %43
%47 = load i32, i32* @stderr
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 0
%50 = load i8*, i8** %49
%51 = load i32, i32* @errno
%52 = call i8* @strerror(i32 %51)
%53 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %50, i8* %52)
%54 = call i32 @exit(i32 3)
unreachable
55: ; preds = %43
%56 = load i32, i32* %6
%57 = call i32 @close(i32 %56)
ret i32 0
}

LLVM IR (-O2):
@.str = [6 x i8] c"/dev/\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"usage: %s /dev/tty<x>\0A\00"
@O_RDWR = global i32 0
@O_NDELAY = global i32 0
@.str.2 = [23 x i8] c"%s: can't open %s: %s\0A\00"
@errno = global i32 0
@.str.3 = [26 x i8] c"%s: vhangup() failed: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strncmp(i8* %6, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i32 5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %4, %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = load i32, i32* @O_RDWR
%17 = load i32, i32* @O_NDELAY
%18 = or i32 %17, %16
%19 = tail call i32 @open(i8* %15, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %14
%22 = load i32, i32* @stderr
%23 = load i8*, i8** %1
%24 = load i8*, i8** %5
%25 = load i32, i32* @errno
%26 = tail call i8* @strerror(i32 %25)
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i8* %23, i8* %24, i8* %26)
%28 = tail call i32 @exit(i32 2)
unreachable
29: ; preds = %14
%30 = tail call i64 (...) @vhangup()
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %1
%35 = load i32, i32* @errno
%36 = tail call i8* @strerror(i32 %35)
%37 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %34, i8* %36)
%38 = tail call i32 @exit(i32 3)
unreachable
39: ; preds = %29
%40 = tail call i32 @close(i32 %19)
ret i32 0
}