#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 */

/* Variables and functions */
unsigned char detect_byte(unsigned char *, unsigned int, unsigned int,
                          unsigned int, unsigned int);
void detect_block(unsigned char *decoded_string, unsigned int prefix_len,
                  unsigned int block_idx, unsigned int block_size) {
  unsigned int byte_idx;
  unsigned int block_length = ((138) - block_idx * block_size > block_size)
                                  ? block_size
                                  : (138) - block_idx * block_size;
  for (byte_idx = 0; byte_idx < block_length; byte_idx++)
    decoded_string[block_idx * block_size + byte_idx] = detect_byte(
        decoded_string, prefix_len, byte_idx, block_idx, block_size);
}


x86 assembly (clang, -O0):
<detect_block>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    -0x10(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    $0x8a,%eax
sub    %ecx,%eax
cmp    -0x14(%rbp),%eax
jbe    1147 <detect_block+0x37>
mov    -0x14(%rbp),%eax
mov    %eax,-0x20(%rbp)
jmp    1158 <detect_block+0x48>
mov    -0x10(%rbp),%ecx
imul   -0x14(%rbp),%ecx
mov    $0x8a,%eax
sub    %ecx,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jae    11aa <detect_block+0x9a>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%edx
mov    -0x10(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1030 <detect_byte@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
imul   -0x14(%rbp),%ecx
add    -0x18(%rbp),%ecx
mov    %ecx,%ecx
mov    %dl,(%rax,%rcx,1)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1165 <detect_block+0x55>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_block>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r12d
mov    %ecx,%eax
imul   %edx,%eax
mov    $0x8a,%edx
sub    %eax,%edx
cmp    %ecx,%edx
cmova  %ecx,%edx
test   %edx,%edx
je     1176 <detect_block+0x66>
mov    %ecx,%ebp
mov    %esi,%r15d
mov    %rdi,%r13
mov    %edx,%edx
mov    %rdx,(%rsp)
mov    %eax,%r14d
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
mov    %r13,%rdi
mov    %r15d,%esi
mov    %ebx,%edx
mov    %r12d,%ecx
mov    %ebp,%r8d
call   1030 <detect_byte@plt>
lea    (%r14,%rbx,1),%edx
mov    %al,0x0(%r13,%rdx,1)
add    $0x1,%rbx
cmp    %rbx,(%rsp)
jne    1150 <detect_block+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @detect_block(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%11 = load i32, i32* %7
%12 = load i32, i32* %8
%13 = mul i32 %11, %12
%14 = sub i32 138, %13
%15 = load i32, i32* %8
%16 = icmp ugt i32 %14, %15
br i1 %16, label %17, label %19
17: ; preds = %4
%18 = load i32, i32* %8
br label %24
19: ; preds = %4
%20 = load i32, i32* %7
%21 = load i32, i32* %8
%22 = mul i32 %20, %21
%23 = sub i32 138, %22
br label %24
24: ; preds = %19, %17
%25 = phi i32 [ %18, %17 ], [ %23, %19 ]
store i32 %25, i32* %10
store i32 0, i32* %9
br label %26
26: ; preds = %45, %24
%27 = load i32, i32* %9
%28 = load i32, i32* %10
%29 = icmp ult i32 %27, %28
br i1 %29, label %30, label %48
30: ; preds = %26
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = load i32, i32* %9
%34 = load i32, i32* %7
%35 = load i32, i32* %8
%36 = call zeroext i8 @detect_byte(i8* %31, i32 %32, i32 %33, i32 %34, i32 %35)
%37 = load i8*, i8** %5
%38 = load i32, i32* %7
%39 = load i32, i32* %8
%40 = mul i32 %38, %39
%41 = load i32, i32* %9
%42 = add i32 %40, %41
%43 = zext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %37, i64 %43
store i8 %36, i8* %44
br label %45
45: ; preds = %30
%46 = load i32, i32* %9
%47 = add i32 %46, 1
store i32 %47, i32* %9
br label %26
48: ; preds = %26
ret void
}

LLVM IR (-O2):
define void @detect_block(i8* %0, i32 %1, i32 %2, i32 %3) {
%5 = mul i32 %3, %2
%6 = sub i32 138, %5
%7 = icmp ugt i32 %6, %3
%8 = select i1 %7, i32 %3, i32 %6
%9 = icmp eq i32 %8, 0
br i1 %9, label %21, label %10
10: ; preds = %4
%11 = zext i32 %8 to i64
br label %12
12: ; preds = %10, %12
%13 = phi i64 [ 0, %10 ], [ %19, %12 ]
%14 = trunc i64 %13 to i32
%15 = tail call zeroext i8 @detect_byte(i8* %0, i32 %1, i32 %14, i32 %2, i32 %3)
%16 = add i32 %5, %14
%17 = zext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %0, i64 %17
store i8 %15, i8* %18
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %11
br i1 %20, label %21, label %12
21: ; preds = %12, %4
ret void
}