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

/* Variables and functions */
int O_APPEND;
int O_WRONLY;
int /*<<< orphan*/ SEEK_SET;
int close(int);
int lseek(int, int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int write(int, char *, int);
int main(int argc, char **argv) {
  int inputFd;
  off_t offSet = 0;
  ssize_t numWritten;
  char *buf;
  buf = "Will this work? Maybe? Maybe not?";
  inputFd = open("/net/home/f10/awzurn/Dropbox/School/SJU/CompSci/CS350/"
                 "Homework/Assign4/assign4-2txt.txt",
                 O_WRONLY | O_APPEND);
  if (inputFd == -1) {
    printf("open error! \n");
    return -1;
  }
  offSet = lseek(inputFd, offSet, SEEK_SET);
  if (offSet == -1) {
    printf("seek error! \n");
    return -1;
  }
  numWritten = write(inputFd, buf, 33);
  if (numWritten == -1) {
    printf("write error! \n");
    return -1;
  }
  if ((close(inputFd)) == -1) {
    printf("close error! \n");
    return -1;
  }
  return 0;
}


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)
movl   $0x0,-0x18(%rbp)
lea    0xe8c(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    0x2e51(%rip),%rax
mov    (%rax),%esi
mov    0x2e40(%rip),%rax
or     (%rax),%esi
lea    0xe91(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11bb <main+0x6b>
lea    0xed0(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <main+0x10a>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    0x2e18(%rip),%rax
mov    (%rax),%edx
call   1050 <lseek@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    11f4 <main+0xa4>
lea    0xea5(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <main+0x10a>
mov    -0x14(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    $0x21,%edx
call   1030 <write@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    122a <main+0xda>
lea    0xe7d(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <main+0x10a>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
cmp    $0xffffffff,%eax
jne    1253 <main+0x103>
lea    0xe63(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    125a <main+0x10a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    0x2e78(%rip),%rax
mov    0x2e69(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11b7 <main+0x67>
mov    %eax,%ebx
mov    0x2e63(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
cmp    $0xffffffff,%eax
je     11c0 <main+0x70>
lea    0xe6c(%rip),%rsi
mov    %ebx,%edi
mov    $0x21,%edx
call   1040 <write@plt>
cmp    $0xffffffff,%eax
je     11c9 <main+0x79>
mov    %ebx,%edi
call   1060 <close@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
je     11d2 <main+0x82>
pop    %rbx
ret
lea    0xee5(%rip),%rdi
jmp    11d9 <main+0x89>
lea    0xecf(%rip),%rdi
jmp    11d9 <main+0x89>
lea    0xeb8(%rip),%rdi
jmp    11d9 <main+0x89>
lea    0xea1(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [34 x i8] c"Will this work? Maybe? Maybe not?\00"
@.str.1 = [88 x i8] c"/net/home/f10/awzurn/Dropbox/School/SJU/CompSci/CS350/Homework/Assign4/assign4-2txt.txt\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@.str.2 = [14 x i8] c"open error! \0A\00"
@SEEK_SET = global i32 0
@.str.3 = [14 x i8] c"seek error! \0A\00"
@.str.4 = [15 x i8] c"write error! \0A\00"
@.str.5 = [15 x i8] c"close error! \0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
store i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = load i32, i32* @O_WRONLY
%11 = load i32, i32* @O_APPEND
%12 = or i32 %10, %11
%13 = call i32 @open(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), i32 %12)
store i32 %13, i32* %6
%14 = load i32, i32* %6
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %18
16: ; preds = %2
%17 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
18: ; preds = %2
%19 = load i32, i32* %6
%20 = load i32, i32* %7
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @lseek(i32 %19, i32 %20, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, -1
br i1 %24, label %25, label %27
25: ; preds = %18
%26 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
27: ; preds = %18
%28 = load i32, i32* %6
%29 = load i8*, i8** %9
%30 = call i32 @write(i32 %28, i8* %29, i32 33)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %35
33: ; preds = %27
%34 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
35: ; preds = %27
%36 = load i32, i32* %6
%37 = call i32 @close(i32 %36)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
41: ; preds = %35
store i32 0, i32* %3
br label %42
42: ; preds = %41, %39, %33, %25, %16
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [34 x i8] c"Will this work? Maybe? Maybe not?\00"
@.str.1 = [88 x i8] c"/net/home/f10/awzurn/Dropbox/School/SJU/CompSci/CS350/Homework/Assign4/assign4-2txt.txt\00"
@O_WRONLY = global i32 0
@O_APPEND = global i32 0
@SEEK_SET = global i32 0
@str = [14 x i8] c"close error! \00"
@str.6 = [14 x i8] c"write error! \00"
@str.7 = [13 x i8] c"seek error! \00"
@str.8 = [13 x i8] c"open error! \00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = load i32, i32* @O_WRONLY
%4 = load i32, i32* @O_APPEND
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @lseek(i32 %6, i32 0, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %18, label %12
12: ; preds = %8
%13 = tail call i32 @write(i32 %6, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str, i64 0, i64 0), i32 33)
%14 = icmp eq i32 %13, -1
br i1 %14, label %18, label %15
15: ; preds = %12
%16 = tail call i32 @close(i32 %6)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15, %12, %8, %2
%19 = phi i8* [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.8, i64 0, i64 0), %2 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @str.7, i64 0, i64 0), %8 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str.6, i64 0, i64 0), %12 ], [ getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0), %15 ]
%20 = tail call i32 @puts(i8* dereferenceable(1) %19)
br label %21
21: ; preds = %18, %15
%22 = phi i32 [ 0, %15 ], [ -1, %18 ]
ret i32 %22
}