#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 */
struct stat {
  int st_mode;
};

/* Variables and functions */
scalar_t__ access(char *, int);
int /*<<< orphan*/ stat(char *, struct stat *);
int testeOuvertureFichier(char *nomFichier, int nbArgument) {
  struct stat buffer;
  if (nbArgument != 2)
    return -1;
  if (access(nomFichier, 00) == 0) {
    if (access(nomFichier, 04) != 0)
      return -3;
  } else
    return -2;
  stat(nomFichier, &buffer);
  if (buffer.st_mode >> 12 != 0x8) {
    return -4;
  }
  return 0;
}


x86 assembly (clang, -O0):
<testeOuvertureFichier>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
cmpl   $0x2,-0x14(%rbp)
je     1145 <testeOuvertureFichier+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    11be <testeOuvertureFichier+0x9e>
mov    -0x10(%rbp),%rdi
xor    %esi,%esi
call   1040 <access@plt>
cmp    $0x0,%rax
jne    1183 <testeOuvertureFichier+0x63>
mov    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1040 <access@plt>
cmp    $0x0,%rax
je     117e <testeOuvertureFichier+0x5e>
movl   $0xfffffffd,-0x4(%rbp)
jmp    11be <testeOuvertureFichier+0x9e>
jmp    118f <testeOuvertureFichier+0x6f>
movl   $0xfffffffe,-0x4(%rbp)
jmp    11be <testeOuvertureFichier+0x9e>
mov    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <stat@plt>
mov    -0x18(%rbp),%eax
sar    $0xc,%eax
cmp    $0x8,%eax
je     11b7 <testeOuvertureFichier+0x97>
movl   $0xfffffffc,-0x4(%rbp)
jmp    11be <testeOuvertureFichier+0x9e>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testeOuvertureFichier>:
push   %rbx
sub    $0x10,%rsp
mov    $0xffffffff,%eax
cmp    $0x2,%esi
jne    1187 <testeOuvertureFichier+0x67>
mov    %rdi,%rbx
xor    %esi,%esi
call   1040 <access@plt>
mov    %rax,%rcx
mov    $0xfffffffe,%eax
test   %rcx,%rcx
jne    1187 <testeOuvertureFichier+0x67>
mov    %rbx,%rdi
mov    $0x4,%esi
call   1040 <access@plt>
mov    %rax,%rcx
mov    $0xfffffffd,%eax
test   %rcx,%rcx
jne    1187 <testeOuvertureFichier+0x67>
lea    0x8(%rsp),%rsi
mov    %rbx,%rdi
call   1030 <stat@plt>
mov    $0xfffff000,%eax
and    0x8(%rsp),%eax
xor    %ecx,%ecx
cmp    $0x8000,%eax
sete   %cl
lea    -0x4(,%rcx,4),%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
define i32 @testeOuvertureFichier(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca %struct.stat
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* %5
%8 = icmp ne i32 %7, 2
br i1 %8, label %9, label %10
9: ; preds = %2
store i32 -1, i32* %3
br label %30
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i64 @access(i8* %11, i32 0)
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i8*, i8** %4
%16 = call i64 @access(i8* %15, i32 4)
%17 = icmp ne i64 %16, 0
br i1 %17, label %18, label %19
18: ; preds = %14
store i32 -3, i32* %3
br label %30
19: ; preds = %14
br label %21
20: ; preds = %10
store i32 -2, i32* %3
br label %30
21: ; preds = %19
%22 = load i8*, i8** %4
%23 = call i32 @stat(i8* %22, %struct.stat* %6)
%24 = getelementptr inbounds %struct.stat, %struct.stat* %6, i32 0, i32 0
%25 = load i32, i32* %24
%26 = ashr i32 %25, 12
%27 = icmp ne i32 %26, 8
br i1 %27, label %28, label %29
28: ; preds = %21
store i32 -4, i32* %3
br label %30
29: ; preds = %21
store i32 0, i32* %3
br label %30
30: ; preds = %29, %28, %20, %18, %9
%31 = load i32, i32* %3
ret i32 %31
}

LLVM IR (-O2):
%struct.stat = type { i32 }
define i32 @testeOuvertureFichier(i8* nocapture %0, i32 %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %1, 2
br i1 %5, label %6, label %19
6: ; preds = %2
%7 = tail call i64 @access(i8* %0, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = tail call i64 @access(i8* %0, i32 4)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %9
%13 = call i32 @stat(i8* %0, %struct.stat* %3)
%14 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%15 = load i32, i32* %14
%16 = and i32 %15, -4096
%17 = icmp eq i32 %16, 32768
%18 = select i1 %17, i32 0, i32 -4
br label %19
19: ; preds = %12, %6, %9, %2
%20 = phi i32 [ -1, %2 ], [ -3, %9 ], [ -2, %6 ], [ %18, %12 ]
ret i32 %20
}