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

/* Variables and functions */
size_t ComputeReqParamHashOffset(size_t);
int /*<<< orphan*/ SHA1_Final(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, int /*<<< orphan*/ const *,
                               size_t);
void ComputeReqParamsHash(const uint8_t *cmd, uint32_t cmd_length,
                          uint32_t ordinal, uint8_t *params_hash) {
  uint32_t params_offset = 10 + ComputeReqParamHashOffset(ordinal);
  SHA_CTX sha_ctx;
  SHA1_Init(&sha_ctx);
  SHA1_Update(&sha_ctx, &cmd[6], 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):
<ComputeReqParamsHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <ComputeReqParamHashOffset@plt>
add    $0xa,%rax
mov    %rax,-0x28(%rbp)
lea    -0x2c(%rbp),%rdi
call   1050 <SHA1_Init@plt>
mov    -0x8(%rbp),%rsi
add    $0x18,%rsi
lea    -0x2c(%rbp),%rdi
mov    $0x4,%edx
call   1030 <SHA1_Update@plt>
mov    -0x10(%rbp),%rax
cmp    -0x28(%rbp),%rax
jbe    11b6 <ComputeReqParamsHash+0x76>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rsi
mov    -0x10(%rbp),%rdx
sub    -0x28(%rbp),%rdx
lea    -0x2c(%rbp),%rdi
call   1030 <SHA1_Update@plt>
mov    -0x20(%rbp),%rdi
lea    -0x2c(%rbp),%rsi
call   1060 <SHA1_Final@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ComputeReqParamsHash>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rsi,%r12
mov    %rdi,%r15
mov    %rdx,%rdi
call   1040 <ComputeReqParamHashOffset@plt>
mov    %rax,%rbx
add    $0xa,%rbx
lea    0xc(%rsp),%r13
mov    %r13,%rdi
call   1050 <SHA1_Init@plt>
lea    0x18(%r15),%rsi
mov    $0x4,%edx
mov    %r13,%rdi
call   1030 <SHA1_Update@plt>
cmp    %r12,%rbx
jae    119c <ComputeReqParamsHash+0x5c>
lea    (%r15,%rbx,4),%rsi
sub    %rbx,%r12
lea    0xc(%rsp),%rdi
mov    %r12,%rdx
call   1030 <SHA1_Update@plt>
lea    0xc(%rsp),%rsi
mov    %r14,%rdi
call   1060 <SHA1_Final@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @ComputeReqParamsHash(i32* %0, i64 %1, i64 %2, i32* %3) {
%5 = alloca i32
%6 = tail call i64 @ComputeReqParamHashOffset(i64 %2)
%7 = add i64 %6, 10
%8 = bitcast i32* %5 to i8*
%9 = call i32 @SHA1_Init(i32* %5)
%10 = getelementptr inbounds i32, i32* %0, i64 6
%11 = call i32 @SHA1_Update(i32* %5, i32* %10, i64 4)
%12 = icmp ult i64 %7, %1
br i1 %12, label %13, label %17
13: ; preds = %4
%14 = getelementptr inbounds i32, i32* %0, i64 %7
%15 = sub i64 %1, %7
%16 = call i32 @SHA1_Update(i32* %5, i32* %14, i64 %15)
br label %17
17: ; preds = %13, %4
%18 = call i32 @SHA1_Final(i32* %3, i32* %5)
ret void
}