#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 */
int /*<<< orphan*/ load_as_directory(char *, struct stat *);
int /*<<< orphan*/ load_as_file(char *, struct stat *);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcmp(char const *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char const *);
int node_require(const char *cwd, const char *s, struct stat *require_stat) {
  char buffer[256];
  int i, cl = strlen(cwd);
  if (!strcmp(s, "http") || !strcmp(s, "fs")) {
    return 0;
  }
  strcpy(buffer, cwd);
  if (s[0] == '/' ||
      s[0] == '.' && (s[1] == '/' || s[1] == '.' && s[2] == '/')) {
    strcat(buffer, s);
    if (!load_as_file(buffer, require_stat))
      return 0;
    if (!load_as_directory(buffer, require_stat))
      return 0;
  }
  for (i = cl - 1; i >= 0; i--) {
    if (cwd[i] == '/') {
      buffer[i + 1] = '\0';
      strcat(buffer, "node_modules/");
      strcat(buffer, s);
      if (!load_as_file(buffer, require_stat))
        return 0;
      if (!load_as_directory(buffer, require_stat))
        return 0;
    }
  }
  return -1;
}


x86 assembly (clang, -O0):
<node_require>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x128(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe6f(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
je     11b8 <node_require+0x58>
mov    -0x18(%rbp),%rdi
lea    0xe5b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%eax
jne    11c4 <node_require+0x64>
movl   $0x0,-0x4(%rbp)
jmp    135f <node_require+0x1ff>
lea    -0x120(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2f,%eax
je     1227 <node_require+0xc7>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2e,%eax
jne    1286 <node_require+0x126>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2f,%eax
je     1227 <node_require+0xc7>
mov    -0x18(%rbp),%rax
movsbl 0x1(%rax),%eax
cmp    $0x2e,%eax
jne    1286 <node_require+0x126>
mov    -0x18(%rbp),%rax
movsbl 0x2(%rax),%eax
cmp    $0x2f,%eax
jne    1286 <node_require+0x126>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <load_as_file@plt>
cmp    $0x0,%eax
jne    125c <node_require+0xfc>
movl   $0x0,-0x4(%rbp)
jmp    135f <node_require+0x1ff>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <load_as_directory@plt>
cmp    $0x0,%eax
jne    1281 <node_require+0x121>
movl   $0x0,-0x4(%rbp)
jmp    135f <node_require+0x1ff>
jmp    1286 <node_require+0x126>
mov    -0x128(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x124(%rbp)
cmpl   $0x0,-0x124(%rbp)
jl     1358 <node_require+0x1f8>
mov    -0x10(%rbp),%rax
movslq -0x124(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
jne    133f <node_require+0x1df>
mov    -0x124(%rbp),%eax
add    $0x1,%eax
cltq
movb   $0x0,-0x120(%rbp,%rax,1)
lea    -0x120(%rbp),%rdi
lea    0xd2d(%rip),%rsi
call   1080 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <load_as_file@plt>
cmp    $0x0,%eax
jne    1315 <node_require+0x1b5>
movl   $0x0,-0x4(%rbp)
jmp    135f <node_require+0x1ff>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <load_as_directory@plt>
cmp    $0x0,%eax
jne    133a <node_require+0x1da>
movl   $0x0,-0x4(%rbp)
jmp    135f <node_require+0x1ff>
jmp    133f <node_require+0x1df>
jmp    1344 <node_require+0x1e4>
mov    -0x124(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x124(%rbp)
jmp    1295 <node_require+0x135>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<node_require>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%r12d
lea    0xe77(%rip),%rsi
mov    %r13,%rdi
call   1060 <strcmp@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     127b <node_require+0x11b>
lea    0xe62(%rip),%rsi
mov    %r13,%rdi
call   1060 <strcmp@plt>
test   %eax,%eax
je     127b <node_require+0x11b>
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
mov    0x0(%r13),%al
cmp    $0x2f,%al
je     11dd <node_require+0x7d>
cmp    $0x2e,%al
jne    120d <node_require+0xad>
mov    0x1(%r13),%al
cmp    $0x2f,%al
je     11dd <node_require+0x7d>
cmp    $0x2e,%al
jne    120d <node_require+0xad>
cmpb   $0x2f,0x2(%r13)
jne    120d <node_require+0xad>
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <load_as_file@plt>
test   %eax,%eax
je     127b <node_require+0x11b>
mov    %rsp,%rdi
mov    %r15,%rsi
call   1050 <load_as_directory@plt>
test   %eax,%eax
je     127b <node_require+0x11b>
test   %r12d,%r12d
jle    1275 <node_require+0x115>
mov    %r12d,%r12d
add    $0x1,%r12
mov    %rsp,%rbp
jmp    122a <node_require+0xca>
xchg   %ax,%ax
add    $0xffffffffffffffff,%r12
cmp    $0x1,%r12
jbe    1275 <node_require+0x115>
lea    -0x2(%r12),%eax
cmpb   $0x2f,(%rbx,%rax,1)
jne    1220 <node_require+0xc0>
movb   $0x0,-0x1(%rsp,%r12,1)
mov    %rbp,%rdi
lea    0xdc3(%rip),%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1070 <load_as_file@plt>
test   %eax,%eax
je     127b <node_require+0x11b>
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <load_as_directory@plt>
test   %eax,%eax
jne    1220 <node_require+0xc0>
jmp    127b <node_require+0x11b>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [5 x i8] c"http\00"
@.str.1 = [3 x i8] c"fs\00"
@.str.2 = [14 x i8] c"node_modules/\00"
define i32 @node_require(i8* %0, i8* %1, %struct.stat* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca %struct.stat*
%8 = alloca [256 x i8]
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store %struct.stat* %2, %struct.stat** %7
%11 = load i8*, i8** %5
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %10
%13 = load i8*, i8** %6
%14 = call i32 @strcmp(i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %20
16: ; preds = %3
%17 = load i8*, i8** %6
%18 = call i32 @strcmp(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %16, %3
store i32 0, i32* %4
br label %111
21: ; preds = %16
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%23 = load i8*, i8** %5
%24 = call i32 @strcpy(i8* %22, i8* %23)
%25 = load i8*, i8** %6
%26 = getelementptr inbounds i8, i8* %25, i64 0
%27 = load i8, i8* %26
%28 = sext i8 %27 to i32
%29 = icmp eq i32 %28, 47
br i1 %29, label %54, label %30
30: ; preds = %21
%31 = load i8*, i8** %6
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp eq i32 %34, 46
br i1 %35, label %36, label %70
36: ; preds = %30
%37 = load i8*, i8** %6
%38 = getelementptr inbounds i8, i8* %37, i64 1
%39 = load i8, i8* %38
%40 = sext i8 %39 to i32
%41 = icmp eq i32 %40, 47
br i1 %41, label %54, label %42
42: ; preds = %36
%43 = load i8*, i8** %6
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8, i8* %44
%46 = sext i8 %45 to i32
%47 = icmp eq i32 %46, 46
br i1 %47, label %48, label %70
48: ; preds = %42
%49 = load i8*, i8** %6
%50 = getelementptr inbounds i8, i8* %49, i64 2
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp eq i32 %52, 47
br i1 %53, label %54, label %70
54: ; preds = %48, %36, %21
%55 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%56 = load i8*, i8** %6
%57 = call i32 @strcat(i8* %55, i8* %56)
%58 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%59 = load %struct.stat*, %struct.stat** %7
%60 = call i32 @load_as_file(i8* %58, %struct.stat* %59)
%61 = icmp ne i32 %60, 0
br i1 %61, label %63, label %62
62: ; preds = %54
store i32 0, i32* %4
br label %111
63: ; preds = %54
%64 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%65 = load %struct.stat*, %struct.stat** %7
%66 = call i32 @load_as_directory(i8* %64, %struct.stat* %65)
%67 = icmp ne i32 %66, 0
br i1 %67, label %69, label %68
68: ; preds = %63
store i32 0, i32* %4
br label %111
69: ; preds = %63
br label %70
70: ; preds = %69, %48, %42, %30
%71 = load i32, i32* %10
%72 = sub nsw i32 %71, 1
store i32 %72, i32* %9
br label %73
73: ; preds = %107, %70
%74 = load i32, i32* %9
%75 = icmp sge i32 %74, 0
br i1 %75, label %76, label %110
76: ; preds = %73
%77 = load i8*, i8** %5
%78 = load i32, i32* %9
%79 = sext i32 %78 to i64
%80 = getelementptr inbounds i8, i8* %77, i64 %79
%81 = load i8, i8* %80
%82 = sext i8 %81 to i32
%83 = icmp eq i32 %82, 47
br i1 %83, label %84, label %106
84: ; preds = %76
%85 = load i32, i32* %9
%86 = add nsw i32 %85, 1
%87 = sext i32 %86 to i64
%88 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 %87
store i8 0, i8* %88
%89 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%90 = call i32 @strcat(i8* %89, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%91 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%92 = load i8*, i8** %6
%93 = call i32 @strcat(i8* %91, i8* %92)
%94 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%95 = load %struct.stat*, %struct.stat** %7
%96 = call i32 @load_as_file(i8* %94, %struct.stat* %95)
%97 = icmp ne i32 %96, 0
br i1 %97, label %99, label %98
98: ; preds = %84
store i32 0, i32* %4
br label %111
99: ; preds = %84
%100 = getelementptr inbounds [256 x i8], [256 x i8]* %8, i64 0, i64 0
%101 = load %struct.stat*, %struct.stat** %7
%102 = call i32 @load_as_directory(i8* %100, %struct.stat* %101)
%103 = icmp ne i32 %102, 0
br i1 %103, label %105, label %104
104: ; preds = %99
store i32 0, i32* %4
br label %111
105: ; preds = %99
br label %106
106: ; preds = %105, %76
br label %107
107: ; preds = %106
%108 = load i32, i32* %9
%109 = add nsw i32 %108, -1
store i32 %109, i32* %9
br label %73
110: ; preds = %73
store i32 -1, i32* %4
br label %111
111: ; preds = %110, %104, %98, %68, %62, %20
%112 = load i32, i32* %4
ret i32 %112
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [5 x i8] c"http\00"
@.str.1 = [3 x i8] c"fs\00"
@.str.2 = [14 x i8] c"node_modules/\00"
define i32 @node_require(i8* %0, i8* %1, %struct.stat* %2) {
%4 = alloca [256 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(5) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %7, 0
br i1 %8, label %51, label %9
9: ; preds = %3
%10 = tail call i32 @strcmp(i8* dereferenceable(1) %1, i8* dereferenceable(3) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i32 %10, 0
br i1 %11, label %51, label %12
12: ; preds = %9
%13 = call i32 @strcpy(i8* %5, i8* %0)
%14 = load i8, i8* %1
switch i8 %14, label %29 [
i8 47, label %22
i8 46, label %15
]
15: ; preds = %12
%16 = getelementptr inbounds i8, i8* %1, i64 1
%17 = load i8, i8* %16
switch i8 %17, label %29 [
i8 47, label %22
i8 46, label %18
]
18: ; preds = %15
%19 = getelementptr inbounds i8, i8* %1, i64 2
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 47
br i1 %21, label %22, label %29
22: ; preds = %15, %12, %18
%23 = call i32 @strcat(i8* %5, i8* %1)
%24 = call i32 @load_as_file(i8* %5, %struct.stat* %2)
%25 = icmp eq i32 %24, 0
br i1 %25, label %51, label %26
26: ; preds = %22
%27 = call i32 @load_as_directory(i8* %5, %struct.stat* %2)
%28 = icmp eq i32 %27, 0
br i1 %28, label %51, label %29
29: ; preds = %15, %12, %26, %18
%30 = icmp sgt i32 %6, 0
br i1 %30, label %31, label %51
31: ; preds = %29
%32 = zext i32 %6 to i64
br label %33
33: ; preds = %31, %49
%34 = phi i64 [ %32, %31 ], [ %35, %49 ]
%35 = add nsw i64 %34, -1
%36 = and i64 %35, 4294967295
%37 = getelementptr inbounds i8, i8* %0, i64 %36
%38 = load i8, i8* %37
%39 = icmp eq i8 %38, 47
br i1 %39, label %40, label %49
40: ; preds = %33
%41 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 %34
store i8 0, i8* %41
%42 = call i32 @strcat(i8* %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @strcat(i8* %5, i8* %1)
%44 = call i32 @load_as_file(i8* %5, %struct.stat* %2)
%45 = icmp eq i32 %44, 0
br i1 %45, label %51, label %46
46: ; preds = %40
%47 = call i32 @load_as_directory(i8* %5, %struct.stat* %2)
%48 = icmp eq i32 %47, 0
br i1 %48, label %51, label %49
49: ; preds = %33, %46
%50 = icmp ugt i64 %34, 1
br i1 %50, label %33, label %51
51: ; preds = %40, %46, %49, %29, %26, %22, %3, %9
%52 = phi i32 [ 0, %9 ], [ 0, %3 ], [ 0, %22 ], [ 0, %26 ], [ -1, %29 ], [ 0, %40 ], [ 0, %46 ], [ -1, %49 ]
ret i32 %52
}