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

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, size_t);
int /*<<< orphan*/ write32_be(int /*<<< orphan*/, int *);
void md_pad(uint8_t *block, size_t blocksz, size_t used, size_t msg) {
  memset(block + used, 0, blocksz - used - 4);
  block[used] = 0x80;
  block += blocksz - 4;
  write32_be((uint32_t)(msg * 8), block);
}


x86 assembly (clang, -O0):
<md_pad>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x10(%rbp),%rdx
sub    -0x18(%rbp),%rdx
sub    $0x4,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movl   $0x80,(%rax,%rcx,4)
mov    -0x10(%rbp),%rax
sub    $0x4,%rax
shl    $0x2,%rax
add    -0x8(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x20(%rbp),%rax
shl    $0x3,%rax
mov    %eax,%edi
mov    -0x8(%rbp),%rsi
call   1030 <write32_be@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<md_pad>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
lea    (%rdi,%rdx,4),%rdi
lea    -0x4(%rsi),%rdx
sub    %r12,%rdx
xor    %esi,%esi
call   1040 <memset@plt>
movl   $0x80,(%rbx,%r12,4)
lea    (%rbx,%r15,4),%rsi
add    $0xfffffffffffffff0,%rsi
shl    $0x3,%r14d
mov    %r14d,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1030 <write32_be@plt>

LLVM IR (-O0):
define void @md_pad(i32* %0, i64 %1, i64 %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i64 %3, i64* %8
%9 = load i32*, i32** %5
%10 = load i64, i64* %7
%11 = getelementptr inbounds i32, i32* %9, i64 %10
%12 = load i64, i64* %6
%13 = load i64, i64* %7
%14 = sub i64 %12, %13
%15 = sub i64 %14, 4
%16 = call i32 @memset(i32* %11, i32 0, i64 %15)
%17 = load i32*, i32** %5
%18 = load i64, i64* %7
%19 = getelementptr inbounds i32, i32* %17, i64 %18
store i32 128, i32* %19
%20 = load i64, i64* %6
%21 = sub i64 %20, 4
%22 = load i32*, i32** %5
%23 = getelementptr inbounds i32, i32* %22, i64 %21
store i32* %23, i32** %5
%24 = load i64, i64* %8
%25 = mul i64 %24, 8
%26 = trunc i64 %25 to i32
%27 = load i32*, i32** %5
%28 = call i32 @write32_be(i32 %26, i32* %27)
ret void
}

LLVM IR (-O2):
define void @md_pad(i32* %0, i64 %1, i64 %2, i64 %3) {
%5 = getelementptr inbounds i32, i32* %0, i64 %2
%6 = add i64 %1, -4
%7 = sub i64 %6, %2
%8 = tail call i32 @memset(i32* %5, i32 0, i64 %7)
store i32 128, i32* %5
%9 = getelementptr inbounds i32, i32* %0, i64 %6
%10 = trunc i64 %3 to i32
%11 = shl i32 %10, 3
%12 = tail call i32 @write32_be(i32 %11, i32* %9)
ret void
}