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

/* Variables and functions */
int BUFSIZ;
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ SHA256_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Update(int /*<<< orphan*/ *, unsigned char *, size_t);
scalar_t__ malloc(int);
size_t strlen(unsigned char *);
unsigned char *GetHash(unsigned char *identity, char **error) {
  int i;
  size_t length;
  unsigned char buffer[BUFSIZ], *hash;
  SHA256_CTX ctx;
  SHA256_Init(&ctx);
  length = strlen(identity);
  if (length > BUFSIZ) {
    *error = "identity length greather than BUFSIZ";
    return NULL;
  }
  for (i = 0; i < length; i++)
    buffer[i] = identity[i];
  buffer[i] = '\0';
  SHA256_Update(&ctx, buffer, length);
  SHA256_Final(buffer, &ctx);
  hash =
      (unsigned char *)malloc(SHA256_DIGEST_LENGTH * sizeof(unsigned char) + 1);
  if (hash == NULL) {
    *error = "malloc error";
    return NULL;
  }
  for (i = 0; i < SHA256_DIGEST_LENGTH; i++)
    hash[i] = buffer[i];
  hash[SHA256_DIGEST_LENGTH] = '\0';
  *error = "success";
  return hash;
}


x86 assembly (clang, -O0):
<GetHash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    0x2e79(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x50(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
lea    -0x44(%rbp),%rdi
call   1040 <SHA256_Init@plt>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    0x2e33(%rip),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jbe    11db <GetHash+0x8b>
mov    -0x18(%rbp),%rax
lea    0xe3c(%rip),%rcx
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    12f0 <GetHash+0x1a0>
movl   $0x0,-0x1c(%rbp)
movslq -0x1c(%rbp),%rax
cmp    -0x28(%rbp),%rax
jae    1214 <GetHash+0xc4>
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq -0x1c(%rbp),%rdx
mov    (%rcx,%rdx,1),%dl
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e2 <GetHash+0x92>
mov    -0x50(%rbp),%rsi
movslq -0x1c(%rbp),%rax
movb   $0x0,(%rsi,%rax,1)
mov    -0x28(%rbp),%rdx
lea    -0x44(%rbp),%rdi
call   1070 <SHA256_Update@plt>
mov    -0x50(%rbp),%rdi
lea    -0x44(%rbp),%rsi
call   1060 <SHA256_Final@plt>
mov    0x2d97(%rip),%rax
movslq (%rax),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    1284 <GetHash+0x134>
mov    -0x18(%rbp),%rax
lea    0xdb8(%rip),%rcx
mov    %rcx,(%rax)
movq   $0x0,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
jmp    12f0 <GetHash+0x1a0>
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2d43(%rip),%rcx
cmp    (%rcx),%eax
jge    12c1 <GetHash+0x171>
mov    -0x50(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x40(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    128b <GetHash+0x13b>
mov    -0x40(%rbp),%rax
mov    0x2d0c(%rip),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
lea    0xd54(%rip),%rcx
mov    %rcx,(%rax)
mov    -0x40(%rbp),%rax
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x48(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<GetHash>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    0x2e65(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    -0x2c(%rbp),%rdi
call   1040 <SHA256_Init@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rax,%r12
movslq 0x0(%r13),%rax
cmp    %rax,%r12
jbe    11b9 <GetHash+0x59>
lea    0xe4c(%rip),%rcx
jmp    124a <GetHash+0xea>
test   %r12,%r12
je     11d1 <GetHash+0x71>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
mov    %r12d,%eax
jmp    11d3 <GetHash+0x73>
xor    %eax,%eax
movb   $0x0,(%rbx,%rax,1)
lea    -0x2c(%rbp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1080 <SHA256_Update@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1070 <SHA256_Final@plt>
mov    0x2ddd(%rip),%r15
mov    (%r15),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     1243 <GetHash+0xe3>
mov    (%r15),%ecx
test   %ecx,%ecx
jle    1233 <GetHash+0xd3>
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movzbl (%rbx,%rdx,1),%ecx
mov    %cl,(%rax,%rdx,1)
add    $0x1,%rdx
movslq (%r15),%rcx
cmp    %rcx,%rdx
jl     1220 <GetHash+0xc0>
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
lea    0xdf1(%rip),%rcx
jmp    124c <GetHash+0xec>
lea    0xddb(%rip),%rcx
xor    %eax,%eax
mov    %rcx,(%r14)
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@BUFSIZ = global i32 0
@.str = [37 x i8] c"identity length greather than BUFSIZ\00"
@SHA256_DIGEST_LENGTH = global i32 0
@.str.1 = [13 x i8] c"malloc error\00"
@.str.2 = [8 x i8] c"success\00"
define i8* @GetHash(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%13 = load i32, i32* @BUFSIZ
%14 = zext i32 %13 to i64
%15 = call i8* @llvm.stacksave()
store i8* %15, i8** %8
%16 = alloca i8, i64 %14
store i64 %14, i64* %9
%17 = call i32 @SHA256_Init(i32* %11)
%18 = load i8*, i8** %4
%19 = call i64 @strlen(i8* %18)
store i64 %19, i64* %7
%20 = load i64, i64* %7
%21 = load i32, i32* @BUFSIZ
%22 = sext i32 %21 to i64
%23 = icmp ugt i64 %20, %22
br i1 %23, label %24, label %26
24: ; preds = %2
%25 = load i8**, i8*** %5
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %25
store i8* null, i8** %3
store i32 1, i32* %12
br label %86
26: ; preds = %2
store i32 0, i32* %6
br label %27
27: ; preds = %41, %26
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = load i64, i64* %7
%31 = icmp ult i64 %29, %30
br i1 %31, label %32, label %44
32: ; preds = %27
%33 = load i8*, i8** %4
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = load i32, i32* %6
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %16, i64 %39
store i8 %37, i8* %40
br label %41
41: ; preds = %32
%42 = load i32, i32* %6
%43 = add nsw i32 %42, 1
store i32 %43, i32* %6
br label %27
44: ; preds = %27
%45 = load i32, i32* %6
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %16, i64 %46
store i8 0, i8* %47
%48 = load i64, i64* %7
%49 = call i32 @SHA256_Update(i32* %11, i8* %16, i64 %48)
%50 = call i32 @SHA256_Final(i8* %16, i32* %11)
%51 = load i32, i32* @SHA256_DIGEST_LENGTH
%52 = sext i32 %51 to i64
%53 = mul i64 %52, 1
%54 = add i64 %53, 1
%55 = trunc i64 %54 to i32
%56 = call i64 @malloc(i32 %55)
%57 = inttoptr i64 %56 to i8*
store i8* %57, i8** %10
%58 = load i8*, i8** %10
%59 = icmp eq i8* %58, null
br i1 %59, label %60, label %62
60: ; preds = %44
%61 = load i8**, i8*** %5
store i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8** %61
store i8* null, i8** %3
store i32 1, i32* %12
br label %86
62: ; preds = %44
store i32 0, i32* %6
br label %63
63: ; preds = %76, %62
%64 = load i32, i32* %6
%65 = load i32, i32* @SHA256_DIGEST_LENGTH
%66 = icmp slt i32 %64, %65
br i1 %66, label %67, label %79
67: ; preds = %63
%68 = load i32, i32* %6
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8, i8* %16, i64 %69
%71 = load i8, i8* %70
%72 = load i8*, i8** %10
%73 = load i32, i32* %6
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8, i8* %72, i64 %74
store i8 %71, i8* %75
br label %76
76: ; preds = %67
%77 = load i32, i32* %6
%78 = add nsw i32 %77, 1
store i32 %78, i32* %6
br label %63
79: ; preds = %63
%80 = load i8*, i8** %10
%81 = load i32, i32* @SHA256_DIGEST_LENGTH
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %80, i64 %82
store i8 0, i8* %83
%84 = load i8**, i8*** %5
store i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), i8** %84
%85 = load i8*, i8** %10
store i8* %85, i8** %3
store i32 1, i32* %12
br label %86
86: ; preds = %79, %60, %24
%87 = load i8*, i8** %8
%88 = load i8*, i8** %3
ret i8* %88
}

LLVM IR (-O2):
@BUFSIZ = global i32 0
@.str = [37 x i8] c"identity length greather than BUFSIZ\00"
@SHA256_DIGEST_LENGTH = global i32 0
@.str.1 = [13 x i8] c"malloc error\00"
@.str.2 = [8 x i8] c"success\00"
define i8* @GetHash(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = alloca i32
%4 = load i32, i32* @BUFSIZ
%5 = zext i32 %4 to i64
%6 = alloca i8, i64 %5
%7 = bitcast i32* %3 to i8*
%8 = call i32 @SHA256_Init(i32* %3)
%9 = call i64 @strlen(i8* dereferenceable(1) %0)
%10 = load i32, i32* @BUFSIZ
%11 = sext i32 %10 to i64
%12 = icmp ugt i64 %9, %11
br i1 %12, label %43, label %13
13: ; preds = %2
%14 = icmp eq i64 %9, 0
br i1 %14, label %17, label %15
15: ; preds = %13
%16 = and i64 %9, 4294967295
br label %17
17: ; preds = %15, %13
%18 = phi i64 [ 0, %13 ], [ %16, %15 ]
%19 = getelementptr inbounds i8, i8* %6, i64 %18
store i8 0, i8* %19
%20 = call i32 @SHA256_Update(i32* %3, i8* %6, i64 %9)
%21 = call i32 @SHA256_Final(i8* %6, i32* %3)
%22 = load i32, i32* @SHA256_DIGEST_LENGTH
%23 = add i32 %22, 1
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = icmp eq i64 %24, 0
br i1 %26, label %43, label %27
27: ; preds = %17
%28 = load i32, i32* @SHA256_DIGEST_LENGTH
%29 = icmp sgt i32 %28, 0
br i1 %29, label %30, label %39
30: ; preds = %27, %30
%31 = phi i64 [ %35, %30 ], [ 0, %27 ]
%32 = getelementptr inbounds i8, i8* %6, i64 %31
%33 = load i8, i8* %32
%34 = getelementptr inbounds i8, i8* %25, i64 %31
store i8 %33, i8* %34
%35 = add nuw nsw i64 %31, 1
%36 = load i32, i32* @SHA256_DIGEST_LENGTH
%37 = sext i32 %36 to i64
%38 = icmp slt i64 %35, %37
br i1 %38, label %30, label %39
39: ; preds = %30, %27
%40 = phi i32 [ %28, %27 ], [ %36, %30 ]
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %25, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %17, %2, %39
%44 = phi i8* [ getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0), %39 ], [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %2 ], [ getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), %17 ]
%45 = phi i8* [ %25, %39 ], [ null, %2 ], [ null, %17 ]
store i8* %44, i8** %1
ret i8* %45
}