#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 */
scalar_t__ EEXIST;
int /*<<< orphan*/ EXIT_FAILURE;
int O_CREAT;
int O_EXCL;
int O_TRUNC;
int O_WRONLY;
scalar_t__ errno;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int, int);
int scanf(char *, char *);
int /*<<< orphan*/ stderr;
int write_open(const char *fn, int is_forced) {
  int fd = -1;
  char c;
  if (!is_forced) {
    if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, 0666)) < 0 &&
        errno == EEXIST) {
      fprintf(stderr,
              "[bgzip] %s already exists; do you wish to overwrite (y or n)? ",
              fn);
      if (scanf("%c", &c) != 1)
        c = 'n';
      if (c != 'Y' && c != 'y') {
        fprintf(stderr, "[bgzip] not overwritten\n");
        exit(EXIT_FAILURE);
      }
    }
  }
  if (fd < 0) {
    if ((fd = open(fn, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) {
      fprintf(stderr, "[bgzip] %s: Fail to write\n", fn);
      exit(EXIT_FAILURE);
    }
  }
  return fd;
}


x86 assembly (clang, -O0):
<write_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0xffffffff,-0x10(%rbp)
cmpl   $0x0,-0xc(%rbp)
jne    1239 <write_open+0xf9>
mov    -0x8(%rbp),%rdi
mov    0x2e35(%rip),%rax
mov    (%rax),%esi
mov    0x2e84(%rip),%rax
or     (%rax),%esi
mov    0x2e73(%rip),%rax
or     (%rax),%esi
mov    0x2e3a(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    1234 <write_open+0xf4>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%rax
jne    1234 <write_open+0xf4>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe34(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
lea    0xe65(%rip),%rdi
lea    -0x11(%rbp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
je     11f0 <write_open+0xb0>
movb   $0x6e,-0x11(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x59,%eax
je     122f <write_open+0xef>
movsbl -0x11(%rbp),%eax
cmp    $0x79,%eax
je     122f <write_open+0xef>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
lea    0xe28(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    1234 <write_open+0xf4>
jmp    1239 <write_open+0xf9>
cmpl   $0x0,-0x10(%rbp)
jge    12a6 <write_open+0x166>
mov    -0x8(%rbp),%rdi
mov    0x2d52(%rip),%rax
mov    (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
mov    0x2d90(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    12a1 <write_open+0x161>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xdcf(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    0x2d16(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
jmp    12a6 <write_open+0x166>
mov    -0x10(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_open>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
test   %esi,%esi
je     119f <write_open+0x5f>
mov    0x2e4e(%rip),%rax
mov    0x2e9f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e8c(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
test   %eax,%eax
jns    11d4 <write_open+0x94>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xed4(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    0x2e18(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
mov    0x2dfa(%rip),%rax
mov    0x2e4b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e38(%rip),%rax
or     (%rax),%esi
mov    0x2dff(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11dc <write_open+0x9c>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd5(%rip),%rax
mov    (%rax),%rax
mov    0x2de3(%rip),%rcx
cmp    (%rcx),%rax
jne    114b <write_open+0xb>
mov    0x2dcb(%rip),%r14
mov    (%r14),%edi
lea    0xdf9(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe27(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
cmp    $0x1,%eax
jne    1237 <write_open+0xf7>
mov    0x7(%rsp),%al
and    $0xdf,%al
cmp    $0x59,%al
je     114b <write_open+0xb>
jmp    123c <write_open+0xfc>
movb   $0x6e,0x7(%rsp)
mov    (%r14),%edi
lea    0xdfc(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
jmp    1191 <write_open+0x51>

LLVM IR (-O0):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [63 x i8] c"[bgzip] %s already exists; do you wish to overwrite (y or n)? \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [25 x i8] c"[bgzip] not overwritten\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [27 x i8] c"[bgzip] %s: Fail to write\0A\00"
define i32 @write_open(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 -1, i32* %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 0
br i1 %8, label %46, label %9
9: ; preds = %2
%10 = load i8*, i8** %3
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %11, %12
%14 = load i32, i32* @O_TRUNC
%15 = or i32 %13, %14
%16 = load i32, i32* @O_EXCL
%17 = or i32 %15, %16
%18 = call i32 @open(i8* %10, i32 %17, i32 438)
store i32 %18, i32* %5
%19 = icmp slt i32 %18, 0
br i1 %19, label %20, label %45
20: ; preds = %9
%21 = load i64, i64* @errno
%22 = load i64, i64* @EEXIST
%23 = icmp eq i64 %21, %22
br i1 %23, label %24, label %45
24: ; preds = %20
%25 = load i32, i32* @stderr
%26 = load i8*, i8** %3
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %25, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%29 = icmp ne i32 %28, 1
br i1 %29, label %30, label %31
30: ; preds = %24
store i8 110, i8* %6
br label %31
31: ; preds = %30, %24
%32 = load i8, i8* %6
%33 = sext i8 %32 to i32
%34 = icmp ne i32 %33, 89
br i1 %34, label %35, label %44
35: ; preds = %31
%36 = load i8, i8* %6
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 121
br i1 %38, label %39, label %44
39: ; preds = %35
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; preds = %35, %31
br label %45
45: ; preds = %44, %20, %9
br label %46
46: ; preds = %45, %2
%47 = load i32, i32* %5
%48 = icmp slt i32 %47, 0
br i1 %48, label %49, label %65
49: ; preds = %46
%50 = load i8*, i8** %3
%51 = load i32, i32* @O_WRONLY
%52 = load i32, i32* @O_CREAT
%53 = or i32 %51, %52
%54 = load i32, i32* @O_TRUNC
%55 = or i32 %53, %54
%56 = call i32 @open(i8* %50, i32 %55, i32 438)
store i32 %56, i32* %5
%57 = icmp slt i32 %56, 0
br i1 %57, label %58, label %64
58: ; preds = %49
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %3
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %60)
%62 = load i32, i32* @EXIT_FAILURE
%63 = call i32 @exit(i32 %62)
unreachable
64: ; preds = %49
br label %65
65: ; preds = %64, %46
%66 = load i32, i32* %5
ret i32 %66
}

LLVM IR (-O2):
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@O_EXCL = global i32 0
@errno = global i64 0
@EEXIST = global i64 0
@stderr = global i32 0
@.str = [63 x i8] c"[bgzip] %s already exists; do you wish to overwrite (y or n)? \00"
@.str.1 = [3 x i8] c"%c\00"
@.str.2 = [25 x i8] c"[bgzip] not overwritten\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [27 x i8] c"[bgzip] %s: Fail to write\0A\00"
define i32 @write_open(i8* %0, i32 %1) {
%3 = alloca i8
%4 = icmp eq i32 %1, 0
br i1 %4, label %5, label %34
5: ; preds = %2
%6 = load i32, i32* @O_WRONLY
%7 = load i32, i32* @O_CREAT
%8 = or i32 %7, %6
%9 = load i32, i32* @O_TRUNC
%10 = or i32 %8, %9
%11 = load i32, i32* @O_EXCL
%12 = or i32 %10, %11
%13 = tail call i32 @open(i8* %0, i32 %12, i32 438)
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %47
15: ; preds = %5
%16 = load i64, i64* @errno
%17 = load i64, i64* @EEXIST
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %34
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str, i64 0, i64 0), i8* %0)
%22 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%23 = icmp eq i32 %22, 1
br i1 %23, label %25, label %24
24: ; preds = %19
store i8 110, i8* %3
br label %29
25: ; preds = %19
%26 = load i8, i8* %3
%27 = and i8 %26, -33
%28 = icmp eq i8 %27, 89
br i1 %28, label %34, label %29
29: ; preds = %24, %25
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%32 = load i32, i32* @EXIT_FAILURE
%33 = call i32 @exit(i32 %32)
unreachable
34: ; preds = %2, %25, %15
%35 = load i32, i32* @O_WRONLY
%36 = load i32, i32* @O_CREAT
%37 = or i32 %36, %35
%38 = load i32, i32* @O_TRUNC
%39 = or i32 %37, %38
%40 = call i32 @open(i8* %0, i32 %39, i32 438)
%41 = icmp slt i32 %40, 0
br i1 %41, label %42, label %47
42: ; preds = %34
%43 = load i32, i32* @stderr
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %43, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%45 = load i32, i32* @EXIT_FAILURE
%46 = call i32 @exit(i32 %45)
unreachable
47: ; preds = %5, %34
%48 = phi i32 [ %40, %34 ], [ %13, %5 ]
ret i32 %48
}