#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 pkcs7_depadding(void const *, unsigned int);
unsigned char pkcs7_padding_plus_len(unsigned int, unsigned char);
unsigned int pkcs7_depadding_blocksize(const void *_data,
                                       unsigned int _datapaddinglen,
                                       unsigned char _blocksize) {
  unsigned int data_depadding_len = 0;
  unsigned char verify_plus_len = 0;
  unsigned char plus_len = 0;
  data_depadding_len = pkcs7_depadding(_data, _datapaddinglen);
  if (0 == data_depadding_len)
    return 0;
  verify_plus_len = pkcs7_padding_plus_len(data_depadding_len, _blocksize);
  if (0 == verify_plus_len)
    return 0;
  plus_len = ((const unsigned char *)_data)[_datapaddinglen - 1];
  if (0 == plus_len)
    return 0;
  if (verify_plus_len != plus_len)
    return 0;
  return data_depadding_len;
}


x86 assembly (clang, -O0):
<pkcs7_depadding_blocksize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %al,-0x15(%rbp)
movl   $0x0,-0x1c(%rbp)
movb   $0x0,-0x1d(%rbp)
movb   $0x0,-0x1e(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
call   1040 <pkcs7_depadding@plt>
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmp    -0x1c(%rbp),%eax
jne    1169 <pkcs7_depadding_blocksize+0x49>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <pkcs7_depadding_blocksize+0xc0>
mov    -0x1c(%rbp),%edi
movzbl -0x15(%rbp),%esi
call   1030 <pkcs7_padding_plus_len@plt>
mov    %al,-0x1d(%rbp)
movzbl -0x1d(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    1192 <pkcs7_depadding_blocksize+0x72>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <pkcs7_depadding_blocksize+0xc0>
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1e(%rbp)
movzbl -0x1e(%rbp),%ecx
xor    %eax,%eax
cmp    %ecx,%eax
jne    11be <pkcs7_depadding_blocksize+0x9e>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <pkcs7_depadding_blocksize+0xc0>
movzbl -0x1d(%rbp),%eax
movzbl -0x1e(%rbp),%ecx
cmp    %ecx,%eax
je     11da <pkcs7_depadding_blocksize+0xba>
movl   $0x0,-0x4(%rbp)
jmp    11e0 <pkcs7_depadding_blocksize+0xc0>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pkcs7_depadding_blocksize>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r12d
mov    %esi,%ebx
mov    %rdi,%r15
call   1040 <pkcs7_depadding@plt>
xor    %r14d,%r14d
test   %eax,%eax
je     1161 <pkcs7_depadding_blocksize+0x41>
mov    %eax,%ebp
movzbl %r12b,%esi
mov    %eax,%edi
call   1030 <pkcs7_padding_plus_len@plt>
test   %al,%al
je     1161 <pkcs7_depadding_blocksize+0x41>
add    $0xffffffff,%ebx
mov    (%r15,%rbx,1),%cl
test   %cl,%cl
je     1161 <pkcs7_depadding_blocksize+0x41>
xor    %r14d,%r14d
cmp    %cl,%al
cmove  %ebp,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
define i32 @pkcs7_depadding_blocksize(i8* %0, i32 %1, i8 zeroext %2) {
%4 = tail call i32 @pkcs7_depadding(i8* %0, i32 %1)
%5 = icmp eq i32 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = tail call zeroext i8 @pkcs7_padding_plus_len(i32 %4, i8 zeroext %2)
%8 = icmp eq i8 %7, 0
br i1 %8, label %18, label %9
9: ; preds = %6
%10 = add i32 %1, -1
%11 = zext i32 %10 to i64
%12 = getelementptr inbounds i8, i8* %0, i64 %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = icmp eq i8 %7, %13
%17 = select i1 %16, i32 %4, i32 0
br label %18
18: ; preds = %15, %9, %6, %3
%19 = phi i32 [ 0, %3 ], [ 0, %6 ], [ 0, %9 ], [ %17, %15 ]
ret i32 %19
}