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

/* Variables and functions */
size_t ComputeRspParamHashOffset(size_t);
int /*<<< orphan*/ SHA1_Final(int /*<<< orphan*/ const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                               size_t);
int /*<<< orphan*/ TtlMarshal_uint32_t(int /*<<< orphan*/ const **, size_t *);
void ComputeRspParamsHash(const uint8_t *cmd, uint32_t cmd_length,
                          uint32_t ordinal, uint8_t *params_hash) {
  uint8_t ordinal_buf[4];
  uint8_t *ptr = ordinal_buf;
  TtlMarshal_uint32_t(&ptr, &ordinal);
  uint32_t params_offset = 10 + ComputeRspParamHashOffset(ordinal);
  SHA_CTX sha_ctx;
  SHA1_Init(&sha_ctx);
  SHA1_Update(&sha_ctx, &cmd[6], 4);
  SHA1_Update(&sha_ctx, ordinal_buf, 4);
  if (cmd_length > params_offset) {
    SHA1_Update(&sha_ctx, &cmd[params_offset], cmd_length - params_offset);
  }
  SHA1_Final(params_hash, &sha_ctx);
}


x86 assembly (clang, -O0):
<ComputeRspParamsHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    -0x38(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1060 <TtlMarshal_uint32_t@plt>
mov    -0x18(%rbp),%rdi
call   1040 <ComputeRspParamHashOffset@plt>
add    $0xa,%rax
mov    %rax,-0x40(%rbp)
lea    -0x44(%rbp),%rdi
call   1050 <SHA1_Init@plt>
mov    -0x8(%rbp),%rsi
add    $0x18,%rsi
lea    -0x44(%rbp),%rdi
mov    $0x4,%edx
call   1030 <SHA1_Update@plt>
lea    -0x30(%rbp),%rsi
lea    -0x44(%rbp),%rdi
mov    $0x4,%edx
call   1030 <SHA1_Update@plt>
mov    -0x10(%rbp),%rax
cmp    -0x40(%rbp),%rax
jbe    11ed <ComputeRspParamsHash+0x9d>
mov    -0x8(%rbp),%rsi
mov    -0x40(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
sub    -0x40(%rbp),%rdx
lea    -0x44(%rbp),%rdi
call   1030 <SHA1_Update@plt>
mov    -0x20(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1070 <SHA1_Final@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputeRspParamsHash>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %rcx,%r14
mov    %rsi,%r13
mov    %rdi,%r15
mov    %rdx,0x10(%rsp)
lea    0x20(%rsp),%r12
mov    %r12,0x18(%rsp)
lea    0x18(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1060 <TtlMarshal_uint32_t@plt>
mov    0x10(%rsp),%rdi
call   1040 <ComputeRspParamHashOffset@plt>
mov    %rax,%rbx
add    $0xa,%rbx
lea    0xc(%rsp),%rbp
mov    %rbp,%rdi
call   1050 <SHA1_Init@plt>
lea    0x18(%r15),%rsi
mov    $0x4,%edx
mov    %rbp,%rdi
call   1030 <SHA1_Update@plt>
mov    $0x4,%edx
mov    %rbp,%rdi
mov    %r12,%rsi
call   1030 <SHA1_Update@plt>
cmp    %r13,%rbx
jae    11dd <ComputeRspParamsHash+0x8d>
lea    (%r15,%rbx,4),%rsi
sub    %rbx,%r13
lea    0xc(%rsp),%rdi
mov    %r13,%rdx
call   1030 <SHA1_Update@plt>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1070 <SHA1_Final@plt>
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @ComputeRspParamsHash(i32* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32*
%9 = alloca [4 x i32]
%10 = alloca i32*
%11 = alloca i64
%12 = alloca i32
store i32* %0, i32** %5
store i64 %1, i64* %6
store i64 %2, i64* %7
store i32* %3, i32** %8
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
store i32* %13, i32** %10
%14 = call i32 @TtlMarshal_uint32_t(i32** %10, i64* %7)
%15 = load i64, i64* %7
%16 = call i64 @ComputeRspParamHashOffset(i64 %15)
%17 = add i64 10, %16
store i64 %17, i64* %11
%18 = call i32 @SHA1_Init(i32* %12)
%19 = load i32*, i32** %5
%20 = getelementptr inbounds i32, i32* %19, i64 6
%21 = call i32 @SHA1_Update(i32* %12, i32* %20, i64 4)
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %9, i64 0, i64 0
%23 = call i32 @SHA1_Update(i32* %12, i32* %22, i64 4)
%24 = load i64, i64* %6
%25 = load i64, i64* %11
%26 = icmp ugt i64 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %4
%28 = load i32*, i32** %5
%29 = load i64, i64* %11
%30 = getelementptr inbounds i32, i32* %28, i64 %29
%31 = load i64, i64* %6
%32 = load i64, i64* %11
%33 = sub i64 %31, %32
%34 = call i32 @SHA1_Update(i32* %12, i32* %30, i64 %33)
br label %35
35: ; preds = %27, %4
%36 = load i32*, i32** %8
%37 = call i32 @SHA1_Final(i32* %36, i32* %12)
ret void
}

LLVM IR (-O2):
define void @ComputeRspParamsHash(i32* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i64
%6 = alloca [4 x i32]
%7 = alloca i32*
%8 = alloca i32
store i64 %2, i64* %5
%9 = bitcast [4 x i32]* %6 to i8*
%10 = bitcast i32** %7 to i8*
%11 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 0
store i32* %11, i32** %7
%12 = call i32 @TtlMarshal_uint32_t(i32** %7, i64* %5)
%13 = load i64, i64* %5
%14 = call i64 @ComputeRspParamHashOffset(i64 %13)
%15 = add i64 %14, 10
%16 = bitcast i32* %8 to i8*
%17 = call i32 @SHA1_Init(i32* %8)
%18 = getelementptr inbounds i32, i32* %0, i64 6
%19 = call i32 @SHA1_Update(i32* %8, i32* %18, i64 4)
%20 = call i32 @SHA1_Update(i32* %8, i32* %11, i64 4)
%21 = icmp ult i64 %15, %1
br i1 %21, label %22, label %26
22: ; preds = %4
%23 = getelementptr inbounds i32, i32* %0, i64 %15
%24 = sub i64 %1, %15
%25 = call i32 @SHA1_Update(i32* %8, i32* %23, i64 %24)
br label %26
26: ; preds = %22, %4
%27 = call i32 @SHA1_Final(i32* %3, i32* %8)
ret void
}