#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_directory(char *s, struct stat *stats) {
  int l = strlen(s);
  strcat(s, "/package.json");
  if (!stat_printk(s, stats)) {
    if (S_ISREG(stats->st_mode)) {
      s[l] = '\0';
      return 0;
    }
  }
  s[l + 1] = '\0';
  strcat(s, "index.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 + 7] = '\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_directory>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    11b4 <load_as_directory+0x74>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     11af <load_as_directory+0x6f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    12f1 <load_as_directory+0x1b1>
jmp    11b4 <load_as_directory+0x74>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    121d <load_as_directory+0xdd>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     1218 <load_as_directory+0xd8>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    12f1 <load_as_directory+0x1b1>
jmp    121d <load_as_directory+0xdd>
mov    -0x10(%rbp),%rdi
lea    0xde3(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    1275 <load_as_directory+0x135>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     1270 <load_as_directory+0x130>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    12f1 <load_as_directory+0x1b1>
jmp    1275 <load_as_directory+0x135>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x7,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
lea    0xd86(%rip),%rsi
call   1060 <strcat@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1030 <stat_printk@plt>
cmp    $0x0,%eax
jne    12de <load_as_directory+0x19e>
mov    -0x18(%rbp),%rax
mov    (%rax),%edi
call   1050 <S_ISREG@plt>
cmp    $0x0,%rax
je     12d9 <load_as_directory+0x199>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x0,-0x4(%rbp)
jmp    12f1 <load_as_directory+0x1b1>
jmp    12de <load_as_directory+0x19e>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<load_as_directory>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0xea8(%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     11ef <load_as_directory+0xaf>
movb   $0x0,0x1(%rbp,%rbx,1)
lea    0xe90(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stat_printk@plt>
test   %eax,%eax
je     1206 <load_as_directory+0xc6>
lea    0xe6f(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stat_printk@plt>
test   %eax,%eax
je     121d <load_as_directory+0xdd>
movb   $0x0,0x7(%rbp,%rbx,1)
lea    0xe58(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <stat_printk@plt>
test   %eax,%eax
jne    11e8 <load_as_directory+0xa8>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    122f <load_as_directory+0xef>
mov    $0xffffffff,%eax
jmp    122f <load_as_directory+0xef>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    122f <load_as_directory+0xef>
jmp    1172 <load_as_directory+0x32>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
jne    122f <load_as_directory+0xef>
jmp    1195 <load_as_directory+0x55>
mov    (%r14),%edi
call   1050 <S_ISREG@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     11b3 <load_as_directory+0x73>
movb   $0x0,(%rbx,%rbp,1)
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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