#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 */
struct s_rsa {
  int dummy;
};

/* Variables and functions */
int cryptoCalculateSHA256(unsigned char *, int const, unsigned char *, int);
int rsaGetDER(unsigned char *, int, struct s_rsa const *);
int rsaGetFingerprint(unsigned char *buf, const int buf_size,
                      const struct s_rsa *rsa) {
  unsigned char derbuf[416];
  int dersize = rsaGetDER(derbuf, 416, rsa);
  if (dersize > 0) {
    return cryptoCalculateSHA256(buf, buf_size, derbuf, dersize);
  } else {
    return 0;
  }
}


x86 assembly (clang, -O0):
<rsaGetFingerprint>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
lea    -0x1c0(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x1a0,%esi
call   1040 <rsaGetDER@plt>
mov    %eax,-0x1c4(%rbp)
cmpl   $0x0,-0x1c4(%rbp)
jle    117f <rsaGetFingerprint+0x5f>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x1c0(%rbp),%rdx
mov    -0x1c4(%rbp),%ecx
call   1030 <cryptoCalculateSHA256@plt>
mov    %eax,-0x4(%rbp)
jmp    1186 <rsaGetFingerprint+0x66>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rsaGetFingerprint>:
push   %rbp
push   %rbx
sub    $0x1a8,%rsp
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rdi
mov    $0x1a0,%esi
call   1040 <rsaGetDER@plt>
test   %eax,%eax
jle    1150 <rsaGetFingerprint+0x30>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %eax,%ecx
call   1030 <cryptoCalculateSHA256@plt>
jmp    1152 <rsaGetFingerprint+0x32>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.s_rsa = type { i32 }
define i32 @rsaGetFingerprint(i8* %0, i32 %1, %struct.s_rsa* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca %struct.s_rsa*
%8 = alloca [416 x i8]
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store %struct.s_rsa* %2, %struct.s_rsa** %7
%10 = getelementptr inbounds [416 x i8], [416 x i8]* %8, i64 0, i64 0
%11 = load %struct.s_rsa*, %struct.s_rsa** %7
%12 = call i32 @rsaGetDER(i8* %10, i32 416, %struct.s_rsa* %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %21
15: ; preds = %3
%16 = load i8*, i8** %5
%17 = load i32, i32* %6
%18 = getelementptr inbounds [416 x i8], [416 x i8]* %8, i64 0, i64 0
%19 = load i32, i32* %9
%20 = call i32 @cryptoCalculateSHA256(i8* %16, i32 %17, i8* %18, i32 %19)
store i32 %20, i32* %4
br label %22
21: ; preds = %3
store i32 0, i32* %4
br label %22
22: ; preds = %21, %15
%23 = load i32, i32* %4
ret i32 %23
}

LLVM IR (-O2):
%struct.s_rsa = type { i32 }
define i32 @rsaGetFingerprint(i8* %0, i32 %1, %struct.s_rsa* %2) {
%4 = alloca [416 x i8]
%5 = getelementptr inbounds [416 x i8], [416 x i8]* %4, i64 0, i64 0
%6 = call i32 @rsaGetDER(i8* %5, i32 416, %struct.s_rsa* %2)
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %3
%9 = call i32 @cryptoCalculateSHA256(i8* %0, i32 %1, i8* %5, i32 %6)
br label %10
10: ; preds = %3, %8
%11 = phi i32 [ %9, %8 ], [ 0, %3 ]
ret i32 %11
}