#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 O_CREAT;
int O_EXCL;
int O_TRUNC;
int O_WRONLY;
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int open(char const *, int, int);
int /*<<< orphan*/ 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);
      scanf("%c", &c);
      if (c != 'Y' && c != 'y') {
        fprintf(stderr, "[bgzip] not overwritten\n");
        exit(1);
      }
    }
  }
  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(1);
    }
  }
  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    1228 <write_open+0xe8>
mov    -0x8(%rbp),%rdi
mov    0x2e3d(%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    1223 <write_open+0xe3>
mov    0x2e13(%rip),%rax
mov    (%rax),%rax
mov    0x2e21(%rip),%rcx
cmp    (%rcx),%rax
jne    1223 <write_open+0xe3>
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>
movsbl -0x11(%rbp),%eax
cmp    $0x59,%eax
je     121e <write_open+0xde>
movsbl -0x11(%rbp),%eax
cmp    $0x79,%eax
je     121e <write_open+0xde>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1223 <write_open+0xe3>
jmp    1228 <write_open+0xe8>
cmpl   $0x0,-0x10(%rbp)
jge    1291 <write_open+0x151>
mov    -0x8(%rbp),%rdi
mov    0x2d6b(%rip),%rax
mov    (%rax),%esi
mov    0x2db2(%rip),%rax
or     (%rax),%esi
mov    0x2da1(%rip),%rax
or     (%rax),%esi
mov    $0x1b6,%edx
call   1050 <open@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jge    128c <write_open+0x14c>
mov    0x2d5a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xde0(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
jmp    1291 <write_open+0x151>
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     119b <write_open+0x5b>
mov    0x2e56(%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    11d0 <write_open+0x90>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xed4(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    0x2e06(%rip),%rax
mov    0x2e4f(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e3c(%rip),%rax
or     (%rax),%esi
mov    0x2e03(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
mov    $0x1b6,%edx
call   1050 <open@plt>
test   %eax,%eax
js     11d8 <write_open+0x98>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd9(%rip),%rax
mov    (%rax),%rax
mov    0x2de7(%rip),%rcx
cmp    (%rcx),%rax
jne    114b <write_open+0xb>
mov    0x2dcf(%rip),%r14
mov    (%r14),%edi
lea    0xdfd(%rip),%rsi
mov    %rbx,%rdx
xor    %eax,%eax
call   1030 <fprintf@plt>
lea    0xe2b(%rip),%rdi
lea    0x7(%rsp),%rsi
call   1040 <scanf@plt>
mov    0x7(%rsp),%al
and    $0xdf,%al
cmp    $0x59,%al
je     114b <write_open+0xb>
mov    (%r14),%edi
lea    0xe0c(%rip),%rsi
xor    %eax,%eax
call   1030 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

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"
@.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 %42, 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 %41
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 %41
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 = load i8, i8* %6
%30 = sext i8 %29 to i32
%31 = icmp ne i32 %30, 89
br i1 %31, label %32, label %40
32: ; preds = %24
%33 = load i8, i8* %6
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 121
br i1 %35, label %36, label %40
36: ; preds = %32
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%39 = call i32 @exit(i32 1)
unreachable
40: ; preds = %32, %24
br label %41
41: ; preds = %40, %20, %9
br label %42
42: ; preds = %41, %2
%43 = load i32, i32* %5
%44 = icmp slt i32 %43, 0
br i1 %44, label %45, label %60
45: ; preds = %42
%46 = load i8*, i8** %3
%47 = load i32, i32* @O_WRONLY
%48 = load i32, i32* @O_CREAT
%49 = or i32 %47, %48
%50 = load i32, i32* @O_TRUNC
%51 = or i32 %49, %50
%52 = call i32 @open(i8* %46, i32 %51, i32 438)
store i32 %52, i32* %5
%53 = icmp slt i32 %52, 0
br i1 %53, label %54, label %59
54: ; preds = %45
%55 = load i32, i32* @stderr
%56 = load i8*, i8** %3
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %56)
%58 = call i32 @exit(i32 1)
unreachable
59: ; preds = %45
br label %60
60: ; preds = %59, %42
%61 = load i32, i32* %5
ret i32 %61
}

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"
@.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 %30
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 %42
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 %30
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 = load i8, i8* %3
%24 = and i8 %23, -33
%25 = icmp eq i8 %24, 89
br i1 %25, label %30, label %26
26: ; preds = %19
%27 = load i32, i32* @stderr
%28 = call i32 (i32, i8*, ...) @fprintf(i32 %27, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.2, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %2, %19, %15
%31 = load i32, i32* @O_WRONLY
%32 = load i32, i32* @O_CREAT
%33 = or i32 %32, %31
%34 = load i32, i32* @O_TRUNC
%35 = or i32 %33, %34
%36 = call i32 @open(i8* %0, i32 %35, i32 438)
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %42
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.3, i64 0, i64 0), i8* %0)
%41 = call i32 @exit(i32 1)
unreachable
42: ; preds = %5, %30
%43 = phi i32 [ %36, %30 ], [ %13, %5 ]
ret i32 %43
}