#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 stat {
  int st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ STDERR_FILENO;
int /*<<< orphan*/ chmod(char const *, int);
int /*<<< orphan*/ err(int, char *, ...);
int /*<<< orphan*/ exit(int);
int getopt(int, char **, char *);
scalar_t__ optind;
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ stat(char const *, struct stat *);
char *ttyname(int /*<<< orphan*/);
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  struct stat sb;
  int ch;
  const char *name;
  while ((ch = getopt(argc, argv, "")) != -1)
    switch (ch) {
    case '?':
    default:
      usage();
    }
  argc -= optind;
  argv += optind;
  if ((name = ttyname(STDERR_FILENO)) == NULL)
    err(2, "tty");
  if (stat(name, &sb))
    err(2, "stat");
  if (*argv == NULL) {
    (void)printf("is %s\n", sb.st_mode & 0100 ? "y" : "n");
    exit(sb.st_mode & 0100 ? 0 : 1);
  }
  switch (argv[0][0]) {
  case 'n':
    if (chmod(name, sb.st_mode & ~0100) < 0)
      err(2, "%s", name);
    break;
  case 'y':
    if (chmod(name, sb.st_mode | 0100) < 0)
      err(2, "%s", name);
    break;
  default:
    usage();
  }
  exit(sb.st_mode & 0100 ? 0 : 1);
}


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)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe6b(%rip),%rdx
call   1090 <getopt@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xffffffff,%eax
je     11d7 <main+0x57>
mov    -0x1c(%rbp),%eax
sub    $0x3f,%eax
jne    11cb <main+0x4b>
jmp    11c6 <main+0x46>
jmp    11cb <main+0x4b>
mov    $0x0,%al
call   1070 <usage@plt>
jmp    1196 <main+0x16>
mov    0x2e0a(%rip),%rax
mov    (%rax),%rcx
movslq -0x8(%rbp),%rax
sub    %rcx,%rax
mov    %eax,-0x8(%rbp)
mov    0x2df6(%rip),%rax
mov    (%rax),%rax
shl    $0x3,%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1060 <ttyname@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    1230 <main+0xb0>
mov    $0x2,%edi
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x28(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
je     125a <main+0xda>
mov    $0x2,%edi
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12a7 <main+0x127>
mov    -0x18(%rbp),%ecx
and    $0x40,%ecx
lea    0xd9b(%rip),%rsi
lea    0xd86(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rsi
lea    0xd7f(%rip),%rdi
call   1030 <printf@plt>
mov    -0x18(%rbp),%ecx
and    $0x40,%ecx
mov    $0x1,%edi
xor    %eax,%eax
cmp    $0x0,%ecx
cmovne %eax,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movsbl (%rax),%eax
mov    %eax,-0x2c(%rbp)
sub    $0x6e,%eax
je     12d3 <main+0x153>
jmp    12c2 <main+0x142>
mov    -0x2c(%rbp),%eax
sub    $0x79,%eax
je     1307 <main+0x187>
jmp    133b <main+0x1bb>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
and    $0xffffffbf,%esi
call   1080 <chmod@plt>
cmp    $0x0,%eax
jge    1302 <main+0x182>
mov    -0x28(%rbp),%rdx
mov    $0x2,%edi
lea    0xd17(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
jmp    1342 <main+0x1c2>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%esi
or     $0x40,%esi
call   1080 <chmod@plt>
cmp    $0x0,%eax
jge    1336 <main+0x1b6>
mov    -0x28(%rbp),%rdx
mov    $0x2,%edi
lea    0xce3(%rip),%rsi
mov    $0x0,%al
call   1050 <err@plt>
jmp    1342 <main+0x1c2>
mov    $0x0,%al
call   1070 <usage@plt>
mov    -0x18(%rbp),%ecx
and    $0x40,%ecx
mov    $0x1,%edi
xor    %eax,%eax
cmp    $0x0,%ecx
cmovne %eax,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %edi,%ebp
lea    0xe7c(%rip),%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x49>
lea    0xe6b(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1070 <usage@plt>
mov    %ebp,%edi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1090 <getopt@plt>
cmp    $0xffffffff,%eax
jne    11b0 <main+0x30>
mov    0x2e18(%rip),%rax
mov    (%rax),%rbx
mov    0x2dfe(%rip),%rax
mov    (%rax),%edi
call   1060 <ttyname@plt>
mov    %rax,%r14
test   %rax,%rax
jne    11fc <main+0x7c>
lea    0xe10(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1050 <err@plt>
mov    %rsp,%rsi
mov    %r14,%rdi
call   1040 <stat@plt>
test   %rax,%rax
je     121f <main+0x9f>
lea    0xdf1(%rip),%rsi
mov    $0x2,%edi
xor    %eax,%eax
call   1050 <err@plt>
mov    (%r15,%rbx,8),%rax
test   %rax,%rax
jne    124c <main+0xcc>
testb  $0x40,(%rsp)
lea    0xddd(%rip),%rax
lea    0xdc8(%rip),%rsi
cmove  %rax,%rsi
lea    0xdc4(%rip),%rdi
call   1030 <printf@plt>
jmp    1292 <main+0x112>
movsbl (%rax),%eax
cmp    $0x79,%eax
je     1261 <main+0xe1>
cmp    $0x6e,%eax
jne    128b <main+0x10b>
mov    (%rsp),%esi
and    $0xffffffbf,%esi
jmp    1267 <main+0xe7>
mov    (%rsp),%esi
or     $0x40,%esi
mov    %r14,%rdi
call   1080 <chmod@plt>
test   %eax,%eax
jns    1292 <main+0x112>
lea    0xd98(%rip),%rsi
mov    $0x2,%edi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <err@plt>
jmp    1292 <main+0x112>
xor    %eax,%eax
call   1070 <usage@plt>
xor    %edi,%edi
testb  $0x40,(%rsp)
sete   %dil
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@STDERR_FILENO = global i32 0
@.str.1 = [4 x i8] c"tty\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [7 x i8] c"is %s\0A\00"
@.str.4 = [2 x i8] c"y\00"
@.str.5 = [2 x i8] c"n\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca %struct.stat
%7 = alloca i32
%8 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %19, %2
%10 = load i32, i32* %4
%11 = load i8**, i8*** %5
%12 = call i32 @getopt(i32 %10, i8** %11, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 %12, i32* %7
%13 = icmp ne i32 %12, -1
br i1 %13, label %14, label %20
14: ; preds = %9
%15 = load i32, i32* %7
switch i32 %15, label %17 [
i32 63, label %16
]
16: ; preds = %14
br label %17
17: ; preds = %14, %16
%18 = call i32 (...) @usage()
br label %19
19: ; preds = %17
br label %9
20: ; preds = %9
%21 = load i64, i64* @optind
%22 = load i32, i32* %4
%23 = sext i32 %22 to i64
%24 = sub nsw i64 %23, %21
%25 = trunc i64 %24 to i32
store i32 %25, i32* %4
%26 = load i64, i64* @optind
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 %26
store i8** %28, i8*** %5
%29 = load i32, i32* @STDERR_FILENO
%30 = call i8* @ttyname(i32 %29)
store i8* %30, i8** %8
%31 = icmp eq i8* %30, null
br i1 %31, label %32, label %34
32: ; preds = %20
%33 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %34
34: ; preds = %32, %20
%35 = load i8*, i8** %8
%36 = call i64 @stat(i8* %35, %struct.stat* %6)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = load i8**, i8*** %5
%42 = load i8*, i8** %41
%43 = icmp eq i8* %42, null
br i1 %43, label %44, label %59
44: ; preds = %40
%45 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%46 = load i32, i32* %45
%47 = and i32 %46, 64
%48 = icmp ne i32 %47, 0
%49 = zext i1 %48 to i64
%50 = select i1 %48, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0)
%51 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %50)
%52 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%53 = load i32, i32* %52
%54 = and i32 %53, 64
%55 = icmp ne i32 %54, 0
%56 = zext i1 %55 to i64
%57 = select i1 %55, i32 0, i32 1
%58 = call i32 @exit(i32 %57)
unreachable
59: ; preds = %40
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 0
%62 = load i8*, i8** %61
%63 = getelementptr inbounds i8, i8* %62, i64 0
%64 = load i8, i8* %63
%65 = sext i8 %64 to i32
switch i32 %65, label %88 [
i32 110, label %66
i32 121, label %77
]
66: ; preds = %59
%67 = load i8*, i8** %8
%68 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%69 = load i32, i32* %68
%70 = and i32 %69, -65
%71 = call i32 @chmod(i8* %67, i32 %70)
%72 = icmp slt i32 %71, 0
br i1 %72, label %73, label %76
73: ; preds = %66
%74 = load i8*, i8** %8
%75 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %74)
br label %76
76: ; preds = %73, %66
br label %90
77: ; preds = %59
%78 = load i8*, i8** %8
%79 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%80 = load i32, i32* %79
%81 = or i32 %80, 64
%82 = call i32 @chmod(i8* %78, i32 %81)
%83 = icmp slt i32 %82, 0
br i1 %83, label %84, label %87
84: ; preds = %77
%85 = load i8*, i8** %8
%86 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %85)
br label %87
87: ; preds = %84, %77
br label %90
88: ; preds = %59
%89 = call i32 (...) @usage()
br label %90
90: ; preds = %88, %87, %76
%91 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%92 = load i32, i32* %91
%93 = and i32 %92, 64
%94 = icmp ne i32 %93, 0
%95 = zext i1 %94 to i64
%96 = select i1 %94, i32 0, i32 1
%97 = call i32 @exit(i32 %96)
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [1 x i8] zeroinitializer
@optind = global i64 0
@STDERR_FILENO = global i32 0
@.str.1 = [4 x i8] c"tty\00"
@.str.2 = [5 x i8] c"stat\00"
@.str.3 = [7 x i8] c"is %s\0A\00"
@.str.4 = [2 x i8] c"y\00"
@.str.5 = [2 x i8] c"n\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i32 %5, -1
br i1 %6, label %11, label %7
7: ; preds = %2, %7
%8 = tail call i32 (...) @usage()
%9 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32 %9, -1
br i1 %10, label %11, label %7
11: ; preds = %7, %2
%12 = load i64, i64* @optind
%13 = getelementptr inbounds i8*, i8** %1, i64 %12
%14 = load i32, i32* @STDERR_FILENO
%15 = tail call i8* @ttyname(i32 %14)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = tail call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %11
%20 = call i64 @stat(i8* %15, %struct.stat* %3)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
%25 = load i8*, i8** %13
%26 = icmp eq i8* %25, null
br i1 %26, label %27, label %39
27: ; preds = %24
%28 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%29 = load i32, i32* %28
%30 = and i32 %29, 64
%31 = icmp eq i32 %30, 0
%32 = select i1 %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0)
%33 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), i8* %32)
%34 = load i32, i32* %28
%35 = lshr i32 %34, 6
%36 = and i32 %35, 1
%37 = xor i32 %36, 1
%38 = call i32 @exit(i32 %37)
unreachable
39: ; preds = %24
%40 = load i8, i8* %25
%41 = sext i8 %40 to i32
switch i32 %41, label %58 [
i32 110, label %42
i32 121, label %50
]
42: ; preds = %39
%43 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%44 = load i32, i32* %43
%45 = and i32 %44, -65
%46 = call i32 @chmod(i8* %15, i32 %45)
%47 = icmp slt i32 %46, 0
br i1 %47, label %48, label %60
48: ; preds = %42
%49 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %15)
br label %60
50: ; preds = %39
%51 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%52 = load i32, i32* %51
%53 = or i32 %52, 64
%54 = call i32 @chmod(i8* %15, i32 %53)
%55 = icmp slt i32 %54, 0
br i1 %55, label %56, label %60
56: ; preds = %50
%57 = call i32 (i32, i8*, ...) @err(i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %15)
br label %60
58: ; preds = %39
%59 = call i32 (...) @usage()
br label %60
60: ; preds = %50, %56, %42, %48, %58
%61 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%62 = load i32, i32* %61
%63 = lshr i32 %62, 6
%64 = and i32 %63, 1
%65 = xor i32 %64, 1
%66 = call i32 @exit(i32 %65)
unreachable
}