#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 dummy;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ errno;
int /*<<< orphan*/ lmsc_U2l(char *);
int /*<<< orphan*/ lmsc_l2U(char *);
int stat(char const *, struct stat *);
int lmsc_statihack(const char *fn, char *n, struct stat *sb) {
  int statr, isup = (*n == 'V');
  if ((statr = stat(fn, sb)) && errno == ENOENT && isup) {
    lmsc_U2l(n);
    if ((statr = stat(fn, sb))) {
      lmsc_l2U(n);
      errno = ENOENT;
    }
  }
  return statr;
}


x86 assembly (clang, -O0):
<lmsc_statihack>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x56,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11da <lmsc_statihack+0xaa>
mov    0x2e67(%rip),%rax
mov    (%rax),%rax
mov    0x2e4d(%rip),%rcx
cmp    (%rcx),%rax
jne    11da <lmsc_statihack+0xaa>
cmpl   $0x0,-0x20(%rbp)
je     11da <lmsc_statihack+0xaa>
mov    -0x10(%rbp),%rdi
call   1030 <lmsc_U2l@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <stat@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11d5 <lmsc_statihack+0xa5>
mov    -0x10(%rbp),%rdi
call   1050 <lmsc_l2U@plt>
mov    0x2e08(%rip),%rax
mov    (%rax),%rcx
mov    0x2e0e(%rip),%rax
mov    %rcx,(%rax)
jmp    11da <lmsc_statihack+0xaa>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lmsc_statihack>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%rbx
mov    (%rsi),%bpl
mov    %rdx,%rsi
call   1040 <stat@plt>
test   %eax,%eax
je     11a3 <lmsc_statihack+0x73>
mov    0x2e86(%rip),%r12
mov    (%r12),%rcx
mov    0x2e6b(%rip),%r13
cmp    0x0(%r13),%rcx
jne    11a5 <lmsc_statihack+0x75>
cmp    $0x56,%bpl
jne    11a5 <lmsc_statihack+0x75>
mov    %r14,%rdi
call   1030 <lmsc_U2l@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <stat@plt>
mov    %eax,%ebx
mov    $0x0,%eax
test   %ebx,%ebx
je     11a5 <lmsc_statihack+0x75>
mov    %r14,%rdi
call   1050 <lmsc_l2U@plt>
mov    0x0(%r13),%rax
mov    %rax,(%r12)
mov    %ebx,%eax
jmp    11a5 <lmsc_statihack+0x75>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
define i32 @lmsc_statihack(i8* %0, i8* %1, %struct.stat* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.stat*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.stat* %2, %struct.stat** %6
%9 = load i8*, i8** %5
%10 = load i8, i8* %9
%11 = sext i8 %10 to i32
%12 = icmp eq i32 %11, 86
%13 = zext i1 %12 to i32
store i32 %13, i32* %8
%14 = load i8*, i8** %4
%15 = load %struct.stat*, %struct.stat** %6
%16 = call i32 @stat(i8* %14, %struct.stat* %15)
store i32 %16, i32* %7
%17 = icmp ne i32 %16, 0
br i1 %17, label %18, label %37
18: ; preds = %3
%19 = load i64, i64* @errno
%20 = load i64, i64* @ENOENT
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %37
22: ; preds = %18
%23 = load i32, i32* %8
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %37
25: ; preds = %22
%26 = load i8*, i8** %5
%27 = call i32 @lmsc_U2l(i8* %26)
%28 = load i8*, i8** %4
%29 = load %struct.stat*, %struct.stat** %6
%30 = call i32 @stat(i8* %28, %struct.stat* %29)
store i32 %30, i32* %7
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = load i8*, i8** %5
%34 = call i32 @lmsc_l2U(i8* %33)
%35 = load i64, i64* @ENOENT
store i64 %35, i64* @errno
br label %36
36: ; preds = %32, %25
br label %37
37: ; preds = %36, %22, %18, %3
%38 = load i32, i32* %7
ret i32 %38
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@errno = global i64 0
@ENOENT = global i64 0
define i32 @lmsc_statihack(i8* nocapture %0, i8* %1, %struct.stat* nocapture %2) {
%4 = load i8, i8* %1
%5 = tail call i32 @stat(i8* %0, %struct.stat* %2)
%6 = icmp eq i32 %5, 0
br i1 %6, label %20, label %7
7: ; preds = %3
%8 = icmp eq i8 %4, 86
%9 = load i64, i64* @errno
%10 = load i64, i64* @ENOENT
%11 = icmp eq i64 %9, %10
%12 = select i1 %11, i1 %8, i1 false
br i1 %12, label %13, label %20
13: ; preds = %7
%14 = tail call i32 @lmsc_U2l(i8* %1)
%15 = tail call i32 @stat(i8* %0, %struct.stat* %2)
%16 = icmp eq i32 %15, 0
br i1 %16, label %20, label %17
17: ; preds = %13
%18 = tail call i32 @lmsc_l2U(i8* %1)
%19 = load i64, i64* @ENOENT
store i64 %19, i64* @errno
br label %20
20: ; preds = %13, %17, %7, %3
%21 = phi i32 [ %15, %17 ], [ 0, %13 ], [ %5, %7 ], [ 0, %3 ]
ret i32 %21
}