#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 const EACCES;
int const EISDIR;
int const ENOENT;
int const ENOTDIR;
int const O_RDONLY;
int const O_RDWR;
int const O_WRONLY;
int /*<<< orphan*/ fat_close(int, int *);
int fat_open(char const *, int const, int /*<<< orphan*/, int *);
int /*<<< orphan*/ printf(char *, ...);
char *strerror(int const);
int test_open(int p) {
  int i;
  int v;
  const char *desc[] = {
      "Test O_WRONLY on a read only file.",
      "Test O_RDWR on a read only file.",
      "Test O_RDONLY on a read only file.",
      "Test O_WRONLY on a directory.",
      "Test O_RDWR on a directory.",
      "Test O_RDONLY on a directory.",
      "Test O_WRONLY on a missing file.",
      "Test O_RDWR on a missing file.",
      "Test O_RDONLY on a missing file.",
      "Test O_WRONLY on a path with file as non terminal member.",
      "Test O_RDWR on a path with file as non terminal member.",
      "Test O_RDONLY on a path with a file as non terminal member.",
  };
  const char *filename[] = {
      "/ROFILE.TXT",
      "/ROFILE.TXT",
      "/ROFILE.TXT",
      "/DIR1",
      "/DIR1",
      "/DIR1",
      "/MISSING.TXT",
      "/MISSING.TXT",
      "/MISSING.TXT",
      "/ROFILE.TXT/NONE.TXT",
      "/ROFILE.TXT/NONE.TXT",
      "/ROFILE.TXT/NONE.TXT",
  };
  const int flags[] = {
      O_WRONLY, O_RDWR, O_RDONLY, O_WRONLY, O_RDWR, O_RDONLY,
      O_WRONLY, O_RDWR, O_RDONLY, O_WRONLY, O_RDWR, O_RDONLY,
  };
  const int result[] = {
      EACCES, EACCES, 0,      EISDIR,  EISDIR,  0,
      ENOENT, ENOENT, ENOENT, ENOTDIR, ENOTDIR, ENOTDIR,
  };
  const int cases = 12;
  int rerrno;
  for (i = 0; i < cases; i++) {
    printf("[%4d] Testing %s", p++, desc[i]);
    v = fat_open(filename[i], flags[i], 0, &rerrno);
    if (rerrno == result[i]) {
      printf("  [ ok ]\n");
    } else {
      printf("  [fail]\n  expected (%d) %s\n  got (%d) %s\n", result[i],
             strerror(result[i]), rerrno, strerror(-rerrno));
    }
    if (v > -1) {
      fat_close(v, &rerrno);
      if (rerrno != 0) {
        printf("fat_close returned %d (%s)\n", rerrno, strerror(rerrno));
      }
    }
  }
  return p;
}


x86 assembly (clang, -O0):
<test_open>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
mov    %edi,-0x4(%rbp)
lea    -0x70(%rbp),%rdi
lea    0x2bb7(%rip),%rsi
mov    $0x60,%edx
call   1050 <memcpy@plt>
lea    -0xd0(%rbp),%rdi
lea    0x2bff(%rip),%rsi
mov    $0x60,%edx
call   1050 <memcpy@plt>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x100(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xfc(%rbp)
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf8(%rbp)
mov    0x2de1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf4(%rbp)
mov    0x2e0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xf0(%rbp)
mov    0x2deb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xec(%rbp)
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe8(%rbp)
mov    0x2ddd(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe4(%rbp)
mov    0x2dbe(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xe0(%rbp)
mov    0x2d87(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xdc(%rbp)
mov    0x2db0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd8(%rbp)
mov    0x2d91(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xd4(%rbp)
mov    0x2d7a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x130(%rbp)
mov    0x2d6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x12c(%rbp)
movl   $0x0,-0x128(%rbp)
mov    0x2d62(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x124(%rbp)
mov    0x2d53(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x120(%rbp)
movl   $0x0,-0x11c(%rbp)
mov    0x2d12(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x118(%rbp)
mov    0x2d03(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x114(%rbp)
mov    0x2cf4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x110(%rbp)
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x10c(%rbp)
mov    0x2d1e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x108(%rbp)
mov    0x2d0f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x104(%rbp)
movl   $0xc,-0x134(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xc,-0x8(%rbp)
jge    1449 <test_open+0x2f9>
mov    -0x4(%rbp),%esi
mov    %esi,%eax
add    $0x1,%eax
mov    %eax,-0x4(%rbp)
movslq -0x8(%rbp),%rax
mov    -0x70(%rbp,%rax,8),%rdx
lea    0xee3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movslq -0x8(%rbp),%rax
mov    -0xd0(%rbp,%rax,8),%rdi
ff
movslq -0x8(%rbp),%rax
mov    -0x100(%rbp,%rax,4),%esi
xor    %edx,%edx
lea    -0x138(%rbp),%rcx
call   1060 <fat_open@plt>
mov    %eax,-0xc(%rbp)
mov    -0x138(%rbp),%eax
movslq -0x8(%rbp),%rcx
cmp    -0x130(%rbp,%rcx,4),%eax
jne    1378 <test_open+0x228>
lea    0xea7(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    13dd <test_open+0x28d>
movslq -0x8(%rbp),%rax
mov    -0x130(%rbp,%rax,4),%eax
mov    %eax,-0x14c(%rbp)
movslq -0x8(%rbp),%rax
mov    -0x130(%rbp,%rax,4),%edi
call   1070 <strerror@plt>
mov    %rax,-0x148(%rbp)
mov    -0x138(%rbp),%eax
mov    %eax,-0x13c(%rbp)
xor    %edi,%edi
sub    -0x138(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x14c(%rbp),%esi
mov    -0x148(%rbp),%rdx
mov    -0x13c(%rbp),%ecx
mov    %rax,%r8
lea    0xe47(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0xffffffff,-0xc(%rbp)
jle    1436 <test_open+0x2e6>
mov    -0xc(%rbp),%edi
lea    -0x138(%rbp),%rsi
call   1040 <fat_close@plt>
cmpl   $0x0,-0x138(%rbp)
je     1431 <test_open+0x2e1>
mov    -0x138(%rbp),%eax
mov    %eax,-0x150(%rbp)
mov    -0x138(%rbp),%edi
call   1070 <strerror@plt>
mov    -0x150(%rbp),%esi
mov    %rax,%rdx
lea    0xe1e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    1436 <test_open+0x2e6>
jmp    143b <test_open+0x2eb>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    12fa <test_open+0x1aa>
mov    -0x4(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_open>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x78,%rsp
mov    %edi,%ebx
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
lea    0x10dc(%rip),%r14
xor    %r15d,%r15d
jmp    11a1 <test_open+0x51>
nopl   (%rax)
add    $0x4,%r15
add    $0x1,%ebx
cmp    $0x30,%r15
je     127c <test_open+0x12c>
movslq (%r15,%r14,1),%rdx
add    %r14,%rdx
lea    0x1053(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0x10d5(%rip),%rax
movslq (%r15,%rax,1),%rdi
add    %rax,%rdi
mov    0x40(%rsp,%r15,1),%esi
xor    %edx,%edx
lea    0xc(%rsp),%rcx
call   1060 <fat_open@plt>
mov    %eax,%r13d
mov    0x10(%rsp,%r15,1),%r12d
cmp    %r12d,0xc(%rsp)
jne    1200 <test_open+0xb0>
lea    0x106d(%rip),%rdi
call   1030 <puts@plt>
test   %r13d,%r13d
jns    1244 <test_open+0xf4>
jmp    1190 <test_open+0x40>
nopl   0x0(%rax)
mov    %r12d,%edi
call   1070 <strerror@plt>
mov    %rax,%rbp
mov    0xc(%rsp),%r14d
mov    %r14d,%edi
neg    %edi
call   1070 <strerror@plt>
lea    0xff2(%rip),%rdi
mov    %r12d,%esi
mov    %rbp,%rdx
mov    %r14d,%ecx
lea    0x1033(%rip),%r14
mov    %rax,%r8
xor    %eax,%eax
call   1040 <printf@plt>
test   %r13d,%r13d
js     1190 <test_open+0x40>
mov    %r13d,%edi
lea    0xc(%rsp),%rsi
call   1050 <fat_close@plt>
mov    0xc(%rsp),%ebp
test   %ebp,%ebp
je     1190 <test_open+0x40>
mov    %ebp,%edi
call   1070 <strerror@plt>
lea    0xfd3(%rip),%rdi
mov    %ebp,%esi
mov    %rax,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1190 <test_open+0x40>
mov    %ebx,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"Test O_WRONLY on a read only file.\00"
@.str.1 = [33 x i8] c"Test O_RDWR on a read only file.\00"
@.str.2 = [35 x i8] c"Test O_RDONLY on a read only file.\00"
@.str.3 = [30 x i8] c"Test O_WRONLY on a directory.\00"
@.str.4 = [28 x i8] c"Test O_RDWR on a directory.\00"
@.str.5 = [30 x i8] c"Test O_RDONLY on a directory.\00"
@.str.6 = [33 x i8] c"Test O_WRONLY on a missing file.\00"
@.str.7 = [31 x i8] c"Test O_RDWR on a missing file.\00"
@.str.8 = [33 x i8] c"Test O_RDONLY on a missing file.\00"
@.str.9 = [58 x i8] c"Test O_WRONLY on a path with file as non terminal member.\00"
@.str.10 = [56 x i8] c"Test O_RDWR on a path with file as non terminal member.\00"
@.str.11 = [60 x i8] c"Test O_RDONLY on a path with a file as non terminal member.\00"
@__const.test_open.desc = [12 x i8*] [i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.11, i32 0, i32 0)]
@.str.12 = [12 x i8] c"/ROFILE.TXT\00"
@.str.13 = [6 x i8] c"/DIR1\00"
@.str.14 = [13 x i8] c"/MISSING.TXT\00"
@.str.15 = [21 x i8] c"/ROFILE.TXT/NONE.TXT\00"
@__const.test_open.filename = [12 x i8*] [i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.12, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.13, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.14, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.15, i32 0, i32 0), i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.15, i32 0, i32 0)]
@O_WRONLY = constant i32 0
@O_RDWR = constant i32 0
@O_RDONLY = constant i32 0
@EACCES = constant i32 0
@EISDIR = constant i32 0
@ENOENT = constant i32 0
@ENOTDIR = constant i32 0
@.str.16 = [17 x i8] c"[%4d] Testing %s\00"
@.str.17 = [10 x i8] c" [ ok ]\0A\00"
@.str.18 = [43 x i8] c" [fail]\0A expected (%d) %s\0A got (%d) %s\0A\00"
@.str.19 = [28 x i8] c"fat_close returned %d (%s)\0A\00"
define i32 @test_open(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [12 x i8*]
%6 = alloca [12 x i8*]
%7 = alloca [12 x i32]
%8 = alloca [12 x i32]
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %2
%11 = bitcast [12 x i8*]* %5 to i8*
%12 = bitcast [12 x i8*]* %6 to i8*
%13 = getelementptr inbounds [12 x i32], [12 x i32]* %7, i64 0, i64 0
%14 = load i32, i32* @O_WRONLY
store i32 %14, i32* %13
%15 = getelementptr inbounds i32, i32* %13, i64 1
%16 = load i32, i32* @O_RDWR
store i32 %16, i32* %15
%17 = getelementptr inbounds i32, i32* %15, i64 1
%18 = load i32, i32* @O_RDONLY
store i32 %18, i32* %17
%19 = getelementptr inbounds i32, i32* %17, i64 1
%20 = load i32, i32* @O_WRONLY
store i32 %20, i32* %19
%21 = getelementptr inbounds i32, i32* %19, i64 1
%22 = load i32, i32* @O_RDWR
store i32 %22, i32* %21
%23 = getelementptr inbounds i32, i32* %21, i64 1
%24 = load i32, i32* @O_RDONLY
store i32 %24, i32* %23
%25 = getelementptr inbounds i32, i32* %23, i64 1
%26 = load i32, i32* @O_WRONLY
store i32 %26, i32* %25
%27 = getelementptr inbounds i32, i32* %25, i64 1
%28 = load i32, i32* @O_RDWR
store i32 %28, i32* %27
%29 = getelementptr inbounds i32, i32* %27, i64 1
%30 = load i32, i32* @O_RDONLY
store i32 %30, i32* %29
%31 = getelementptr inbounds i32, i32* %29, i64 1
%32 = load i32, i32* @O_WRONLY
store i32 %32, i32* %31
%33 = getelementptr inbounds i32, i32* %31, i64 1
%34 = load i32, i32* @O_RDWR
store i32 %34, i32* %33
%35 = getelementptr inbounds i32, i32* %33, i64 1
%36 = load i32, i32* @O_RDONLY
store i32 %36, i32* %35
%37 = getelementptr inbounds [12 x i32], [12 x i32]* %8, i64 0, i64 0
%38 = load i32, i32* @EACCES
store i32 %38, i32* %37
%39 = getelementptr inbounds i32, i32* %37, i64 1
%40 = load i32, i32* @EACCES
store i32 %40, i32* %39
%41 = getelementptr inbounds i32, i32* %39, i64 1
store i32 0, i32* %41
%42 = getelementptr inbounds i32, i32* %41, i64 1
%43 = load i32, i32* @EISDIR
store i32 %43, i32* %42
%44 = getelementptr inbounds i32, i32* %42, i64 1
%45 = load i32, i32* @EISDIR
store i32 %45, i32* %44
%46 = getelementptr inbounds i32, i32* %44, i64 1
store i32 0, i32* %46
%47 = getelementptr inbounds i32, i32* %46, i64 1
%48 = load i32, i32* @ENOENT
store i32 %48, i32* %47
%49 = getelementptr inbounds i32, i32* %47, i64 1
%50 = load i32, i32* @ENOENT
store i32 %50, i32* %49
%51 = getelementptr inbounds i32, i32* %49, i64 1
%52 = load i32, i32* @ENOENT
store i32 %52, i32* %51
%53 = getelementptr inbounds i32, i32* %51, i64 1
%54 = load i32, i32* @ENOTDIR
store i32 %54, i32* %53
%55 = getelementptr inbounds i32, i32* %53, i64 1
%56 = load i32, i32* @ENOTDIR
store i32 %56, i32* %55
%57 = getelementptr inbounds i32, i32* %55, i64 1
%58 = load i32, i32* @ENOTDIR
store i32 %58, i32* %57
store i32 12, i32* %9
store i32 0, i32* %3
br label %59
59: ; preds = %117, %1
%60 = load i32, i32* %3
%61 = icmp slt i32 %60, 12
br i1 %61, label %62, label %120
62: ; preds = %59
%63 = load i32, i32* %2
%64 = add nsw i32 %63, 1
store i32 %64, i32* %2
%65 = load i32, i32* %3
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds [12 x i8*], [12 x i8*]* %5, i64 0, i64 %66
%68 = load i8*, i8** %67
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), i32 %63, i8* %68)
%70 = load i32, i32* %3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds [12 x i8*], [12 x i8*]* %6, i64 0, i64 %71
%73 = load i8*, i8** %72
%74 = load i32, i32* %3
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds [12 x i32], [12 x i32]* %7, i64 0, i64 %75
%77 = load i32, i32* %76
%78 = call i32 @fat_open(i8* %73, i32 %77, i32 0, i32* %10)
store i32 %78, i32* %4
%79 = load i32, i32* %10
%80 = load i32, i32* %3
%81 = sext i32 %80 to i64
%82 = getelementptr inbounds [12 x i32], [12 x i32]* %8, i64 0, i64 %81
%83 = load i32, i32* %82
%84 = icmp eq i32 %79, %83
br i1 %84, label %85, label %87
85: ; preds = %62
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.17, i64 0, i64 0))
br label %102
87: ; preds = %62
%88 = load i32, i32* %3
%89 = sext i32 %88 to i64
%90 = getelementptr inbounds [12 x i32], [12 x i32]* %8, i64 0, i64 %89
%91 = load i32, i32* %90
%92 = load i32, i32* %3
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds [12 x i32], [12 x i32]* %8, i64 0, i64 %93
%95 = load i32, i32* %94
%96 = call i8* @strerror(i32 %95)
%97 = load i32, i32* %10
%98 = load i32, i32* %10
%99 = sub nsw i32 0, %98
%100 = call i8* @strerror(i32 %99)
%101 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.18, i64 0, i64 0), i32 %91, i8* %96, i32 %97, i8* %100)
br label %102
102: ; preds = %87, %85
%103 = load i32, i32* %4
%104 = icmp sgt i32 %103, -1
br i1 %104, label %105, label %116
105: ; preds = %102
%106 = load i32, i32* %4
%107 = call i32 @fat_close(i32 %106, i32* %10)
%108 = load i32, i32* %10
%109 = icmp ne i32 %108, 0
br i1 %109, label %110, label %115
110: ; preds = %105
%111 = load i32, i32* %10
%112 = load i32, i32* %10
%113 = call i8* @strerror(i32 %112)
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i32 %111, i8* %113)
br label %115
115: ; preds = %110, %105
br label %116
116: ; preds = %115, %102
br label %117
117: ; preds = %116
%118 = load i32, i32* %3
%119 = add nsw i32 %118, 1
store i32 %119, i32* %3
br label %59
120: ; preds = %59
%121 = load i32, i32* %2
ret i32 %121
}

LLVM IR (-O2):
@.str = [35 x i8] c"Test O_WRONLY on a read only file.\00"
@.str.1 = [33 x i8] c"Test O_RDWR on a read only file.\00"
@.str.2 = [35 x i8] c"Test O_RDONLY on a read only file.\00"
@.str.3 = [30 x i8] c"Test O_WRONLY on a directory.\00"
@.str.4 = [28 x i8] c"Test O_RDWR on a directory.\00"
@.str.5 = [30 x i8] c"Test O_RDONLY on a directory.\00"
@.str.6 = [33 x i8] c"Test O_WRONLY on a missing file.\00"
@.str.7 = [31 x i8] c"Test O_RDWR on a missing file.\00"
@.str.8 = [33 x i8] c"Test O_RDONLY on a missing file.\00"
@.str.9 = [58 x i8] c"Test O_WRONLY on a path with file as non terminal member.\00"
@.str.10 = [56 x i8] c"Test O_RDWR on a path with file as non terminal member.\00"
@.str.11 = [60 x i8] c"Test O_RDONLY on a path with a file as non terminal member.\00"
@reltable.test_open = [12 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([35 x i8]* @.str to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([33 x i8]* @.str.1 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([35 x i8]* @.str.2 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str.3 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([28 x i8]* @.str.4 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([30 x i8]* @.str.5 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([33 x i8]* @.str.6 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([31 x i8]* @.str.7 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([33 x i8]* @.str.8 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([58 x i8]* @.str.9 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([56 x i8]* @.str.10 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([60 x i8]* @.str.11 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open to i64)) to i32)]
@.str.12 = [12 x i8] c"/ROFILE.TXT\00"
@.str.13 = [6 x i8] c"/DIR1\00"
@.str.14 = [13 x i8] c"/MISSING.TXT\00"
@.str.15 = [21 x i8] c"/ROFILE.TXT/NONE.TXT\00"
@reltable.test_open.20 = [12 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.12 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.12 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([12 x i8]* @.str.12 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.13 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.13 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([6 x i8]* @.str.13 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.14 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.14 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([13 x i8]* @.str.14 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.15 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.15 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.15 to i64), i64 ptrtoint ([12 x i32]* @reltable.test_open.20 to i64)) to i32)]
@O_WRONLY = constant i32 0
@O_RDWR = constant i32 0
@O_RDONLY = constant i32 0
@EACCES = constant i32 0
@EISDIR = constant i32 0
@ENOENT = constant i32 0
@ENOTDIR = constant i32 0
@.str.16 = [17 x i8] c"[%4d] Testing %s\00"
@.str.18 = [43 x i8] c" [fail]\0A expected (%d) %s\0A got (%d) %s\0A\00"
@.str.19 = [28 x i8] c"fat_close returned %d (%s)\0A\00"
@str = [9 x i8] c" [ ok ]\00"
define i32 @test_open(i32 %0) {
%2 = alloca [12 x i32]
%3 = alloca [12 x i32]
%4 = alloca i32
%5 = bitcast [12 x i32]* %2 to i8*
%6 = bitcast [12 x i32]* %3 to i8*
%7 = bitcast [12 x i32]* %2 to i8*
%8 = bitcast i32* %4 to i8*
%9 = bitcast [12 x i32]* %3 to i8*
br label %10
10: ; preds = %1, %43
%11 = phi i64 [ 0, %1 ], [ %44, %43 ]
%12 = phi i32 [ %0, %1 ], [ %13, %43 ]
%13 = add nsw i32 %12, 1
%14 = shl i64 %11, 2
%15 = call i8* @llvm.load.relative.i64(i8* bitcast ([12 x i32]* @reltable.test_open to i8*), i64 %14)
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.16, i64 0, i64 0), i32 %12, i8* %15)
%17 = shl i64 %11, 2
%18 = call i8* @llvm.load.relative.i64(i8* bitcast ([12 x i32]* @reltable.test_open.20 to i8*), i64 %17)
%19 = getelementptr inbounds [12 x i32], [12 x i32]* %2, i64 0, i64 %11
%20 = load i32, i32* %19
%21 = call i32 @fat_open(i8* %18, i32 %20, i32 0, i32* %4)
%22 = load i32, i32* %4
%23 = getelementptr inbounds [12 x i32], [12 x i32]* %3, i64 0, i64 %11
%24 = load i32, i32* %23
%25 = icmp eq i32 %22, %24
br i1 %25, label %26, label %28
26: ; preds = %10
%27 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @str, i64 0, i64 0))
br label %34
28: ; preds = %10
%29 = call i8* @strerror(i32 %24)
%30 = load i32, i32* %4
%31 = sub nsw i32 0, %30
%32 = call i8* @strerror(i32 %31)
%33 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.18, i64 0, i64 0), i32 %24, i8* %29, i32 %30, i8* %32)
br label %34
34: ; preds = %28, %26
%35 = icmp sgt i32 %21, -1
br i1 %35, label %36, label %43
36: ; preds = %34
%37 = call i32 @fat_close(i32 %21, i32* %4)
%38 = load i32, i32* %4
%39 = icmp eq i32 %38, 0
br i1 %39, label %43, label %40
40: ; preds = %36
%41 = call i8* @strerror(i32 %38)
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.19, i64 0, i64 0), i32 %38, i8* %41)
br label %43
43: ; preds = %34, %40, %36
%44 = add nuw nsw i64 %11, 1
%45 = icmp eq i64 %44, 12
br i1 %45, label %46, label %10
46: ; preds = %43
ret i32 %13
}