#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 strlen(char *);
int validate_pcks(const unsigned char *input) {
  unsigned int msg_len = strlen((char *)input);
  unsigned char pad_len = input[msg_len - 1];
  unsigned char *pad_byte = ((unsigned char *)input) + msg_len - 1;
  while (pad_byte > input + msg_len - pad_len) {
    if (*pad_byte != pad_len)
      return 0x00;
    pad_byte--;
  }
  return 0x1;
}


x86 assembly (clang, -O0):
<validate_pcks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
mov    %ecx,%ecx
mov    (%rax,%rcx,1),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
add    %rcx,%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    -0x14(%rbp),%edx
add    %rdx,%rcx
movzbl -0x15(%rbp),%edx
movslq %edx,%rsi
xor    %edx,%edx
sub    %rsi,%rdx
add    %rdx,%rcx
cmp    %rcx,%rax
jbe    11a2 <validate_pcks+0x92>
mov    -0x20(%rbp),%rax
movzbl (%rax),%eax
movzbl -0x15(%rbp),%ecx
cmp    %ecx,%eax
je     1191 <validate_pcks+0x81>
movl   $0x0,-0x4(%rbp)
jmp    11a9 <validate_pcks+0x99>
mov    -0x20(%rbp),%rax
add    $0xffffffffffffffff,%rax
mov    %rax,-0x20(%rbp)
jmp    114c <validate_pcks+0x3c>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_pcks>:
push   %rbx
mov    %rdi,%rbx
call   1030 <strlen@plt>
lea    -0x1(%rax),%ecx
movzbl (%rbx,%rcx,1),%ecx
mov    %eax,%edx
lea    (%rbx,%rdx,1),%rax
sub    %rcx,%rax
add    %rbx,%rdx
add    $0xffffffffffffffff,%rdx
cmp    %rax,%rdx
jbe    1144 <validate_pcks+0x34>
lea    -0x1(%rdx),%rsi
cmp    %cl,(%rdx)
mov    %rsi,%rdx
je     1130 <validate_pcks+0x20>
xor    %eax,%eax
pop    %rbx
ret
mov    $0x1,%eax
pop    %rbx
ret

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

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