#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 int encrypt(unsigned char **, int /*<<< orphan*/ *,
                     int /*<<< orphan*/);
int /*<<< orphan*/ free(unsigned char *);
unsigned int detect_secret_padded_len(unsigned int prefix_len,
                                      unsigned int block_size) {
  unsigned char *cipher0;
  unsigned int clen0 = 0;
  clen0 = encrypt(&cipher0, NULL, 0);
  if (NULL == cipher0 || 0 == clen0)
    return 0;
  free(cipher0);
  return clen0 - (prefix_len - (prefix_len % block_size));
}


x86 assembly (clang, -O0):
<detect_secret_padded_len>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
lea    -0x18(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <encrypt@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
je     115e <detect_secret_padded_len+0x3e>
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
jne    116a <detect_secret_padded_len+0x4a>
movl   $0x0,-0x4(%rbp)
jmp    118e <detect_secret_padded_len+0x6e>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x20(%rbp)
mov    -0x8(%rbp),%ecx
mov    -0x8(%rbp),%eax
xor    %edx,%edx
divl   -0xc(%rbp)
mov    -0x20(%rbp),%eax
sub    %edx,%ecx
sub    %ecx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<detect_secret_padded_len>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %edi,%r15d
xor    %ebx,%ebx
mov    %rsp,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <encrypt@plt>
mov    (%rsp),%rdi
test   %rdi,%rdi
je     115e <detect_secret_padded_len+0x3e>
mov    %eax,%ebp
test   %eax,%eax
je     115e <detect_secret_padded_len+0x3e>
call   1030 <free@plt>
mov    %r15d,%eax
xor    %edx,%edx
div    %r14d
sub    %r15d,%ebp
add    %edx,%ebp
mov    %ebp,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @detect_secret_padded_len(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 0, i32* %7
%8 = call i32 @encrypt(i8** %6, i32* null, i32 0)
store i32 %8, i32* %7
%9 = load i8*, i8** %6
%10 = icmp eq i8* null, %9
br i1 %10, label %14, label %11
11: ; preds = %2
%12 = load i32, i32* %7
%13 = icmp eq i32 0, %12
br i1 %13, label %14, label %15
14: ; preds = %11, %2
store i32 0, i32* %3
br label %25
15: ; preds = %11
%16 = load i8*, i8** %6
%17 = call i32 @free(i8* %16)
%18 = load i32, i32* %7
%19 = load i32, i32* %4
%20 = load i32, i32* %4
%21 = load i32, i32* %5
%22 = urem i32 %20, %21
%23 = sub i32 %19, %22
%24 = sub i32 %18, %23
store i32 %24, i32* %3
br label %25
25: ; preds = %15, %14
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
define i32 @detect_secret_padded_len(i32 %0, i32 %1) {
%3 = alloca i8*
%4 = bitcast i8** %3 to i8*
%5 = call i32 @encrypt(i8** %3, i32* null, i32 0)
%6 = load i8*, i8** %3
%7 = icmp eq i8* %6, null
%8 = icmp eq i32 %5, 0
%9 = select i1 %7, i1 true, i1 %8
br i1 %9, label %15, label %10
10: ; preds = %2
%11 = call i32 @free(i8* %6)
%12 = urem i32 %0, %1
%13 = sub i32 %5, %0
%14 = add i32 %13, %12
br label %15
15: ; preds = %2, %10
%16 = phi i32 [ %14, %10 ], [ 0, %2 ]
ret i32 %16
}