#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 */
typedef int off_t;

/* Variables and functions */
int O_CREAT;
int O_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int S_IRGRP;
int S_IROTH;
int S_IRUSR;
int S_IWUSR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int, int);
scalar_t__ strlen(char const *);
int /*<<< orphan*/ strncmp(char *, char *, scalar_t__);
scalar_t__ write(int, char const *, scalar_t__);
int main(int argc, char **argv) {
  if (argc < 3) {
    err_sys("./hole [HOLE/REG] filename");
  }
  static const char lowercase[] = "abcdefghijklmnopqrstuvwxyz";
  static const char uppercase[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  char *filename = argv[2];
  char *mode = argv[1];
  int fd;
  if ((fd = open(filename, O_WRONLY | O_CREAT,
                 S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) < 0) {
    err_sys("open err");
  }
  if (write(fd, lowercase, strlen(lowercase)) != strlen(lowercase)) {
    err_sys("write lowercase");
  }
  if (!strncmp(mode, "HOLE", strlen("HOLE") + 1))
    lseek(fd, (off_t)1 << 10, SEEK_CUR);
  if (write(fd, uppercase, strlen(uppercase)) != strlen(uppercase)) {
    err_sys("write uppercase");
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    119c <main+0x2c>
lea    0xe69(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2de9(%rip),%rax
mov    (%rax),%esi
mov    0x2e30(%rip),%rax
or     (%rax),%esi
mov    0x2de7(%rip),%rax
mov    (%rax),%edx
mov    0x2dfe(%rip),%rax
or     (%rax),%edx
mov    0x2de5(%rip),%rax
or     (%rax),%edx
mov    0x2dd4(%rip),%rax
or     (%rax),%edx
call   1090 <open@plt>
mov    %eax,-0x24(%rbp)
cmp    $0x0,%eax
jge    120b <main+0x9b>
lea    0xe15(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x34(%rbp)
lea    0xe38(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x34(%rbp),%edi
mov    %rax,%rdx
lea    0xe26(%rip),%rsi
call   1050 <write@plt>
mov    %rax,-0x30(%rbp)
lea    0xe16(%rip),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x30(%rbp),%rax
cmp    %rcx,%rax
je     125b <main+0xeb>
lea    0xdce(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xdca(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rdx
add    $0x1,%rdx
lea    0xdb3(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    12a5 <main+0x135>
mov    -0x24(%rbp),%edi
mov    0x2d47(%rip),%rax
mov    (%rax),%edx
mov    $0x400,%esi
call   1070 <lseek@plt>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4c(%rbp)
lea    0xdbe(%rip),%rdi
call   1060 <strlen@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rdx
lea    0xdac(%rip),%rsi
call   1050 <write@plt>
mov    %rax,-0x48(%rbp)
lea    0xd9c(%rip),%rdi
call   1060 <strlen@plt>
mov    %rax,%rcx
mov    -0x48(%rbp),%rax
cmp    %rcx,%rax
je     12f5 <main+0x185>
lea    0xd49(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x24(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jg     1178 <main+0x18>
lea    0xe8d(%rip),%rdi
call   1040 <err_sys@plt>
mov    0x2e29(%rip),%rax
mov    0x2e72(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e27(%rip),%rax
mov    0x2e40(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
mov    0x8(%rbx),%r14
mov    0x2e21(%rip),%rax
or     (%rax),%edx
mov    0x10(%rbx),%rdi
mov    0x2e0c(%rip),%rax
or     (%rax),%edx
call   1080 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    11cd <main+0x6d>
lea    0xe53(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xe7c(%rip),%rsi
mov    $0x1a,%edx
mov    %ebx,%edi
call   1050 <write@plt>
cmp    $0x1a,%rax
je     11f2 <main+0x92>
lea    0xe37(%rip),%rdi
call   1040 <err_sys@plt>
lea    0xe3b(%rip),%rsi
mov    $0x5,%edx
mov    %r14,%rdi
call   1030 <strncmp@plt>
test   %eax,%eax
jne    121f <main+0xbf>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x400,%esi
call   1060 <lseek@plt>
lea    0xe4a(%rip),%rsi
mov    $0x1a,%edx
mov    %ebx,%edi
call   1050 <write@plt>
cmp    $0x1a,%rax
je     1244 <main+0xe4>
lea    0xdfa(%rip),%rdi
call   1040 <err_sys@plt>
mov    %ebx,%edi
call   1070 <close@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [27 x i8] c"./hole [HOLE/REG] filename\00"
@main.lowercase = internal constant [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@main.uppercase = internal constant [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [9 x i8] c"open err\00"
@.str.2 = [16 x i8] c"write lowercase\00"
@.str.3 = [5 x i8] c"HOLE\00"
@SEEK_CUR = global i32 0
@.str.4 = [16 x i8] c"write uppercase\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @err_sys(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
%16 = load i8*, i8** %15
store i8* %16, i8** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %7
%20 = load i8*, i8** %6
%21 = load i32, i32* @O_WRONLY
%22 = load i32, i32* @O_CREAT
%23 = or i32 %21, %22
%24 = load i32, i32* @S_IRUSR
%25 = load i32, i32* @S_IWUSR
%26 = or i32 %24, %25
%27 = load i32, i32* @S_IRGRP
%28 = or i32 %26, %27
%29 = load i32, i32* @S_IROTH
%30 = or i32 %28, %29
%31 = call i32 @open(i8* %20, i32 %23, i32 %30)
store i32 %31, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %13
%34 = call i32 @err_sys(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %35
35: ; preds = %33, %13
%36 = load i32, i32* %8
%37 = call i64 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.lowercase, i64 0, i64 0))
%38 = call i64 @write(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.lowercase, i64 0, i64 0), i64 %37)
%39 = call i64 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.lowercase, i64 0, i64 0))
%40 = icmp ne i64 %38, %39
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %43
43: ; preds = %41, %35
%44 = load i8*, i8** %7
%45 = call i64 @strlen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%46 = add nsw i64 %45, 1
%47 = call i32 @strncmp(i8* %44, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %53, label %49
49: ; preds = %43
%50 = load i32, i32* %8
%51 = load i32, i32* @SEEK_CUR
%52 = call i32 @lseek(i32 %50, i32 1024, i32 %51)
br label %53
53: ; preds = %49, %43
%54 = load i32, i32* %8
%55 = call i64 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.uppercase, i64 0, i64 0))
%56 = call i64 @write(i32 %54, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.uppercase, i64 0, i64 0), i64 %55)
%57 = call i64 @strlen(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.uppercase, i64 0, i64 0))
%58 = icmp ne i64 %56, %57
br i1 %58, label %59, label %61
59: ; preds = %53
%60 = call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %61
61: ; preds = %59, %53
%62 = load i32, i32* %8
%63 = call i32 @close(i32 %62)
ret i32 0
}

LLVM IR (-O2):
@.str = [27 x i8] c"./hole [HOLE/REG] filename\00"
@main.lowercase = internal constant [27 x i8] c"abcdefghijklmnopqrstuvwxyz\00"
@main.uppercase = internal constant [27 x i8] c"ABCDEFGHIJKLMNOPQRSTUVWXYZ\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@S_IRGRP = global i32 0
@S_IROTH = global i32 0
@.str.1 = [9 x i8] c"open err\00"
@.str.2 = [16 x i8] c"write lowercase\00"
@.str.3 = [5 x i8] c"HOLE\00"
@SEEK_CUR = global i32 0
@.str.4 = [16 x i8] c"write uppercase\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @err_sys(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0))
br label %6
6: ; preds = %4, %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
%8 = load i8*, i8** %7
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = load i32, i32* @O_WRONLY
%12 = load i32, i32* @O_CREAT
%13 = or i32 %12, %11
%14 = load i32, i32* @S_IRUSR
%15 = load i32, i32* @S_IWUSR
%16 = or i32 %15, %14
%17 = load i32, i32* @S_IRGRP
%18 = or i32 %16, %17
%19 = load i32, i32* @S_IROTH
%20 = or i32 %18, %19
%21 = tail call i32 @open(i8* %8, i32 %13, i32 %20)
%22 = icmp slt i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %6
%24 = tail call i32 @err_sys(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %6
%26 = tail call i64 @write(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.lowercase, i64 0, i64 0), i64 26)
%27 = icmp eq i64 %26, 26
br i1 %27, label %30, label %28
28: ; preds = %25
%29 = tail call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %30
30: ; preds = %28, %25
%31 = tail call i32 @strncmp(i8* dereferenceable(1) %10, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i64 5)
%32 = icmp eq i32 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %30
%34 = load i32, i32* @SEEK_CUR
%35 = tail call i32 @lseek(i32 %21, i32 1024, i32 %34)
br label %36
36: ; preds = %33, %30
%37 = tail call i64 @write(i32 %21, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @main.uppercase, i64 0, i64 0), i64 26)
%38 = icmp eq i64 %37, 26
br i1 %38, label %41, label %39
39: ; preds = %36
%40 = tail call i32 @err_sys(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %41
41: ; preds = %39, %36
%42 = tail call i32 @close(i32 %21)
ret i32 0
}