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

/* Variables and functions */
scalar_t__ cust_hash(unsigned char *, unsigned int, unsigned char *, int);
int /*<<< orphan*/ memset(unsigned char *, int, unsigned int);
int cust_sign(unsigned char *data_buf, unsigned int data_len,
              unsigned char *sig_buf, unsigned int sig_len) {
  memset(sig_buf, 0x00, sig_len);
  if ((128) == sig_len) {
    unsigned char sha1sum[(20)] = {0};
    if (cust_hash(data_buf, data_len, sha1sum, (20)) != 0) {
      return 0;
    }
    return 0;
  } else if ((256) == sig_len) {
    unsigned char sha256sum[(32)] = {0};
    if (cust_hash(data_buf, data_len, sha256sum, (32)) != 0) {
      return 0;
    }
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<cust_sign>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    $0x80,%eax
cmp    -0x24(%rbp),%eax
jne    1199 <cust_sign+0x79>
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x40(%rbp),%rdx
mov    $0x14,%ecx
call   1040 <cust_hash@plt>
cmp    $0x0,%rax
je     118d <cust_sign+0x6d>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <cust_sign+0xd5>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <cust_sign+0xd5>
mov    $0x100,%eax
cmp    -0x24(%rbp),%eax
jne    11ee <cust_sign+0xce>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x20,%edx
call   1030 <memset@plt>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x60(%rbp),%rdx
mov    $0x20,%ecx
call   1040 <cust_hash@plt>
cmp    $0x0,%rax
je     11e2 <cust_sign+0xc2>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <cust_sign+0xd5>
movl   $0x0,-0x4(%rbp)
jmp    11f5 <cust_sign+0xd5>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cust_sign>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
xor    %ebp,%ebp
mov    %rdx,%rdi
xor    %esi,%esi
mov    %ecx,%edx
call   1030 <memset@plt>
cmp    $0x100,%ebx
je     117b <cust_sign+0x5b>
mov    $0xffffffff,%ebp
cmp    $0x80,%ebx
jne    119a <cust_sign+0x7a>
xorps  %xmm0,%xmm0
movaps %xmm0,(%rsp)
movl   $0x0,0x10(%rsp)
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x14,%ecx
call   1040 <cust_hash@plt>
xor    %ebp,%ebp
jmp    119a <cust_sign+0x7a>
xorps  %xmm0,%xmm0
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %rsp,%rdx
mov    %r15,%rdi
mov    %r14d,%esi
mov    $0x20,%ecx
call   1040 <cust_hash@plt>
mov    %ebp,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @cust_sign(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32
%10 = alloca [20 x i8]
%11 = alloca [32 x i8]
store i8* %0, i8** %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32 %3, i32* %9
%12 = load i8*, i8** %8
%13 = load i32, i32* %9
%14 = call i32 @memset(i8* %12, i32 0, i32 %13)
%15 = load i32, i32* %9
%16 = icmp eq i32 128, %15
br i1 %16, label %17, label %26
17: ; preds = %4
%18 = bitcast [20 x i8]* %10 to i8*
%19 = load i8*, i8** %6
%20 = load i32, i32* %7
%21 = getelementptr inbounds [20 x i8], [20 x i8]* %10, i64 0, i64 0
%22 = call i64 @cust_hash(i8* %19, i32 %20, i8* %21, i32 20)
%23 = icmp ne i64 %22, 0
br i1 %23, label %24, label %25
24: ; preds = %17
store i32 0, i32* %5
br label %39
25: ; preds = %17
store i32 0, i32* %5
br label %39
26: ; preds = %4
%27 = load i32, i32* %9
%28 = icmp eq i32 256, %27
br i1 %28, label %29, label %38
29: ; preds = %26
%30 = bitcast [32 x i8]* %11 to i8*
%31 = load i8*, i8** %6
%32 = load i32, i32* %7
%33 = getelementptr inbounds [32 x i8], [32 x i8]* %11, i64 0, i64 0
%34 = call i64 @cust_hash(i8* %31, i32 %32, i8* %33, i32 32)
%35 = icmp ne i64 %34, 0
br i1 %35, label %36, label %37
36: ; preds = %29
store i32 0, i32* %5
br label %39
37: ; preds = %29
store i32 0, i32* %5
br label %39
38: ; preds = %26
store i32 -1, i32* %5
br label %39
39: ; preds = %38, %37, %36, %25, %24
%40 = load i32, i32* %5
ret i32 %40
}

LLVM IR (-O2):
define i32 @cust_sign(i8* %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [20 x i8]
%6 = alloca [32 x i8]
%7 = tail call i32 @memset(i8* %2, i32 0, i32 %3)
switch i32 %3, label %14 [
i32 128, label %8
i32 256, label %11
]
8: ; preds = %4
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%10 = call i64 @cust_hash(i8* %0, i32 %1, i8* %9, i32 20)
br label %14
11: ; preds = %4
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%13 = call i64 @cust_hash(i8* %0, i32 %1, i8* %12, i32 32)
br label %14
14: ; preds = %4, %11, %8
%15 = phi i32 [ 0, %8 ], [ 0, %11 ], [ -1, %4 ]
ret i32 %15
}