#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 /*<<< orphan*/ write(int, ...);
void generate_pcks(const unsigned char *input, const unsigned char pad_len) {
  char null_byte;
  unsigned char v;
  unsigned int j, msg_len = strlen((char *)input);
  write(1, input, msg_len);
  v = pad_len - (msg_len % pad_len);
  for (j = 0; j < v; j++) {
    write(1, &v, 1);
  }
  null_byte = 0x00;
  write(1, &null_byte, 1);
}


x86 assembly (clang, -O0):
<generate_pcks>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x14(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    $0x1,%edi
mov    $0x0,%al
call   1030 <write@plt>
movzbl -0x9(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x14(%rbp),%eax
movzbl -0x9(%rbp),%ecx
xor    %edx,%edx
div    %ecx
mov    -0x18(%rbp),%eax
sub    %edx,%eax
mov    %al,-0xb(%rbp)
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
movzbl -0xb(%rbp),%ecx
cmp    %ecx,%eax
jae    11a1 <generate_pcks+0x81>
mov    $0x1,%edx
lea    -0xb(%rbp),%rsi
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1172 <generate_pcks+0x52>
movb   $0x0,-0xa(%rbp)
mov    $0x1,%edx
lea    -0xa(%rbp),%rsi
mov    %edx,%edi
mov    $0x0,%al
call   1030 <write@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_pcks>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %esi,%ebx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    $0x1,%edi
mov    %r14,%rsi
mov    %eax,%edx
xor    %eax,%eax
call   1030 <write@plt>
mov    %ebp,%eax
xor    %edx,%edx
div    %ebx
sub    %dl,%bl
mov    %bl,0xe(%rsp)
je     1180 <generate_pcks+0x60>
lea    0xe(%rsp),%rbx
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    $0x1,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
add    $0x1,%ebp
movzbl 0xe(%rsp),%eax
cmp    %eax,%ebp
jb     1160 <generate_pcks+0x40>
movb   $0x0,0xf(%rsp)
lea    0xf(%rsp),%rsi
mov    $0x1,%edi
mov    $0x1,%edx
xor    %eax,%eax
call   1030 <write@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @generate_pcks(i8* %0, i8 zeroext %1) {
%3 = alloca i8*
%4 = alloca i8
%5 = alloca i8
%6 = alloca i8
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i8 %1, i8* %4
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
store i32 %10, i32* %8
%11 = load i8*, i8** %3
%12 = load i32, i32* %8
%13 = call i32 (i32, ...) @write(i32 1, i8* %11, i32 %12)
%14 = load i8, i8* %4
%15 = zext i8 %14 to i32
%16 = load i32, i32* %8
%17 = load i8, i8* %4
%18 = zext i8 %17 to i32
%19 = urem i32 %16, %18
%20 = sub i32 %15, %19
%21 = trunc i32 %20 to i8
store i8 %21, i8* %6
store i32 0, i32* %7
br label %22
22: ; preds = %29, %2
%23 = load i32, i32* %7
%24 = load i8, i8* %6
%25 = zext i8 %24 to i32
%26 = icmp ult i32 %23, %25
br i1 %26, label %27, label %32
27: ; preds = %22
%28 = call i32 (i32, ...) @write(i32 1, i8* %6, i32 1)
br label %29
29: ; preds = %27
%30 = load i32, i32* %7
%31 = add i32 %30, 1
store i32 %31, i32* %7
br label %22
32: ; preds = %22
store i8 0, i8* %5
%33 = call i32 (i32, ...) @write(i32 1, i8* %5, i32 1)
ret void
}

LLVM IR (-O2):
define void @generate_pcks(i8* %0, i8 zeroext %1) {
%3 = alloca i8
%4 = alloca i8
%5 = tail call i32 @strlen(i8* %0)
%6 = tail call i32 (i32, ...) @write(i32 1, i8* %0, i32 %5)
%7 = zext i8 %1 to i32
%8 = urem i32 %5, %7
%9 = trunc i32 %8 to i8
%10 = sub i8 %1, %9
store i8 %10, i8* %4
%11 = icmp eq i8 %10, 0
br i1 %11, label %19, label %12
12: ; preds = %2, %12
%13 = phi i32 [ %15, %12 ], [ 0, %2 ]
%14 = call i32 (i32, ...) @write(i32 1, i8* %4, i32 1)
%15 = add nuw nsw i32 %13, 1
%16 = load i8, i8* %4
%17 = zext i8 %16 to i32
%18 = icmp ult i32 %15, %17
br i1 %18, label %12, label %19
19: ; preds = %12, %2
store i8 0, i8* %3
%20 = call i32 (i32, ...) @write(i32 1, i8* %3, i32 1)
ret void
}