#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 *, char *, int, int);
int32_t romfs_string_length_chunks(struct superblock_type *sb, int32_t offset) {
  char temp_buffer[16];
  int32_t our_offset = offset;
  int32_t max_length = 0;
  while (1) {
    romfs_read_noinc(sb, temp_buffer, our_offset, 16);
    our_offset += 16;
    if (temp_buffer[15] == 0) {
      max_length += 16;
      break;
    }
    max_length += 16;
  }
  return max_length;
}


x86 assembly (clang, -O0):
<romfs_string_length_chunks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    -0x24(%rbp),%edx
mov    $0x10,%ecx
call   1030 <romfs_read_noinc@plt>
mov    -0x24(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    1165 <romfs_string_length_chunks+0x55>
mov    -0x28(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    1173 <romfs_string_length_chunks+0x63>
mov    -0x28(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    112c <romfs_string_length_chunks+0x1c>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<romfs_string_length_chunks>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
mov    %rsp,%rsi
mov    $0x10,%ebx
mov    %r14d,%edx
mov    $0x10,%ecx
call   1030 <romfs_read_noinc@plt>
cmpb   $0x0,0xf(%rsp)
je     116e <romfs_string_length_chunks+0x5e>
mov    $0x10,%ebx
mov    %rsp,%r12
cs nopw 0x0(%rax,%rax,1)
nop
lea    (%r14,%rbx,1),%edx
add    $0x10,%ebx
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x10,%ecx
call   1030 <romfs_read_noinc@plt>
cmpb   $0x0,0xf(%rsp)
jne    1150 <romfs_string_length_chunks+0x40>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.superblock_type = type { i32 }
define i32 @romfs_string_length_chunks(%struct.superblock_type* %0, i32 %1) {
%3 = alloca %struct.superblock_type*
%4 = alloca i32
%5 = alloca [16 x i8]
%6 = alloca i32
%7 = alloca i32
store %struct.superblock_type* %0, %struct.superblock_type** %3
store i32 %1, i32* %4
%8 = load i32, i32* %4
store i32 %8, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %2, %23
%10 = load %struct.superblock_type*, %struct.superblock_type** %3
%11 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%12 = load i32, i32* %6
%13 = call i32 @romfs_read_noinc(%struct.superblock_type* %10, i8* %11, i32 %12, i32 16)
%14 = load i32, i32* %6
%15 = add nsw i32 %14, 16
store i32 %15, i32* %6
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %9
%21 = load i32, i32* %7
%22 = add nsw i32 %21, 16
store i32 %22, i32* %7
br label %26
23: ; preds = %9
%24 = load i32, i32* %7
%25 = add nsw i32 %24, 16
store i32 %25, i32* %7
br label %9
26: ; preds = %20
%27 = load i32, i32* %7
ret i32 %27
}

LLVM IR (-O2):
%struct.superblock_type = type { i32 }
define i32 @romfs_string_length_chunks(%struct.superblock_type* %0, i32 %1) {
%3 = alloca [16 x i8]
%4 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%5 = call i32 @romfs_read_noinc(%struct.superblock_type* %0, i8* %4, i32 %1, i32 16)
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 15
%7 = load i8, i8* %6
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %11
9: ; preds = %11, %2
%10 = phi i32 [ 16, %2 ], [ %15, %11 ]
ret i32 %10
11: ; preds = %2, %11
%12 = phi i32 [ %15, %11 ], [ 16, %2 ]
%13 = phi i32 [ %14, %11 ], [ %1, %2 ]
%14 = add nsw i32 %13, 16
%15 = add i32 %12, 16
%16 = call i32 @romfs_read_noinc(%struct.superblock_type* %0, i8* %4, i32 %14, i32 16)
%17 = load i8, i8* %6
%18 = icmp eq i8 %17, 0
br i1 %18, label %9, label %11
}