#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 */
int /*<<< orphan*/ SHA256(unsigned char const *, int /*<<< orphan*/,
                          unsigned char *);
int /*<<< orphan*/ get_nonce_test();
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strlen(char *);
int main() {
  unsigned char md[128] = {0};
  SHA256((const unsigned char *)"hello1", strlen("hello1"), md);
  int i = 0;
  char buf[65] = {0};
  char tmp[8] = {0};
  for (i = 0; i < 32; i++) {
    sprintf(tmp, "%02X", md[i]);
    strcat(buf, tmp);
    md[i] ^= 'x';
    sprintf(tmp, " %02X ", md[i]);
    strcat(buf, tmp);
  }
  printf("buf = %s\n", buf);
  for (i = 0; i < 5; i++)
    get_nonce_test();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xf0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x80,%edx
call   1060 <memset@plt>
lea    0xe64(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%esi
lea    -0x90(%rbp),%rdx
lea    0xe4f(%rip),%rdi
call   1030 <SHA256@plt>
movl   $0x0,-0x94(%rbp)
lea    -0xe0(%rbp),%rdi
xor    %esi,%esi
mov    $0x41,%edx
call   1060 <memset@plt>
lea    -0xe8(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1060 <memset@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x20,-0x94(%rbp)
jge    1294 <main+0x124>
lea    -0xe8(%rbp),%rdi
movslq -0x94(%rbp),%rax
lea    0xdf5(%rip),%rsi
movzbl -0x90(%rbp,%rax,1),%edx
ff
call   1090 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    -0xe8(%rbp),%rsi
call   1080 <strcat@plt>
movslq -0x94(%rbp),%rax
movzbl -0x90(%rbp,%rax,1),%ecx
ff
xor    $0x78,%ecx
mov    %cl,-0x90(%rbp,%rax,1)
lea    -0xe8(%rbp),%rdi
movslq -0x94(%rbp),%rax
lea    0xdac(%rip),%rsi
movzbl -0x90(%rbp,%rax,1),%edx
ff
call   1090 <sprintf@plt>
lea    -0xe0(%rbp),%rdi
lea    -0xe8(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    11f0 <main+0x80>
lea    -0xe0(%rbp),%rsi
lea    0xd71(%rip),%rdi
call   1050 <printf@plt>
movl   $0x0,-0x94(%rbp)
cmpl   $0x5,-0x94(%rbp)
jge    12d9 <main+0x169>
mov    $0x0,%al
call   1070 <get_nonce_test@plt>
mov    -0x94(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x94(%rbp)
jmp    12b1 <main+0x141>
xor    %eax,%eax
add    $0xf0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xe0,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
lea    0xe4c(%rip),%rbx
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x60(%rsp),%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1030 <SHA256@plt>
xorps  %xmm0,%xmm0
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movb   $0x0,0x50(%rsp)
movq   $0x0,0x8(%rsp)
xor    %ebx,%ebx
lea    0xe0e(%rip),%r14
lea    0x8(%rsp),%r13
lea    0x10(%rsp),%r15
lea    0xe02(%rip),%r12
nopw   0x0(%rax,%rax,1)
movzbl 0x60(%rsp,%rbx,1),%edx
mov    %r13,%rdi
mov    %r14,%rsi
call   1080 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <strcat@plt>
movzbl 0x60(%rsp,%rbx,1),%edx
xor    $0x78,%edx
mov    %dl,0x60(%rsp,%rbx,1)
mov    %r13,%rdi
mov    %r12,%rsi
call   1080 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <strcat@plt>
add    $0x1,%rbx
cmp    $0x20,%rbx
jne    1210 <main+0xb0>
lea    0xdb5(%rip),%rdi
lea    0x10(%rsp),%rsi
call   1050 <printf@plt>
xor    %eax,%eax
call   1060 <get_nonce_test@plt>
xor    %eax,%eax
call   1060 <get_nonce_test@plt>
xor    %eax,%eax
call   1060 <get_nonce_test@plt>
xor    %eax,%eax
call   1060 <get_nonce_test@plt>
xor    %eax,%eax
call   1060 <get_nonce_test@plt>
xor    %eax,%eax
add    $0xe0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"hello1\00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [7 x i8] c" %02X \00"
@.str.3 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [128 x i8]
%3 = alloca i32
%4 = alloca [65 x i8]
%5 = alloca [8 x i8]
store i32 0, i32* %1
%6 = bitcast [128 x i8]* %2 to i8*
%7 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%9 = call i32 @SHA256(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %7, i8* %8)
store i32 0, i32* %3
%10 = bitcast [65 x i8]* %4 to i8*
%11 = bitcast [8 x i8]* %5 to i8*
store i32 0, i32* %3
br label %12
12: ; preds = %41, %0
%13 = load i32, i32* %3
%14 = icmp slt i32 %13, 32
br i1 %14, label %15, label %44
15: ; preds = %12
%16 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%17 = load i32, i32* %3
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %18
%20 = load i8, i8* %19
%21 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %20)
%22 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%24 = call i32 @strcat(i8* %22, i8* %23)
%25 = load i32, i32* %3
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %26
%28 = load i8, i8* %27
%29 = zext i8 %28 to i32
%30 = xor i32 %29, 120
%31 = trunc i32 %30 to i8
store i8 %31, i8* %27
%32 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%33 = load i32, i32* %3
%34 = sext i32 %33 to i64
%35 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = call i32 @sprintf(i8* %32, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %36)
%38 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%39 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%40 = call i32 @strcat(i8* %38, i8* %39)
br label %41
41: ; preds = %15
%42 = load i32, i32* %3
%43 = add nsw i32 %42, 1
store i32 %43, i32* %3
br label %12
44: ; preds = %12
%45 = getelementptr inbounds [65 x i8], [65 x i8]* %4, i64 0, i64 0
%46 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %45)
store i32 0, i32* %3
br label %47
47: ; preds = %52, %44
%48 = load i32, i32* %3
%49 = icmp slt i32 %48, 5
br i1 %49, label %50, label %55
50: ; preds = %47
%51 = call i32 (...) @get_nonce_test()
br label %52
52: ; preds = %50
%53 = load i32, i32* %3
%54 = add nsw i32 %53, 1
store i32 %54, i32* %3
br label %47
55: ; preds = %47
ret i32 0
}

LLVM IR (-O2):
@.str = [7 x i8] c"hello1\00"
@.str.1 = [5 x i8] c"%02X\00"
@.str.2 = [7 x i8] c" %02X \00"
@.str.3 = [10 x i8] c"buf = %s\0A\00"
define i32 @main() {
%1 = alloca [128 x i8]
%2 = alloca [65 x i8]
%3 = alloca i64
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @SHA256(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5, i8* %4)
%7 = getelementptr inbounds [65 x i8], [65 x i8]* %2, i64 0, i64 0
%8 = bitcast i64* %3 to i8*
store i64 0, i64* %3
br label %9
9: ; preds = %0, %9
%10 = phi i64 [ 0, %0 ], [ %19, %9 ]
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %1, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8 zeroext %12)
%14 = call i32 @strcat(i8* %7, i8* %8)
%15 = load i8, i8* %11
%16 = xor i8 %15, 120
store i8 %16, i8* %11
%17 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8 zeroext %16)
%18 = call i32 @strcat(i8* %7, i8* %8)
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, 32
br i1 %20, label %21, label %9
21: ; preds = %9
%22 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0), i8* %7)
%23 = call i32 (...) @get_nonce_test()
%24 = call i32 (...) @get_nonce_test()
%25 = call i32 (...) @get_nonce_test()
%26 = call i32 (...) @get_nonce_test()
%27 = call i32 (...) @get_nonce_test()
ret i32 0
}