#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 superblock_type {
  int dummy;
};
typedef int int32_t;

/* Variables and functions */
int /*<<< orphan*/ romfs_read_noinc(struct superblock_type *, int *, int, int);
int32_t romfs_inode_follow_links(struct superblock_type *sb, int32_t inode) {
  int32_t header_offset, temp_int;
  int32_t type, spec_info;
inode_link_loop:
  header_offset = inode;
  romfs_read_noinc(sb, &temp_int, header_offset, 4);
  type = (((temp_int) << 24 & 0xFF000000UL) | ((temp_int) << 8 & 0x00FF0000UL) |
          ((temp_int) >> 8 & 0x0000FF00UL) | ((temp_int) >> 24 & 0x000000FFUL));
  type &= 0x7;
  header_offset += 4;
  romfs_read_noinc(sb, &temp_int, header_offset, 4);
  spec_info =
      (((temp_int) << 24 & 0xFF000000UL) | ((temp_int) << 8 & 0x00FF0000UL) |
       ((temp_int) >> 8 & 0x0000FF00UL) | ((temp_int) >> 24 & 0x000000FFUL));
  if (type == 0) {
    inode = spec_info;
    goto inode_link_loop;
  }
  return inode;
}


x86 assembly (clang, -O0):
<romfs_inode_follow_links>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    -0x14(%rbp),%rsi
mov    $0x4,%ecx
call   1030 <romfs_read_noinc@plt>
mov    -0x14(%rbp),%eax
shl    $0x18,%eax
cltq
movabs $0xff000000,%rcx
and    %rcx,%rax
mov    -0x14(%rbp),%ecx
shl    $0x8,%ecx
movslq %ecx,%rcx
and    $0xff0000,%rcx
or     %rcx,%rax
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
movslq %ecx,%rcx
and    $0xff00,%rcx
or     %rcx,%rax
mov    -0x14(%rbp),%ecx
sar    $0x18,%ecx
movslq %ecx,%rcx
and    $0xff,%rcx
or     %rcx,%rax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%eax
and    $0x7,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%edx
lea    -0x14(%rbp),%rsi
mov    $0x4,%ecx
call   1030 <romfs_read_noinc@plt>
mov    -0x14(%rbp),%eax
shl    $0x18,%eax
cltq
movabs $0xff000000,%rcx
and    %rcx,%rax
mov    -0x14(%rbp),%ecx
shl    $0x8,%ecx
movslq %ecx,%rcx
and    $0xff0000,%rcx
or     %rcx,%rax
mov    -0x14(%rbp),%ecx
sar    $0x8,%ecx
movslq %ecx,%rcx
and    $0xff00,%rcx
or     %rcx,%rax
mov    -0x14(%rbp),%ecx
sar    $0x18,%ecx
movslq %ecx,%rcx
and    $0xff,%rcx
or     %rcx,%rax
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1218 <romfs_inode_follow_links+0x108>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
jmp    111f <romfs_inode_follow_links+0xf>
mov    -0xc(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<romfs_inode_follow_links>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %rdi,%r14
lea    0x4(%rsp),%r15
mov    %r15,%rsi
mov    %ebx,%edx
mov    $0x4,%ecx
call   1030 <romfs_read_noinc@plt>
lea    0x4(%rbx),%edx
mov    0x4(%rsp),%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%ecx
call   1030 <romfs_read_noinc@plt>
test   $0x7000000,%ebp
jne    1197 <romfs_inode_follow_links+0x87>
lea    0x4(%rsp),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    0x4(%rsp),%ebx
bswap  %ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
mov    $0x4,%ecx
call   1030 <romfs_read_noinc@plt>
lea    0x4(%rbx),%edx
mov    0x4(%rsp),%ebp
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x4,%ecx
call   1030 <romfs_read_noinc@plt>
test   $0x7000000,%ebp
je     1160 <romfs_inode_follow_links+0x50>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.superblock_type = type { i32 }
define i32 @romfs_inode_follow_links(%struct.superblock_type* %0, i32 %1) {
%3 = alloca %struct.superblock_type*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.superblock_type* %0, %struct.superblock_type** %3
store i32 %1, i32* %4
br label %9
9: ; preds = %63, %2
%10 = load i32, i32* %4
store i32 %10, i32* %5
%11 = load %struct.superblock_type*, %struct.superblock_type** %3
%12 = load i32, i32* %5
%13 = call i32 @romfs_read_noinc(%struct.superblock_type* %11, i32* %6, i32 %12, i32 4)
%14 = load i32, i32* %6
%15 = shl i32 %14, 24
%16 = sext i32 %15 to i64
%17 = and i64 %16, 4278190080
%18 = load i32, i32* %6
%19 = shl i32 %18, 8
%20 = sext i32 %19 to i64
%21 = and i64 %20, 16711680
%22 = or i64 %17, %21
%23 = load i32, i32* %6
%24 = ashr i32 %23, 8
%25 = sext i32 %24 to i64
%26 = and i64 %25, 65280
%27 = or i64 %22, %26
%28 = load i32, i32* %6
%29 = ashr i32 %28, 24
%30 = sext i32 %29 to i64
%31 = and i64 %30, 255
%32 = or i64 %27, %31
%33 = trunc i64 %32 to i32
store i32 %33, i32* %7
%34 = load i32, i32* %7
%35 = and i32 %34, 7
store i32 %35, i32* %7
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 4
store i32 %37, i32* %5
%38 = load %struct.superblock_type*, %struct.superblock_type** %3
%39 = load i32, i32* %5
%40 = call i32 @romfs_read_noinc(%struct.superblock_type* %38, i32* %6, i32 %39, i32 4)
%41 = load i32, i32* %6
%42 = shl i32 %41, 24
%43 = sext i32 %42 to i64
%44 = and i64 %43, 4278190080
%45 = load i32, i32* %6
%46 = shl i32 %45, 8
%47 = sext i32 %46 to i64
%48 = and i64 %47, 16711680
%49 = or i64 %44, %48
%50 = load i32, i32* %6
%51 = ashr i32 %50, 8
%52 = sext i32 %51 to i64
%53 = and i64 %52, 65280
%54 = or i64 %49, %53
%55 = load i32, i32* %6
%56 = ashr i32 %55, 24
%57 = sext i32 %56 to i64
%58 = and i64 %57, 255
%59 = or i64 %54, %58
%60 = trunc i64 %59 to i32
store i32 %60, i32* %8
%61 = load i32, i32* %7
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %65
63: ; preds = %9
%64 = load i32, i32* %8
store i32 %64, i32* %4
br label %9
65: ; preds = %9
%66 = load i32, i32* %4
ret i32 %66
}

LLVM IR (-O2):
%struct.superblock_type = type { i32 }
define i32 @romfs_inode_follow_links(%struct.superblock_type* %0, i32 %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = call i32 @romfs_read_noinc(%struct.superblock_type* %0, i32* %3, i32 %1, i32 4)
%6 = load i32, i32* %3
%7 = add nsw i32 %1, 4
%8 = call i32 @romfs_read_noinc(%struct.superblock_type* %0, i32* %3, i32 %7, i32 4)
%9 = and i32 %6, 117440512
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %20
11: ; preds = %2, %11
%12 = load i32, i32* %3
%13 = call i32 @llvm.bswap.i32(i32 %12)
%14 = call i32 @romfs_read_noinc(%struct.superblock_type* %0, i32* %3, i32 %13, i32 4)
%15 = load i32, i32* %3
%16 = add nsw i32 %13, 4
%17 = call i32 @romfs_read_noinc(%struct.superblock_type* %0, i32* %3, i32 %16, i32 4)
%18 = and i32 %15, 117440512
%19 = icmp eq i32 %18, 0
br i1 %19, label %11, label %20
20: ; preds = %11, %2
%21 = phi i32 [ %1, %2 ], [ %13, %11 ]
ret i32 %21
}