#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 /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ S_ISREG(int /*<<< orphan*/);
int /*<<< orphan*/ stat_printk(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
__attribute__((always_)) int load_as_file(char *s, struct stat *stats) {
  int stat_result, result;
  int l = strlen(s);
  if (!stat_printk(s, stats)) {
    if (S_ISREG(stats->st_mode))
      return 0;
  }
  strcat(s, ".js");
  if (!stat_printk(s, stats)) {
    if (S_ISREG(stats->st_mode)) {
      s[l] = '\0';
      return 0;
    }
  }
  strcat(s, "on");
  if (!stat_printk(s, stats)) {
    if (S_ISREG(stats->st_mode)) {
      s[l] = '\0';
      return 0;
    }
  }
  s[l + 1] = '\0';
  strcat(s, "node");
  if (!stat_printk(s, stats)) {
    if (S_ISREG(stats->st_mode)) {
      s[l] = '\0';
      return 0;
    }
  }
  s[l] = '\0';
  return -1;
}


x86 assembly (clang, -O0):
<load_as_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    1198 <load_as_file+0x58>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     1193 <load_as_file+0x53>
movl   $0x0,-0x4(%rbp)
jmp    12c4 <load_as_file+0x184>
jmp    1198 <load_as_file+0x58>
mov    -0x10(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    11f0 <load_as_file+0xb0>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     11eb <load_as_file+0xab>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    12c4 <load_as_file+0x184>
jmp    11f0 <load_as_file+0xb0>
mov    -0x10(%rbp),%rdi
lea    0xe09(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    1248 <load_as_file+0x108>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     1243 <load_as_file+0x103>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    12c4 <load_as_file+0x184>
jmp    1248 <load_as_file+0x108>
mov    -0x10(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xda3(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    12b1 <load_as_file+0x171>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     12ac <load_as_file+0x16c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    12c4 <load_as_file+0x184>
jmp    12b1 <load_as_file+0x171>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_as_file>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stat_printk@plt>
test   %eax,%eax
je     11db <load_as_file+0x9b>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stat_printk@plt>
movslq %ebp,%rbp
test   %eax,%eax
je     11f2 <load_as_file+0xb2>
lea    0xe7c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stat_printk@plt>
test   %eax,%eax
je     1209 <load_as_file+0xc9>
movb   $0x0,0x1(%rbp,%rbx,1)
lea    0xe5c(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stat_printk@plt>
test   %eax,%eax
jne    11d4 <load_as_file+0x94>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    121b <load_as_file+0xdb>
mov    $0xffffffff,%eax
jmp    121b <load_as_file+0xdb>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    121f <load_as_file+0xdf>
jmp    1160 <load_as_file+0x20>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    121b <load_as_file+0xdb>
jmp    1181 <load_as_file+0x41>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     119f <load_as_file+0x5f>
movb   $0x0,(%rbx,%rbp,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [4 x i8] c".js\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [5 x i8] c"node\00"
define i32 @load_as_file(i8* %0, %struct.stat* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca %struct.stat*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store %struct.stat* %1, %struct.stat** %5
%9 = load i8*, i8** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i8*, i8** %4
%12 = load %struct.stat*, %struct.stat** %5
%13 = call i32 @stat_printk(i8* %11, %struct.stat* %12)
%14 = icmp ne i32 %13, 0
br i1 %14, label %23, label %15
15: ; preds = %2
%16 = load %struct.stat*, %struct.stat** %5
%17 = getelementptr inbounds %struct.stat, %struct.stat* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i64 @S_ISREG(i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %15
store i32 0, i32* %3
br label %90
22: ; preds = %15
br label %23
23: ; preds = %22, %2
%24 = load i8*, i8** %4
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%26 = load i8*, i8** %4
%27 = load %struct.stat*, %struct.stat** %5
%28 = call i32 @stat_printk(i8* %26, %struct.stat* %27)
%29 = icmp ne i32 %28, 0
br i1 %29, label %42, label %30
30: ; preds = %23
%31 = load %struct.stat*, %struct.stat** %5
%32 = getelementptr inbounds %struct.stat, %struct.stat* %31, i32 0, i32 0
%33 = load i32, i32* %32
%34 = call i64 @S_ISREG(i32 %33)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %30
%37 = load i8*, i8** %4
%38 = load i32, i32* %8
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
store i8 0, i8* %40
store i32 0, i32* %3
br label %90
41: ; preds = %30
br label %42
42: ; preds = %41, %23
%43 = load i8*, i8** %4
%44 = call i32 @strcat(i8* %43, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%45 = load i8*, i8** %4
%46 = load %struct.stat*, %struct.stat** %5
%47 = call i32 @stat_printk(i8* %45, %struct.stat* %46)
%48 = icmp ne i32 %47, 0
br i1 %48, label %61, label %49
49: ; preds = %42
%50 = load %struct.stat*, %struct.stat** %5
%51 = getelementptr inbounds %struct.stat, %struct.stat* %50, i32 0, i32 0
%52 = load i32, i32* %51
%53 = call i64 @S_ISREG(i32 %52)
%54 = icmp ne i64 %53, 0
br i1 %54, label %55, label %60
55: ; preds = %49
%56 = load i8*, i8** %4
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8, i8* %56, i64 %58
store i8 0, i8* %59
store i32 0, i32* %3
br label %90
60: ; preds = %49
br label %61
61: ; preds = %60, %42
%62 = load i8*, i8** %4
%63 = load i32, i32* %8
%64 = add nsw i32 %63, 1
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %62, i64 %65
store i8 0, i8* %66
%67 = load i8*, i8** %4
%68 = call i32 @strcat(i8* %67, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%69 = load i8*, i8** %4
%70 = load %struct.stat*, %struct.stat** %5
%71 = call i32 @stat_printk(i8* %69, %struct.stat* %70)
%72 = icmp ne i32 %71, 0
br i1 %72, label %85, label %73
73: ; preds = %61
%74 = load %struct.stat*, %struct.stat** %5
%75 = getelementptr inbounds %struct.stat, %struct.stat* %74, i32 0, i32 0
%76 = load i32, i32* %75
%77 = call i64 @S_ISREG(i32 %76)
%78 = icmp ne i64 %77, 0
br i1 %78, label %79, label %84
79: ; preds = %73
%80 = load i8*, i8** %4
%81 = load i32, i32* %8
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 0, i8* %83
store i32 0, i32* %3
br label %90
84: ; preds = %73
br label %85
85: ; preds = %84, %61
%86 = load i8*, i8** %4
%87 = load i32, i32* %8
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8, i8* %86, i64 %88
store i8 0, i8* %89
store i32 -1, i32* %3
br label %90
90: ; preds = %85, %79, %55, %36, %21
%91 = load i32, i32* %3
ret i32 %91
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [4 x i8] c".js\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [5 x i8] c"node\00"
define i32 @load_as_file(i8* %0, %struct.stat* %1) {
%3 = tail call i32 @strlen(i8* %0)
%4 = tail call i32 @stat_printk(i8* %0, %struct.stat* %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %6, label %11
6: ; preds = %2
%7 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%8 = load i32, i32* %7
%9 = tail call i64 @S_ISREG(i32 %8)
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %46
11: ; preds = %6, %2
%12 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%13 = tail call i32 @stat_printk(i8* %0, %struct.stat* %1)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%17 = load i32, i32* %16
%18 = tail call i64 @S_ISREG(i32 %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %42
20: ; preds = %15, %11
%21 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%22 = tail call i32 @stat_printk(i8* %0, %struct.stat* %1)
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %20
%25 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%26 = load i32, i32* %25
%27 = tail call i64 @S_ISREG(i32 %26)
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %42
29: ; preds = %24, %20
%30 = add nsw i32 %3, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %0, i64 %31
store i8 0, i8* %32
%33 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%34 = tail call i32 @stat_printk(i8* %0, %struct.stat* %1)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %41
36: ; preds = %29
%37 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%38 = load i32, i32* %37
%39 = tail call i64 @S_ISREG(i32 %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %42
41: ; preds = %36, %29
br label %42
42: ; preds = %36, %24, %15, %41
%43 = phi i32 [ -1, %41 ], [ 0, %15 ], [ 0, %24 ], [ 0, %36 ]
%44 = sext i32 %3 to i64
%45 = getelementptr inbounds i8, i8* %0, i64 %44
store i8 0, i8* %45
br label %46
46: ; preds = %42, %6
%47 = phi i32 [ 0, %6 ], [ %43, %42 ]
ret i32 %47
}