#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*/ block;

/* Variables and functions */
int /*<<< orphan*/ memset(int *, int /*<<< orphan*/, int);
int /*<<< orphan*/ write_block(int *);
void sha256_padding(const uint8_t *input, unsigned int count) {
  int i, len_rem, block_nb;
  uint8_t block[(512 / 8)], block1[(512 / 8)];
  memset(block, 0, (sizeof(block) / sizeof((block)[0])));
  memset(block1, 0, (sizeof(block) / sizeof((block)[0])));
  len_rem = count % (512 / 8);
  block_nb = (((512 / 8) - 9) < (len_rem % (512 / 8)));
  if (block_nb) {
    for (i = 0; i < len_rem; i++)
      block[i] = input[i];
    block[i] = 0x80;
    block1[60] = ((count * 8) & 0xff000000) >> 24;
    block1[61] = ((count * 8) & 0x00ff0000) >> 16;
    block1[62] = ((count * 8) & 0x0000ff00) >> 8;
    block1[63] = ((count * 8) & 0x000000ff);
    write_block(block);
    write_block(block1);
  } else {
    for (i = 0; i < len_rem; i++)
      block[i] = input[i];
    block[i] = 0x80;
    block[60] = ((count * 8) & 0xff000000) >> 24;
    block[61] = ((count * 8) & 0x00ff0000) >> 16;
    block[62] = ((count * 8) & 0x0000ff00) >> 8;
    block[63] = ((count * 8) & 0x000000ff);
    write_block(block);
  }
}


x86 assembly (clang, -O0):
<sha256_padding>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    -0x220(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    -0xc(%rbp),%eax
and    $0x3f,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    $0x40,%ecx
cltd
idiv   %ecx
mov    $0x37,%eax
cmp    %edx,%eax
setl   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
je     1238 <sha256_padding+0x118>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    11bf <sha256_padding+0x9f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x120(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    118f <sha256_padding+0x6f>
movslq -0x10(%rbp),%rax
movl   $0x80,-0x120(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x130(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %eax,-0x12c(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %eax,-0x128(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff,%eax
mov    %eax,-0x124(%rbp)
lea    -0x120(%rbp),%rdi
call   1030 <write_block@plt>
lea    -0x220(%rbp),%rdi
call   1030 <write_block@plt>
jmp    12cb <sha256_padding+0x1ab>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    126f <sha256_padding+0x14f>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
mov    (%rax,%rcx,4),%ecx
movslq -0x10(%rbp),%rax
mov    %ecx,-0x120(%rbp,%rax,4)
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    123f <sha256_padding+0x11f>
movslq -0x10(%rbp),%rax
movl   $0x80,-0x120(%rbp,%rax,4)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff000000,%eax
shr    $0x18,%eax
mov    %eax,-0x30(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff0000,%eax
shr    $0x10,%eax
mov    %eax,-0x2c(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff00,%eax
shr    $0x8,%eax
mov    %eax,-0x28(%rbp)
mov    -0xc(%rbp),%eax
shl    $0x3,%eax
and    $0xff,%eax
mov    %eax,-0x24(%rbp)
lea    -0x120(%rbp),%rdi
call   1030 <write_block@plt>
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha256_padding>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x200,%rsp
mov    %esi,%r13d
mov    %rdi,%r12
mov    %rsp,%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
lea    0x100(%rsp),%r15
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1040 <memset@plt>
mov    %r13d,%ebx
and    $0x3f,%ebx
cmp    $0x37,%ebx
jbe    11e4 <sha256_padding+0xb4>
lea    -0x1(%rbx),%eax
lea    0x4(,%rax,4),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    %r12,%rsi
call   1050 <memcpy@plt>
mov    %ebx,%eax
movl   $0x80,(%rsp,%rax,4)
lea    0x0(,%r13,8),%eax
movzbl %al,%ecx
shr    $0x18,%eax
mov    %eax,0x1f0(%rsp)
mov    %r13d,%eax
shr    $0xd,%eax
movzbl %al,%eax
mov    %eax,0x1f4(%rsp)
shr    $0x5,%r13d
movzbl %r13b,%eax
mov    %eax,0x1f8(%rsp)
mov    %ecx,0x1fc(%rsp)
mov    %r14,%rdi
call   1030 <write_block@plt>
mov    %r15,%r14
jmp    1246 <sha256_padding+0x116>
test   %ebx,%ebx
je     1202 <sha256_padding+0xd2>
lea    0x0(,%r13,4),%eax
movzbl %al,%edx
mov    %rsp,%rdi
mov    %r12,%rsi
call   1050 <memcpy@plt>
mov    %ebx,%eax
jmp    1204 <sha256_padding+0xd4>
xor    %eax,%eax
movl   $0x80,(%rsp,%rax,4)
lea    0x0(,%r13,8),%eax
movzbl %al,%ecx
shr    $0x18,%eax
mov    %eax,0xf0(%rsp)
mov    %r13d,%eax
shr    $0xd,%eax
movzbl %al,%eax
mov    %eax,0xf4(%rsp)
shr    $0x5,%r13d
movzbl %r13b,%eax
mov    %eax,0xf8(%rsp)
mov    %ecx,0xfc(%rsp)
mov    %r14,%rdi
call   1030 <write_block@plt>
add    $0x200,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @sha256_padding(i32* %0, i32 %1) {
%3 = alloca i32*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca [64 x i32]
%9 = alloca [64 x i32]
store i32* %0, i32** %3
store i32 %1, i32* %4
%10 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 0
%11 = call i32 @memset(i32* %10, i32 0, i32 64)
%12 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 0
%13 = call i32 @memset(i32* %12, i32 0, i32 64)
%14 = load i32, i32* %4
%15 = urem i32 %14, 64
store i32 %15, i32* %6
%16 = load i32, i32* %6
%17 = srem i32 %16, 64
%18 = icmp slt i32 55, %17
%19 = zext i1 %18 to i32
store i32 %19, i32* %7
%20 = load i32, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %66
22: ; preds = %2
store i32 0, i32* %5
br label %23
23: ; preds = %36, %22
%24 = load i32, i32* %5
%25 = load i32, i32* %6
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %39
27: ; preds = %23
%28 = load i32*, i32** %3
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i32, i32* %28, i64 %30
%32 = load i32, i32* %31
%33 = load i32, i32* %5
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 %34
store i32 %32, i32* %35
br label %36
36: ; preds = %27
%37 = load i32, i32* %5
%38 = add nsw i32 %37, 1
store i32 %38, i32* %5
br label %23
39: ; preds = %23
%40 = load i32, i32* %5
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 %41
store i32 128, i32* %42
%43 = load i32, i32* %4
%44 = mul i32 %43, 8
%45 = and i32 %44, -16777216
%46 = lshr i32 %45, 24
%47 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 60
store i32 %46, i32* %47
%48 = load i32, i32* %4
%49 = mul i32 %48, 8
%50 = and i32 %49, 16711680
%51 = lshr i32 %50, 16
%52 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 61
store i32 %51, i32* %52
%53 = load i32, i32* %4
%54 = mul i32 %53, 8
%55 = and i32 %54, 65280
%56 = lshr i32 %55, 8
%57 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 62
store i32 %56, i32* %57
%58 = load i32, i32* %4
%59 = mul i32 %58, 8
%60 = and i32 %59, 255
%61 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 63
store i32 %60, i32* %61
%62 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 0
%63 = call i32 @write_block(i32* %62)
%64 = getelementptr inbounds [64 x i32], [64 x i32]* %9, i64 0, i64 0
%65 = call i32 @write_block(i32* %64)
br label %108
66: ; preds = %2
store i32 0, i32* %5
br label %67
67: ; preds = %80, %66
%68 = load i32, i32* %5
%69 = load i32, i32* %6
%70 = icmp slt i32 %68, %69
br i1 %70, label %71, label %83
71: ; preds = %67
%72 = load i32*, i32** %3
%73 = load i32, i32* %5
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i32, i32* %72, i64 %74
%76 = load i32, i32* %75
%77 = load i32, i32* %5
%78 = sext i32 %77 to i64
%79 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 %78
store i32 %76, i32* %79
br label %80
80: ; preds = %71
%81 = load i32, i32* %5
%82 = add nsw i32 %81, 1
store i32 %82, i32* %5
br label %67
83: ; preds = %67
%84 = load i32, i32* %5
%85 = sext i32 %84 to i64
%86 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 %85
store i32 128, i32* %86
%87 = load i32, i32* %4
%88 = mul i32 %87, 8
%89 = and i32 %88, -16777216
%90 = lshr i32 %89, 24
%91 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 60
store i32 %90, i32* %91
%92 = load i32, i32* %4
%93 = mul i32 %92, 8
%94 = and i32 %93, 16711680
%95 = lshr i32 %94, 16
%96 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 61
store i32 %95, i32* %96
%97 = load i32, i32* %4
%98 = mul i32 %97, 8
%99 = and i32 %98, 65280
%100 = lshr i32 %99, 8
%101 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 62
store i32 %100, i32* %101
%102 = load i32, i32* %4
%103 = mul i32 %102, 8
%104 = and i32 %103, 255
%105 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 63
store i32 %104, i32* %105
%106 = getelementptr inbounds [64 x i32], [64 x i32]* %8, i64 0, i64 0
%107 = call i32 @write_block(i32* %106)
br label %108
108: ; preds = %83, %39
ret void
}

LLVM IR (-O2):
define void @sha256_padding(i32* nocapture %0, i32 %1) {
%3 = bitcast i32* %0 to i8*
%4 = alloca [64 x i32]
%5 = bitcast [64 x i32]* %4 to i8*
%6 = alloca [64 x i32]
%7 = bitcast [64 x i32]* %6 to i8*
%8 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 0
%9 = call i32 @memset(i32* %8, i32 0, i32 64)
%10 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 0
%11 = call i32 @memset(i32* %10, i32 0, i32 64)
%12 = and i32 %1, 63
%13 = icmp ugt i32 %12, 55
br i1 %13, label %21, label %14
14: ; preds = %2
%15 = icmp eq i32 %12, 0
br i1 %15, label %40, label %16
16: ; preds = %14
%17 = shl i32 %1, 2
%18 = and i32 %17, 252
%19 = zext i32 %18 to i64
%20 = zext i32 %12 to i64
br label %40
21: ; preds = %2
%22 = add nsw i32 %12, -1
%23 = zext i32 %22 to i64
%24 = shl nuw nsw i64 %23, 2
%25 = add nuw nsw i64 %24, 4
%26 = zext i32 %12 to i64
%27 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %26
store i32 128, i32* %27
%28 = shl i32 %1, 3
%29 = lshr i32 %28, 24
%30 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 60
store i32 %29, i32* %30
%31 = lshr i32 %28, 16
%32 = and i32 %31, 255
%33 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 61
store i32 %32, i32* %33
%34 = lshr i32 %28, 8
%35 = and i32 %34, 255
%36 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 62
store i32 %35, i32* %36
%37 = and i32 %28, 248
%38 = getelementptr inbounds [64 x i32], [64 x i32]* %6, i64 0, i64 63
store i32 %37, i32* %38
%39 = call i32 @write_block(i32* %8)
br label %54
40: ; preds = %16, %14
%41 = phi i64 [ 0, %14 ], [ %20, %16 ]
%42 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 %41
store i32 128, i32* %42
%43 = shl i32 %1, 3
%44 = lshr i32 %43, 24
%45 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 60
store i32 %44, i32* %45
%46 = lshr i32 %43, 16
%47 = and i32 %46, 255
%48 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 61
store i32 %47, i32* %48
%49 = lshr i32 %43, 8
%50 = and i32 %49, 255
%51 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 62
store i32 %50, i32* %51
%52 = and i32 %43, 248
%53 = getelementptr inbounds [64 x i32], [64 x i32]* %4, i64 0, i64 63
store i32 %52, i32* %53
br label %54
54: ; preds = %40, %21
%55 = phi i32* [ %8, %40 ], [ %10, %21 ]
%56 = call i32 @write_block(i32* %55)
ret void
}