#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 /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ strlen(char *);
scalar_t__ strncmp(char *, char *, int);
scalar_t__ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  int fd = -1;
  if (argc != 2) {
    printf("Usage: %s /cluster2/test/FileName\n", argv[0]);
    exit(1);
  }
  if (strncmp("/cluster2/test", argv[1], 14)) {
    printf("Please input FilePath: /cluster2/test\n");
    exit(1);
  }
  fd = open(argv[1], O_RDWR, 0644);
  if (fd == -1) {
    perror("open()");
    exit(-1);
  }
  if (lseek(fd, 0, SEEK_SET) < 0) {
    perror("lseek()");
  }
  if (write(fd, "hello", strlen("hello")) != strlen("hello"))
    perror("write()");
  close(fd);
  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   $0xffffffff,-0x14(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11d6 <main+0x46>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe3e(%rip),%rdi
mov    $0xe,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
je     1211 <main+0x81>
lea    0xe32(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dc8(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    124f <main+0xbf>
lea    0xe19(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
mov    -0x14(%rbp),%edi
mov    0x2d7f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0x0,%rax
jge    1278 <main+0xe8>
lea    0xded(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
lea    0xde3(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x24(%rbp),%edi
mov    %rax,%rdx
lea    0xdd1(%rip),%rsi
call   1040 <write@plt>
mov    %rax,-0x20(%rbp)
lea    0xdc1(%rip),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
je     12c8 <main+0x138>
lea    0xdab(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x14(%rbp),%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
mov    %rsi,%rbx
cmp    $0x2,%edi
jne    1234 <main+0xa4>
mov    0x8(%rbx),%rsi
lea    0xeaf(%rip),%rdi
mov    $0xe,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    124f <main+0xbf>
mov    0x8(%rbx),%rdi
mov    0x2e22(%rip),%rax
mov    (%rax),%esi
mov    $0x1a4,%edx
call   1090 <open@plt>
cmp    $0xffffffff,%eax
je     1265 <main+0xd5>
mov    %eax,%ebx
mov    0x2df4(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
test   %rax,%rax
js     1218 <main+0x88>
lea    0xe37(%rip),%rsi
mov    $0x5,%edx
mov    %ebx,%edi
call   1050 <write@plt>
cmp    $0x5,%rax
jne    1226 <main+0x96>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
pop    %rbx
ret
lea    0xe0b(%rip),%rdi
call   10a0 <perror@plt>
jmp    11f4 <main+0x64>
lea    0xe0b(%rip),%rdi
call   10a0 <perror@plt>
jmp    120d <main+0x7d>
mov    (%rbx),%rsi
lea    0xdc2(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdea(%rip),%rdi
call   1040 <puts@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
lea    0xdb7(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [35 x i8] c"Usage: %s /cluster2/test/FileName\0A\00"
@.str.1 = [15 x i8] c"/cluster2/test\00"
@.str.2 = [39 x i8] c"Please input FilePath: /cluster2/test\0A\00"
@O_RDWR = global i32 0
@.str.3 = [7 x i8] c"open()\00"
@SEEK_SET = global i32 0
@.str.4 = [8 x i8] c"lseek()\00"
@.str.5 = [6 x i8] c"hello\00"
@.str.6 = [8 x i8] c"write()\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 -1, i32* %6
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 1
%18 = load i8*, i8** %17
%19 = call i64 @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 14)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 1)
unreachable
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDWR
%29 = call i32 @open(i8* %27, i32 %28, i32 420)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %35
32: ; preds = %24
%33 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %24
%36 = load i32, i32* %6
%37 = load i32, i32* @SEEK_SET
%38 = call i64 @lseek(i32 %36, i32 0, i32 %37)
%39 = icmp slt i64 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %35
%41 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %42
42: ; preds = %40, %35
%43 = load i32, i32* %6
%44 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%45 = call i64 @write(i32 %43, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i64 %44)
%46 = call i64 @strlen(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0))
%47 = icmp ne i64 %45, %46
br i1 %47, label %48, label %50
48: ; preds = %42
%49 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %50
50: ; preds = %48, %42
%51 = load i32, i32* %6
%52 = call i32 @close(i32 %51)
ret i32 0
}

LLVM IR (-O2):
@.str = [35 x i8] c"Usage: %s /cluster2/test/FileName\0A\00"
@.str.1 = [15 x i8] c"/cluster2/test\00"
@O_RDWR = global i32 0
@.str.3 = [7 x i8] c"open()\00"
@SEEK_SET = global i32 0
@.str.4 = [8 x i8] c"lseek()\00"
@.str.5 = [6 x i8] c"hello\00"
@.str.6 = [8 x i8] c"write()\00"
@str = [38 x i8] c"Please input FilePath: /cluster2/test\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* %5)
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i64 @strncmp(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %10, i32 14)
%12 = icmp eq i64 %11, 0
br i1 %12, label %16, label %13
13: ; preds = %8
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @exit(i32 1)
unreachable
16: ; preds = %8
%17 = load i8*, i8** %9
%18 = load i32, i32* @O_RDWR
%19 = tail call i32 @open(i8* %17, i32 %18, i32 420)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0))
%23 = tail call i32 @exit(i32 -1)
unreachable
24: ; preds = %16
%25 = load i32, i32* @SEEK_SET
%26 = tail call i64 @lseek(i32 %19, i32 0, i32 %25)
%27 = icmp slt i64 %26, 0
br i1 %27, label %28, label %30
28: ; preds = %24
%29 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %28, %24
%31 = tail call i64 @write(i32 %19, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.5, i64 0, i64 0), i64 5)
%32 = icmp eq i64 %31, 5
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %30
%36 = tail call i32 @close(i32 %19)
ret i32 0
}