#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 uint8_t;
struct key_settings {
  int dummy;
};
typedef int /*<<< orphan*/ SHA256_CTX;

/* Variables and functions */
int SHA256_DIGEST_LENGTH;
int /*<<< orphan*/ SHA256_Final(int *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA256_Update(int /*<<< orphan*/ *, int *, int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
void generate_SHA256(struct key_settings *settings) {
  SHA256_CTX ctx;
  uint8_t results[SHA256_DIGEST_LENGTH];
  char *buf;
  int n;
  buf = "H";
  n = strlen(buf);
  SHA256_Init(&ctx);
  SHA256_Update(&ctx, (uint8_t *)buf, n);
  SHA256_Final(results, &ctx);
  for (n = 0; n < SHA256_DIGEST_LENGTH; n++)
    printf("%02x", results[n]);
  printf("\n");
}


x86 assembly (clang, -O0):
<generate_SHA256>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2e7d(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
lea    0xf(,%rax,4),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
lea    0xe70(%rip),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <SHA256_Init@plt>
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
lea    -0xc(%rbp),%rdi
call   1070 <SHA256_Update@plt>
mov    -0x38(%rbp),%rdi
lea    -0xc(%rbp),%rsi
call   1060 <SHA256_Final@plt>
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    0x2e09(%rip),%rcx
cmp    (%rcx),%eax
jge    1206 <generate_SHA256+0xb6>
mov    -0x38(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,4),%esi
lea    0xe11(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    11cd <generate_SHA256+0x7d>
lea    0xdfa(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_SHA256>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsp,-0x30(%rbp)
mov    0x2e64(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r12
lea    0xf(,%rax,4),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    0xe64(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %eax,%r15d
lea    -0x34(%rbp),%rbx
mov    %rbx,%rdi
call   1060 <SHA256_Init@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15d,%edx
call   1080 <SHA256_Update@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <SHA256_Final@plt>
cmpl   $0x0,0x0(%r13)
jle    11fb <generate_SHA256+0x9b>
lea    0xe28(%rip),%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    (%r12,%rbx,4),%esi
mov    %r14,%rdi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%rbx
movslq 0x0(%r13),%rax
cmp    %rax,%rbx
jl     11e0 <generate_SHA256+0x80>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    -0x30(%rbp),%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.key_settings = type { i32 }
@SHA256_DIGEST_LENGTH = global i32 0
@.str = [2 x i8] c"H\00"
@.str.1 = [5 x i8] c"%02x\00"
@.str.2 = [2 x i8] c"\0A\00"
define void @generate_SHA256(%struct.key_settings* %0) {
%2 = alloca %struct.key_settings*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
store %struct.key_settings* %0, %struct.key_settings** %2
%8 = load i32, i32* @SHA256_DIGEST_LENGTH
%9 = zext i32 %8 to i64
%10 = call i8* @llvm.stacksave()
store i8* %10, i8** %4
%11 = alloca i32, i64 %9
store i64 %9, i64* %5
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %6
%12 = load i8*, i8** %6
%13 = call i32 @strlen(i8* %12)
store i32 %13, i32* %7
%14 = call i32 @SHA256_Init(i32* %3)
%15 = load i8*, i8** %6
%16 = bitcast i8* %15 to i32*
%17 = load i32, i32* %7
%18 = call i32 @SHA256_Update(i32* %3, i32* %16, i32 %17)
%19 = call i32 @SHA256_Final(i32* %11, i32* %3)
store i32 0, i32* %7
br label %20
20: ; preds = %30, %1
%21 = load i32, i32* %7
%22 = load i32, i32* @SHA256_DIGEST_LENGTH
%23 = icmp slt i32 %21, %22
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = load i32, i32* %7
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i32, i32* %11, i64 %26
%28 = load i32, i32* %27
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %28)
br label %30
30: ; preds = %24
%31 = load i32, i32* %7
%32 = add nsw i32 %31, 1
store i32 %32, i32* %7
br label %20
33: ; preds = %20
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%35 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
%struct.key_settings = type { i32 }
@SHA256_DIGEST_LENGTH = global i32 0
@.str = [2 x i8] c"H\00"
@.str.1 = [5 x i8] c"%02x\00"
define void @generate_SHA256(%struct.key_settings* nocapture readnone %0) {
%2 = alloca i32
%3 = bitcast i32* %2 to i8*
%4 = load i32, i32* @SHA256_DIGEST_LENGTH
%5 = zext i32 %4 to i64
%6 = tail call i8* @llvm.stacksave()
%7 = alloca i32, i64 %5
%8 = tail call i32 @strlen(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @SHA256_Init(i32* %2)
%10 = call i32 @SHA256_Update(i32* %2, i32* bitcast ([2 x i8]* @.str to i32*), i32 %8)
%11 = call i32 @SHA256_Final(i32* %7, i32* %2)
%12 = load i32, i32* @SHA256_DIGEST_LENGTH
%13 = icmp sgt i32 %12, 0
br i1 %13, label %14, label %23
14: ; preds = %1, %14
%15 = phi i64 [ %19, %14 ], [ 0, %1 ]
%16 = getelementptr inbounds i32, i32* %7, i64 %15
%17 = load i32, i32* %16
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %17)
%19 = add nuw nsw i64 %15, 1
%20 = load i32, i32* @SHA256_DIGEST_LENGTH
%21 = sext i32 %20 to i64
%22 = icmp slt i64 %19, %21
br i1 %22, label %14, label %23
23: ; preds = %14, %1
%24 = call i32 @putchar(i32 10)
ret void
}