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

/* Variables and functions */
int node_require(char *, char const *, struct stat *);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
__attribute__((always_)) void node_require_test(char *cwd, const char *s,
                                                struct stat *require_stat) {
  int result;
  int cl = strlen(cwd);
  if (cwd[cl - 1] != '/') {
    cwd[cl] = '/';
    cwd[cl + 1] = '\0';
    cl++;
  }
  result = node_require(cwd, s, require_stat);
  printf("require %s = %d\n", s, result);
  if (!result) {
    printf("File size: %zu bytes\n", require_stat->st_size);
  } else {
    printf("File not found\n");
  }
}


x86 assembly (clang, -O0):
<node_require_test>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x2f,%eax
je     1190 <node_require_test+0x60>
mov    -0x8(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x2f,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1030 <node_require@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x10(%rbp),%rsi
mov    -0x1c(%rbp),%edx
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    11dc <node_require_test+0xac>
mov    -0x18(%rbp),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11ea <node_require_test+0xba>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<node_require_test>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%rbx
call   1050 <strlen@plt>
cltq
cmpb   $0x2f,-0x1(%rax,%rbx,1)
je     1162 <node_require_test+0x22>
movw   $0x2f,(%rbx,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r14,%rdx
call   1030 <node_require@plt>
mov    %eax,%ebx
lea    0xe87(%rip),%rdi
mov    %r15,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1060 <printf@plt>
test   %ebx,%ebx
je     119a <node_require_test+0x5a>
lea    0xe97(%rip),%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <puts@plt>
mov    (%r14),%esi
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1060 <printf@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [17 x i8] c"require %s = %d\0A\00"
@.str.1 = [22 x i8] c"File size: %zu bytes\0A\00"
@.str.2 = [16 x i8] c"File not found\0A\00"
define void @node_require_test(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** %4
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i8*, i8** %4
%12 = load i32, i32* %8
%13 = sub nsw i32 %12, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %11, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 47
br i1 %18, label %19, label %31
19: ; preds = %3
%20 = load i8*, i8** %4
%21 = load i32, i32* %8
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
store i8 47, i8* %23
%24 = load i8*, i8** %4
%25 = load i32, i32* %8
%26 = add nsw i32 %25, 1
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %24, i64 %27
store i8 0, i8* %28
%29 = load i32, i32* %8
%30 = add nsw i32 %29, 1
store i32 %30, i32* %8
br label %31
31: ; preds = %19, %3
%32 = load i8*, i8** %4
%33 = load i8*, i8** %5
%34 = load %struct.stat*, %struct.stat** %6
%35 = call i32 @node_require(i8* %32, i8* %33, %struct.stat* %34)
store i32 %35, i32* %7
%36 = load i8*, i8** %5
%37 = load i32, i32* %7
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %36, i32 %37)
%39 = load i32, i32* %7
%40 = icmp ne i32 %39, 0
br i1 %40, label %46, label %41
41: ; preds = %31
%42 = load %struct.stat*, %struct.stat** %6
%43 = getelementptr inbounds %struct.stat, %struct.stat* %42, i32 0, i32 0
%44 = load i32, i32* %43
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %44)
br label %48
46: ; preds = %31
%47 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0))
br label %48
48: ; preds = %46, %41
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [17 x i8] c"require %s = %d\0A\00"
@.str.1 = [22 x i8] c"File size: %zu bytes\0A\00"
@str = [15 x i8] c"File not found\00"
define void @node_require_test(i8* %0, i8* %1, %struct.stat* %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, -1
%6 = sext i32 %5 to i64
%7 = getelementptr inbounds i8, i8* %0, i64 %6
%8 = load i8, i8* %7
%9 = icmp eq i8 %8, 47
br i1 %9, label %16, label %10
10: ; preds = %3
%11 = sext i32 %4 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
store i8 47, i8* %12
%13 = add nsw i32 %4, 1
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %0, i64 %14
store i8 0, i8* %15
br label %16
16: ; preds = %10, %3
%17 = tail call i32 @node_require(i8* %0, i8* %1, %struct.stat* %2)
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %1, i32 %17)
%19 = icmp eq i32 %17, 0
br i1 %19, label %20, label %24
20: ; preds = %16
%21 = getelementptr inbounds %struct.stat, %struct.stat* %2, i64 0, i32 0
%22 = load i32, i32* %21
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), i32 %22)
br label %26
24: ; preds = %16
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @str, i64 0, i64 0))
br label %26
26: ; preds = %24, %20
ret void
}