#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 jffs2_raw_inode {
  int dummy;
};
struct jffs2_raw_dirent {
  scalar_t__ type;
};
typedef scalar_t__ __u32;

/* Variables and functions */
scalar_t__ DT_REG;
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
struct jffs2_raw_inode *find_raw_inode(char *, size_t, scalar_t__);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ putblock(char *, size_t, size_t *, struct jffs2_raw_inode *);
struct jffs2_raw_dirent *resolvepath(char *, size_t, int, char *, scalar_t__ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ write(int, char *, size_t);
void catfile(char *o, size_t size, char *path, char *b, size_t bsize,
             size_t *rsize) {
  struct jffs2_raw_dirent *dd;
  struct jffs2_raw_inode *ri;
  __u32 ino;
  dd = resolvepath(o, size, 1, path, &ino);
  if (ino == 0) {
    fprintf(stderr, "%s: No such file or directory\n", path);
    exit(EXIT_FAILURE);
  }
  if (dd == NULL || dd->type != DT_REG) {
    fprintf(stderr, "%s: Not a regular file\n", path);
    exit(EXIT_FAILURE);
  }
  ri = find_raw_inode(o, size, ino);
  putblock(b, bsize, rsize, ri);
  write(1, b, *rsize);
}


x86 assembly (clang, -O0):
<catfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
mov    $0x1,%edx
lea    -0x48(%rbp),%r8
call   1030 <resolvepath@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    11d0 <catfile+0x70>
mov    0x2e28(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
cmpq   $0x0,-0x38(%rbp)
je     11f2 <catfile+0x92>
mov    -0x38(%rbp),%rax
mov    (%rax),%rax
mov    0x2df7(%rip),%rcx
cmp    (%rcx),%rax
je     1219 <catfile+0xb9>
mov    0x2ddf(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe19(%rip),%rsi
call   1060 <fprintf@plt>
mov    0x2dbe(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x48(%rbp),%rdx
call   1070 <find_raw_inode@plt>
mov    %rax,-0x40(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x40(%rbp),%rcx
call   1050 <putblock@plt>
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rax
mov    (%rax),%rdx
mov    $0x1,%edi
call   1040 <write@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<catfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9,%r13
mov    %r8,%r12
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%rbp
mov    %rsp,%r8
mov    $0x1,%edx
mov    %r15,%rcx
call   1030 <resolvepath@plt>
mov    (%rsp),%rdx
test   %rdx,%rdx
je     11f8 <catfile+0x98>
test   %rax,%rax
je     11e6 <catfile+0x86>
mov    (%rax),%rax
mov    0x2e3b(%rip),%rcx
cmp    (%rcx),%rax
jne    11e6 <catfile+0x86>
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <find_raw_inode@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13,%rdx
mov    %rax,%rcx
call   1050 <putblock@plt>
mov    0x0(%r13),%rdx
mov    $0x1,%edi
mov    %r14,%rsi
call   1040 <write@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2deb(%rip),%rax
mov    (%rax),%edi
lea    0xe29(%rip),%rsi
jmp    1208 <catfile+0xa8>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xdf8(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
mov    0x2db9(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
%struct.jffs2_raw_dirent = type { i64 }
%struct.jffs2_raw_inode = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"%s: No such file or directory\0A\00"
@EXIT_FAILURE = global i32 0
@DT_REG = global i64 0
@.str.1 = [24 x i8] c"%s: Not a regular file\0A\00"
define void @catfile(i8* %0, i64 %1, i8* %2, i8* %3, i64 %4, i64* %5) {
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i64
%12 = alloca i64*
%13 = alloca %struct.jffs2_raw_dirent*
%14 = alloca %struct.jffs2_raw_inode*
%15 = alloca i64
store i8* %0, i8** %7
store i64 %1, i64* %8
store i8* %2, i8** %9
store i8* %3, i8** %10
store i64 %4, i64* %11
store i64* %5, i64** %12
%16 = load i8*, i8** %7
%17 = load i64, i64* %8
%18 = load i8*, i8** %9
%19 = call %struct.jffs2_raw_dirent* @resolvepath(i8* %16, i64 %17, i32 1, i8* %18, i64* %15)
store %struct.jffs2_raw_dirent* %19, %struct.jffs2_raw_dirent** %13
%20 = load i64, i64* %15
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %28
22: ; preds = %6
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %9
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %24)
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; preds = %6
%29 = load %struct.jffs2_raw_dirent*, %struct.jffs2_raw_dirent** %13
%30 = icmp eq %struct.jffs2_raw_dirent* %29, null
br i1 %30, label %37, label %31
31: ; preds = %28
%32 = load %struct.jffs2_raw_dirent*, %struct.jffs2_raw_dirent** %13
%33 = getelementptr inbounds %struct.jffs2_raw_dirent, %struct.jffs2_raw_dirent* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = load i64, i64* @DT_REG
%36 = icmp ne i64 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %31, %28
%38 = load i32, i32* @stderr
%39 = load i8*, i8** %9
%40 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %39)
%41 = load i32, i32* @EXIT_FAILURE
%42 = call i32 @exit(i32 %41)
unreachable
43: ; preds = %31
%44 = load i8*, i8** %7
%45 = load i64, i64* %8
%46 = load i64, i64* %15
%47 = call %struct.jffs2_raw_inode* @find_raw_inode(i8* %44, i64 %45, i64 %46)
store %struct.jffs2_raw_inode* %47, %struct.jffs2_raw_inode** %14
%48 = load i8*, i8** %10
%49 = load i64, i64* %11
%50 = load i64*, i64** %12
%51 = load %struct.jffs2_raw_inode*, %struct.jffs2_raw_inode** %14
%52 = call i32 @putblock(i8* %48, i64 %49, i64* %50, %struct.jffs2_raw_inode* %51)
%53 = load i8*, i8** %10
%54 = load i64*, i64** %12
%55 = load i64, i64* %54
%56 = call i32 @write(i32 1, i8* %53, i64 %55)
ret void
}

LLVM IR (-O2):
%struct.jffs2_raw_dirent = type { i64 }
%struct.jffs2_raw_inode = type { i32 }
@stderr = global i32 0
@.str = [31 x i8] c"%s: No such file or directory\0A\00"
@EXIT_FAILURE = global i32 0
@DT_REG = global i64 0
@.str.1 = [24 x i8] c"%s: Not a regular file\0A\00"
define void @catfile(i8* %0, i64 %1, i8* %2, i8* %3, i64 %4, i64* %5) {
%7 = alloca i64
%8 = bitcast i64* %7 to i8*
%9 = call %struct.jffs2_raw_dirent* @resolvepath(i8* %0, i64 %1, i32 1, i8* %2, i64* %7)
%10 = load i64, i64* %7
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %17
12: ; preds = %6
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str, i64 0, i64 0), i8* %2)
%15 = load i32, i32* @EXIT_FAILURE
%16 = call i32 @exit(i32 %15)
unreachable
17: ; preds = %6
%18 = icmp eq %struct.jffs2_raw_dirent* %9, null
br i1 %18, label %24, label %19
19: ; preds = %17
%20 = getelementptr inbounds %struct.jffs2_raw_dirent, %struct.jffs2_raw_dirent* %9, i64 0, i32 0
%21 = load i64, i64* %20
%22 = load i64, i64* @DT_REG
%23 = icmp eq i64 %21, %22
br i1 %23, label %29, label %24
24: ; preds = %19, %17
%25 = load i32, i32* @stderr
%26 = call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%27 = load i32, i32* @EXIT_FAILURE
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %19
%30 = call %struct.jffs2_raw_inode* @find_raw_inode(i8* %0, i64 %1, i64 %10)
%31 = call i32 @putblock(i8* %3, i64 %4, i64* %5, %struct.jffs2_raw_inode* %30)
%32 = load i64, i64* %5
%33 = call i32 @write(i32 1, i8* %3, i64 %32)
ret void
}