#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*/ STDIN_FILENO;
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
char *strerror(int /*<<< orphan*/);
char *ttyname(int /*<<< orphan*/);
int main(int argc, char **argv) {
  bool silent = false;
  if (argc > 1) {
    if (strcmp(argv[1], "--quiet")) {
      silent = true;
    } else if (strcmp(argv[1], "-s")) {
      silent = true;
    } else if (strcmp(argv[1], "--silent")) {
      silent = true;
    } else {
      fprintf(stderr, "%s: incorrect argument %s\n", argv[0], argv[1]);
      return 1;
    }
  }
  char *tty = ttyname(STDIN_FILENO);
  if (tty == NULL) {
    fprintf(stderr, "%s: %s\n", argv[0], strerror(errno));
    return 1;
  }
  if (silent == false) {
    puts(tty);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    1234 <main+0xe4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe7a(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11a1 <main+0x51>
movl   $0x1,-0x14(%rbp)
jmp    122f <main+0xdf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe58(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11cb <main+0x7b>
movl   $0x1,-0x14(%rbp)
jmp    122a <main+0xda>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe31(%rip),%rsi
call   1040 <strcmp@plt>
cmp    $0x0,%rax
je     11f5 <main+0xa5>
movl   $0x1,-0x14(%rbp)
jmp    1225 <main+0xd5>
mov    0x2de4(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
lea    0xe00(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <main+0x162>
jmp    122a <main+0xda>
jmp    122f <main+0xdf>
jmp    1234 <main+0xe4>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
call   1060 <ttyname@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1298 <main+0x148>
mov    0x2d88(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rdx
mov    %rax,%rcx
lea    0xda8(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    12b2 <main+0x162>
cmpl   $0x0,-0x14(%rbp)
jne    12ab <main+0x15b>
mov    -0x20(%rbp),%rdi
call   1030 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     11b4 <main+0x64>
mov    0x8(%rbx),%rdi
lea    0xe9a(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    119a <main+0x4a>
mov    0x8(%rbx),%rdi
lea    0xe8d(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
jne    119a <main+0x4a>
mov    0x8(%rbx),%rdi
lea    0xe7b(%rip),%rsi
call   1040 <strcmp@plt>
test   %rax,%rax
je     120d <main+0xbd>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1060 <ttyname@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    1206 <main+0xb6>
jmp    11d3 <main+0x83>
mov    0x2e15(%rip),%rax
mov    (%rax),%edi
call   1060 <ttyname@plt>
test   %rax,%rax
je     11d3 <main+0x83>
mov    %rax,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
jmp    1206 <main+0xb6>
mov    0x2e06(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe3b(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1050 <fprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    0x2dcc(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
mov    0x8(%rbx),%rcx
lea    0xdf0(%rip),%rsi
jmp    11fc <main+0xac>

LLVM IR (-O0):
@.str = [8 x i8] c"--quiet\00"
@.str.1 = [3 x i8] c"-s\00"
@.str.2 = [9 x i8] c"--silent\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"%s: incorrect argument %s\0A\00"
@STDIN_FILENO = global i32 0
@.str.4 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i32, i32* %4
%9 = icmp sgt i32 %8, 1
br i1 %9, label %10, label %43
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = call i64 @strcmp(i8* %13, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %17
16: ; preds = %10
store i32 1, i32* %6
br label %42
17: ; preds = %10
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i64 @strcmp(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
store i32 1, i32* %6
br label %41
24: ; preds = %17
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i64 @strcmp(i8* %27, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %31
30: ; preds = %24
store i32 1, i32* %6
br label %40
31: ; preds = %24
%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 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %35, i8* %38)
store i32 1, i32* %3
br label %63
40: ; preds = %30
br label %41
41: ; preds = %40, %23
br label %42
42: ; preds = %41, %16
br label %43
43: ; preds = %42, %2
%44 = load i32, i32* @STDIN_FILENO
%45 = call i8* @ttyname(i32 %44)
store i8* %45, i8** %7
%46 = load i8*, i8** %7
%47 = icmp eq i8* %46, null
br i1 %47, label %48, label %56
48: ; preds = %43
%49 = load i32, i32* @stderr
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = load i32, i32* @errno
%54 = call i8* @strerror(i32 %53)
%55 = call i32 @fprintf(i32 %49, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %52, i8* %54)
store i32 1, i32* %3
br label %63
56: ; preds = %43
%57 = load i32, i32* %6
%58 = icmp eq i32 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %56
%60 = load i8*, i8** %7
%61 = call i32 @puts(i8* %60)
br label %62
62: ; preds = %59, %56
store i32 0, i32* %3
br label %63
63: ; preds = %62, %48, %31
%64 = load i32, i32* %3
ret i32 %64
}

LLVM IR (-O2):
@.str = [8 x i8] c"--quiet\00"
@.str.1 = [3 x i8] c"-s\00"
@.str.2 = [9 x i8] c"--silent\00"
@stderr = global i32 0
@.str.3 = [27 x i8] c"%s: incorrect argument %s\0A\00"
@STDIN_FILENO = global i32 0
@.str.4 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %26
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i64 @strcmp(i8* %6, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %22
9: ; preds = %4
%10 = load i8*, i8** %5
%11 = tail call i64 @strcmp(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %9
%14 = load i8*, i8** %5
%15 = tail call i64 @strcmp(i8* %14, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %13
%18 = load i32, i32* @stderr
%19 = load i8*, i8** %1
%20 = load i8*, i8** %5
%21 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %19, i8* %20)
br label %38
22: ; preds = %13, %9, %4
%23 = load i32, i32* @STDIN_FILENO
%24 = tail call i8* @ttyname(i32 %23)
%25 = icmp eq i8* %24, null
br i1 %25, label %30, label %38
26: ; preds = %2
%27 = load i32, i32* @STDIN_FILENO
%28 = tail call i8* @ttyname(i32 %27)
%29 = icmp eq i8* %28, null
br i1 %29, label %30, label %36
30: ; preds = %26, %22
%31 = load i32, i32* @stderr
%32 = load i8*, i8** %1
%33 = load i32, i32* @errno
%34 = tail call i8* @strerror(i32 %33)
%35 = tail call i32 @fprintf(i32 %31, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i8* %32, i8* %34)
br label %38
36: ; preds = %26
%37 = tail call i32 @puts(i8* %28)
br label %38
38: ; preds = %22, %30, %36, %17
%39 = phi i32 [ 1, %17 ], [ 1, %30 ], [ 0, %36 ], [ 0, %22 ]
ret i32 %39
}