#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;
};
typedef int mode_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int S_IWGRP;
int /*<<< orphan*/ chmod(char *, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stat(char *, struct stat *);
int /*<<< orphan*/ *strchr(char *, char);
char tolower(char);
char *ttyname(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 2 || strchr("yYnN", *argv[1]) == NULL) {
    printf("Usage: %s [y|n]\n", argv[0]);
    exit(EXIT_FAILURE);
  }
  char respone = tolower(*argv[1]);
  char *tty_name = ttyname(0);
  struct stat tty;
  stat(tty_name, &tty);
  mode_t mode = tty.st_mode;
  if (respone == 'y') {
    chmod(tty_name, mode | S_IWGRP);
  } else {
    chmod(tty_name, mode & ~S_IWGRP);
  }
  return EXIT_SUCCESS;
}


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)
cmpl   $0x2,-0x8(%rbp)
jne    11b1 <main+0x41>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
lea    0xe61(%rip),%rdi
movsbl (%rax),%esi
call   1030 <strchr@plt>
cmp    $0x0,%rax
jne    11d2 <main+0x62>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
movsbl (%rax),%edi
call   1060 <tolower@plt>
mov    %al,-0x11(%rbp)
xor    %edi,%edi
call   1070 <ttyname@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1050 <stat@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x2c(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x79,%eax
jne    122a <main+0xba>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x2dca(%rip),%rax
or     (%rax),%esi
call   1080 <chmod@plt>
jmp    1244 <main+0xd4>
mov    -0x20(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
xor    $0xffffffff,%eax
and    %eax,%esi
call   1080 <chmod@plt>
mov    0x2d85(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    11e9 <main+0x79>
mov    0x8(%rbx),%rax
movsbl (%rax),%esi
lea    0xe77(%rip),%rdi
call   1030 <strchr@plt>
test   %rax,%rax
je     11e9 <main+0x79>
mov    0x8(%rbx),%rax
movsbl (%rax),%edi
call   1060 <tolower@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1070 <ttyname@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1050 <stat@plt>
mov    (%rsp),%eax
mov    0x2e28(%rip),%rcx
mov    (%rcx),%esi
mov    %esi,%ecx
not    %ecx
and    %eax,%ecx
or     %eax,%esi
cmp    $0x79,%bpl
cmovne %ecx,%esi
mov    %rbx,%rdi
call   1080 <chmod@plt>
mov    0x2df0(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
mov    (%rbx),%rsi
lea    0xe12(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"yYnN\00"
@.str.1 = [17 x i8] c"Usage: %s [y|n]\0A\00"
@EXIT_FAILURE = global i32 0
@S_IWGRP = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8
%7 = alloca i8*
%8 = alloca %struct.stat
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %19, label %12
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = load i8, i8* %15
%17 = call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %26
19: ; preds = %12, %2
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 0
%22 = load i8*, i8** %21
%23 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %12
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i8, i8* %29
%31 = call signext i8 @tolower(i8 signext %30)
store i8 %31, i8* %6
%32 = call i8* @ttyname(i32 0)
store i8* %32, i8** %7
%33 = load i8*, i8** %7
%34 = call i32 @stat(i8* %33, %struct.stat* %8)
%35 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%36 = load i32, i32* %35
store i32 %36, i32* %9
%37 = load i8, i8* %6
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 121
br i1 %39, label %40, label %46
40: ; preds = %26
%41 = load i8*, i8** %7
%42 = load i32, i32* %9
%43 = load i32, i32* @S_IWGRP
%44 = or i32 %42, %43
%45 = call i32 @chmod(i8* %41, i32 %44)
br label %53
46: ; preds = %26
%47 = load i8*, i8** %7
%48 = load i32, i32* %9
%49 = load i32, i32* @S_IWGRP
%50 = xor i32 %49, -1
%51 = and i32 %48, %50
%52 = call i32 @chmod(i8* %47, i32 %51)
br label %53
53: ; preds = %46, %40
%54 = load i32, i32* @EXIT_SUCCESS
ret i32 %54
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"yYnN\00"
@.str.1 = [17 x i8] c"Usage: %s [y|n]\0A\00"
@EXIT_FAILURE = global i32 0
@S_IWGRP = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %11
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i8, i8* %7
%9 = tail call i32* @strchr(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %8)
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %16
11: ; preds = %5, %2
%12 = load i8*, i8** %1
%13 = tail call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %5
%17 = load i8*, i8** %6
%18 = load i8, i8* %17
%19 = tail call signext i8 @tolower(i8 signext %18)
%20 = tail call i8* @ttyname(i32 0)
%21 = bitcast %struct.stat* %3 to i8*
%22 = call i32 @stat(i8* %20, %struct.stat* %3)
%23 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%24 = load i32, i32* %23
%25 = icmp eq i8 %19, 121
%26 = load i32, i32* @S_IWGRP
%27 = xor i32 %26, -1
%28 = and i32 %24, %27
%29 = or i32 %26, %24
%30 = select i1 %25, i32 %29, i32 %28
%31 = tail call i32 @chmod(i8* %20, i32 %30)
%32 = load i32, i32* @EXIT_SUCCESS
ret i32 %32
}