#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 EOF;
int /*<<< orphan*/ fileno(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int getchar();
int /*<<< orphan*/ isatty(int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
int permission(const char *fname) {
  int ch, first;
  if (!isatty(fileno(stderr)))
    return (0);
  (void)fprintf(stderr, "overwrite %s? ", fname);
  first = ch = getchar();
  while (ch != '\n' && ch != EOF)
    ch = getchar();
  return (first == 'y');
}


x86 assembly (clang, -O0):
<permission>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2e85(%rip),%rax
mov    (%rax),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
cmp    $0x0,%eax
jne    1176 <permission+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11eb <permission+0xab>
mov    0x2e5b(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
mov    %eax,-0x18(%rbp)
xor    %eax,%eax
cmpl   $0xa,-0x14(%rbp)
mov    %al,-0x19(%rbp)
je     11bd <permission+0x7d>
mov    -0x14(%rbp),%eax
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    11cd <permission+0x8d>
jmp    11dc <permission+0x9c>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x14(%rbp)
jmp    119c <permission+0x5c>
cmpl   $0x79,-0x18(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<permission>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    0x2e8b(%rip),%rbp
mov    0x0(%rbp),%edi
call   1060 <fileno@plt>
mov    %eax,%edi
call   1030 <isatty@plt>
test   %eax,%eax
je     11aa <permission+0x6a>
mov    0x0(%rbp),%edi
lea    0xe96(%rip),%rsi
mov    %rbx,%rdx
call   1050 <fprintf@plt>
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
cmp    $0xa,%eax
je     11a0 <permission+0x60>
mov    0x2e61(%rip),%rbx
cmp    (%rbx),%ebp
je     11a0 <permission+0x60>
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     11a0 <permission+0x60>
cmp    (%rbx),%eax
jne    1190 <permission+0x50>
xor    %eax,%eax
cmp    $0x79,%ebp
sete   %al
jmp    11ac <permission+0x6c>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"overwrite %s? \00"
@EOF = global i32 0
define i32 @permission(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
%6 = load i32, i32* @stderr
%7 = call i32 @fileno(i32 %6)
%8 = call i32 @isatty(i32 %7)
%9 = icmp ne i32 %8, 0
br i1 %9, label %11, label %10
10: ; preds = %1
store i32 0, i32* %2
br label %31
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %3
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %13)
%15 = call i32 (...) @getchar()
store i32 %15, i32* %4
store i32 %15, i32* %5
br label %16
16: ; preds = %25, %11
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 10
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %4
%21 = load i32, i32* @EOF
%22 = icmp ne i32 %20, %21
br label %23
23: ; preds = %19, %16
%24 = phi i1 [ false, %16 ], [ %22, %19 ]
br i1 %24, label %25, label %27
25: ; preds = %23
%26 = call i32 (...) @getchar()
store i32 %26, i32* %4
br label %16
27: ; preds = %23
%28 = load i32, i32* %5
%29 = icmp eq i32 %28, 121
%30 = zext i1 %29 to i32
store i32 %30, i32* %2
br label %31
31: ; preds = %27, %10
%32 = load i32, i32* %2
ret i32 %32
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"overwrite %s? \00"
@EOF = global i32 0
define i32 @permission(i8* %0) {
%2 = load i32, i32* @stderr
%3 = tail call i32 @fileno(i32 %2)
%4 = tail call i32 @isatty(i32 %3)
%5 = icmp eq i32 %4, 0
br i1 %5, label %23, label %6
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32 (...) @getchar()
%10 = icmp ne i32 %9, 10
%11 = load i32, i32* @EOF
%12 = icmp ne i32 %9, %11
%13 = select i1 %10, i1 %12, i1 false
br i1 %13, label %14, label %20
14: ; preds = %6, %14
%15 = tail call i32 (...) @getchar()
%16 = icmp ne i32 %15, 10
%17 = load i32, i32* @EOF
%18 = icmp ne i32 %15, %17
%19 = select i1 %16, i1 %18, i1 false
br i1 %19, label %14, label %20
20: ; preds = %14, %6
%21 = icmp eq i32 %9, 121
%22 = zext i1 %21 to i32
br label %23
23: ; preds = %1, %20
%24 = phi i32 [ %22, %20 ], [ 0, %1 ]
ret i32 %24
}