#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 */
typedef int /*<<< orphan*/ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ chunk_set(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ memcpy(int /*<<< orphan*/ *, unsigned char const *,
                          unsigned char);
void pad(uint32_t *padding, const unsigned char *offcut, unsigned int len) {
  unsigned char i, shift, mask1 = 0xff, mask2 = 0x80;
  unsigned char *ptr = (unsigned char *)padding;
  chunk_set(padding, 0);
  i = len / 8;
  memcpy(padding, offcut, i + 1 - ((len & 7) == 0));
  shift = 8 - (len % 8);
  mask1 >>= shift;
  mask2 >>= (shift - 1);
  ptr[i] = (ptr[i] & mask1) | mask2;
}


x86 assembly (clang, -O0):
<pad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movb   $0xff,-0x17(%rbp)
movb   $0x80,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
xor    %esi,%esi
call   1040 <chunk_set@plt>
mov    -0x14(%rbp),%eax
shr    $0x3,%eax
mov    %al,-0x15(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
movzbl -0x15(%rbp),%eax
add    $0x1,%eax
mov    -0x14(%rbp),%ecx
and    $0x7,%ecx
cmp    $0x0,%ecx
sete   %cl
and    $0x1,%cl
movzbl %cl,%ecx
sub    %ecx,%eax
movzbl %al,%edx
call   1030 <memcpy@plt>
mov    -0x14(%rbp),%ecx
and    $0x7,%ecx
mov    $0x8,%eax
sub    %ecx,%eax
mov    %al,-0x16(%rbp)
movzbl -0x16(%rbp),%ecx
movzbl -0x17(%rbp),%eax
sar    %cl,%eax
mov    %al,-0x17(%rbp)
movzbl -0x16(%rbp),%ecx
sub    $0x1,%ecx
movzbl -0x18(%rbp),%eax
sar    %cl,%eax
mov    %al,-0x18(%rbp)
mov    -0x20(%rbp),%rax
movzbl -0x15(%rbp),%ecx
movzbl (%rax,%rcx,1),%eax
movzbl -0x17(%rbp),%ecx
and    %ecx,%eax
movzbl -0x18(%rbp),%ecx
or     %ecx,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movzbl -0x15(%rbp),%ecx
mov    %dl,(%rax,%rcx,1)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pad>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edx,%ebp
mov    %rsi,%r14
mov    %rdi,%r15
xor    %esi,%esi
call   1040 <chunk_set@plt>
mov    %ebp,%ebx
shr    $0x3,%ebx
xor    %eax,%eax
and    $0x7,%ebp
sete   %al
mov    %ebx,%ecx
sub    %eax,%ecx
add    $0x1,%ecx
movzbl %cl,%edx
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <memcpy@plt>
mov    $0x8,%cl
sub    %bpl,%cl
mov    $0xff,%eax
shr    %cl,%eax
xor    $0x7,%bpl
mov    $0x80,%edx
mov    %ebp,%ecx
shr    %cl,%edx
movzbl %bl,%ecx
movzbl (%r15,%rcx,1),%esi
and    %eax,%esi
or     %edx,%esi
mov    %sil,(%r15,%rcx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @pad(i32* %0, i8* %1, i32 %2) {
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8
%8 = alloca i8
%9 = alloca i8
%10 = alloca i8
%11 = alloca i8*
store i32* %0, i32** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i8 -1, i8* %9
store i8 -128, i8* %10
%12 = load i32*, i32** %4
%13 = bitcast i32* %12 to i8*
store i8* %13, i8** %11
%14 = load i32*, i32** %4
%15 = call i32 @chunk_set(i32* %14, i32 0)
%16 = load i32, i32* %6
%17 = udiv i32 %16, 8
%18 = trunc i32 %17 to i8
store i8 %18, i8* %7
%19 = load i32*, i32** %4
%20 = load i8*, i8** %5
%21 = load i8, i8* %7
%22 = zext i8 %21 to i32
%23 = add nsw i32 %22, 1
%24 = load i32, i32* %6
%25 = and i32 %24, 7
%26 = icmp eq i32 %25, 0
%27 = zext i1 %26 to i32
%28 = sub nsw i32 %23, %27
%29 = trunc i32 %28 to i8
%30 = call i32 @memcpy(i32* %19, i8* %20, i8 zeroext %29)
%31 = load i32, i32* %6
%32 = urem i32 %31, 8
%33 = sub i32 8, %32
%34 = trunc i32 %33 to i8
store i8 %34, i8* %8
%35 = load i8, i8* %8
%36 = zext i8 %35 to i32
%37 = load i8, i8* %9
%38 = zext i8 %37 to i32
%39 = ashr i32 %38, %36
%40 = trunc i32 %39 to i8
store i8 %40, i8* %9
%41 = load i8, i8* %8
%42 = zext i8 %41 to i32
%43 = sub nsw i32 %42, 1
%44 = load i8, i8* %10
%45 = zext i8 %44 to i32
%46 = ashr i32 %45, %43
%47 = trunc i32 %46 to i8
store i8 %47, i8* %10
%48 = load i8*, i8** %11
%49 = load i8, i8* %7
%50 = zext i8 %49 to i64
%51 = getelementptr inbounds i8, i8* %48, i64 %50
%52 = load i8, i8* %51
%53 = zext i8 %52 to i32
%54 = load i8, i8* %9
%55 = zext i8 %54 to i32
%56 = and i32 %53, %55
%57 = load i8, i8* %10
%58 = zext i8 %57 to i32
%59 = or i32 %56, %58
%60 = trunc i32 %59 to i8
%61 = load i8*, i8** %11
%62 = load i8, i8* %7
%63 = zext i8 %62 to i64
%64 = getelementptr inbounds i8, i8* %61, i64 %63
store i8 %60, i8* %64
ret void
}

LLVM IR (-O2):
define void @pad(i32* %0, i8* %1, i32 %2) {
%4 = bitcast i32* %0 to i8*
%5 = tail call i32 @chunk_set(i32* %0, i32 0)
%6 = lshr i32 %2, 3
%7 = add nuw nsw i32 %6, 1
%8 = and i32 %2, 7
%9 = icmp eq i32 %8, 0
%10 = sext i1 %9 to i32
%11 = add nsw i32 %7, %10
%12 = trunc i32 %11 to i8
%13 = tail call i32 @memcpy(i32* %0, i8* %1, i8 zeroext %12)
%14 = sub nuw nsw i32 8, %8
%15 = lshr i32 255, %14
%16 = xor i32 %8, 7
%17 = lshr i32 128, %16
%18 = and i32 %6, 255
%19 = zext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %4, i64 %19
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = and i32 %15, %22
%24 = or i32 %23, %17
%25 = trunc i32 %24 to i8
store i8 %25, i8* %20
ret void
}