#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);
scalar_t__ strlen(char *);
int32_t romfs_string_length(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 += strlen(temp_buffer);
      break;
    }
    max_length += 16;
  }
  return max_length;
}


x86 assembly (clang, -O0):
<romfs_string_length>:
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   1040 <romfs_read_noinc@plt>
mov    -0x24(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x24(%rbp)
movsbl -0x11(%rbp),%eax
cmp    $0x0,%eax
jne    1182 <romfs_string_length+0x62>
lea    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,%rcx
movslq -0x28(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x28(%rbp)
jmp    1190 <romfs_string_length+0x70>
mov    -0x28(%rbp),%eax
add    $0x10,%eax
mov    %eax,-0x28(%rbp)
jmp    113c <romfs_string_length+0x1c>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<romfs_string_length>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %esi,%r12d
mov    %rdi,%r14
mov    %rsp,%rsi
mov    %r12d,%edx
mov    $0x10,%ecx
call   1040 <romfs_read_noinc@plt>
cmpb   $0x0,0xf(%rsp)
je     1180 <romfs_string_length+0x60>
add    $0x10,%r12d
xor    %ebx,%ebx
mov    %rsp,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    (%r12,%rbx,1),%edx
add    $0x10,%ebx
mov    %r14,%rdi
mov    %r15,%rsi
mov    $0x10,%ecx
call   1040 <romfs_read_noinc@plt>
cmpb   $0x0,0xf(%rsp)
jne    1160 <romfs_string_length+0x40>
jmp    1182 <romfs_string_length+0x62>
xor    %ebx,%ebx
mov    %rsp,%rdi
call   1030 <strlen@plt>
add    %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(%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, %27
%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 %27
20: ; preds = %9
%21 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
%22 = call i64 @strlen(i8* %21)
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = add nsw i64 %24, %22
%26 = trunc i64 %25 to i32
store i32 %26, i32* %7
br label %30
27: ; preds = %9
%28 = load i32, i32* %7
%29 = add nsw i32 %28, 16
store i32 %29, i32* %7
br label %9
30: ; preds = %20
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
%struct.superblock_type = type { i32 }
define i32 @romfs_string_length(%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 %14
9: ; preds = %14, %2
%10 = phi i32 [ 0, %2 ], [ %18, %14 ]
%11 = call i64 @strlen(i8* %4)
%12 = trunc i64 %11 to i32
%13 = add i32 %10, %12
ret i32 %13
14: ; preds = %2, %14
%15 = phi i32 [ %18, %14 ], [ 0, %2 ]
%16 = phi i32 [ %17, %14 ], [ %1, %2 ]
%17 = add nsw i32 %16, 16
%18 = add nuw nsw i32 %15, 16
%19 = call i32 @romfs_read_noinc(%struct.superblock_type* %0, i8* %4, i32 %17, i32 16)
%20 = load i8, i8* %6
%21 = icmp eq i8 %20, 0
br i1 %21, label %9, label %14
}