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

/* Variables and functions */
int /*<<< orphan*/ SHA1_Final(unsigned char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Init(int /*<<< orphan*/ *);
int /*<<< orphan*/ SHA1_Update(int /*<<< orphan*/ *, unsigned char *,
                               int /*<<< orphan*/);
int SHA_DIGEST_LENGTH;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(unsigned char *);
void incr_sha1(unsigned char *str1, unsigned char *str2) {
  int i;
  SHA_CTX ctx;
  unsigned char result[SHA_DIGEST_LENGTH];
  SHA1_Init(&ctx);
  SHA1_Update(&ctx, str1, strlen(str1));
  SHA1_Update(&ctx, str2, strlen(str2));
  SHA1_Final(result, &ctx);
  for (i = 0; i < SHA_DIGEST_LENGTH; i++)
    fprintf(stderr, "%02x", result[i]);
  fprintf(stderr, "\n");
}


x86 assembly (clang, -O0):
<incr_sha1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x28(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <SHA1_Init@plt>
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rsi
mov    %eax,%edx
lea    -0x18(%rbp),%rdi
call   1050 <SHA1_Update@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
lea    -0x18(%rbp),%rdi
call   1050 <SHA1_Update@plt>
mov    -0x30(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <SHA1_Final@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
jge    122c <incr_sha1+0xdc>
mov    -0x30(%rbp),%rax
mov    0x2dd2(%rip),%rcx
mov    (%rcx),%edi
movslq -0x14(%rbp),%rcx
movzbl (%rax,%rcx,1),%edx
lea    0xde9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11e9 <incr_sha1+0x99>
mov    0x2da5(%rip),%rax
mov    (%rax),%edi
lea    0xdc9(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<incr_sha1>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rsp,-0x30(%rbp)
mov    0x2e76(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%r12
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r12
mov    %r12,%rsp
lea    -0x34(%rbp),%rbx
mov    %rbx,%rdi
call   1060 <SHA1_Init@plt>
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1050 <SHA1_Update@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <SHA1_Update@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
call   1070 <SHA1_Final@plt>
cmpl   $0x0,0x0(%r13)
jle    11ff <incr_sha1+0xaf>
mov    0x2e02(%rip),%r15
lea    0xe23(%rip),%r14
xor    %ebx,%ebx
nop
mov    (%r15),%edi
movzbl (%r12,%rbx,1),%edx
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
add    $0x1,%rbx
movslq 0x0(%r13),%rax
cmp    %rax,%rbx
jl     11e0 <incr_sha1+0x90>
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xdf6(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@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):
@SHA_DIGEST_LENGTH = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @incr_sha1(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
store i8* %0, i8** %3
store i8* %1, i8** %4
%9 = load i32, i32* @SHA_DIGEST_LENGTH
%10 = zext i32 %9 to i64
%11 = call i8* @llvm.stacksave()
store i8* %11, i8** %7
%12 = alloca i8, i64 %10
store i64 %10, i64* %8
%13 = call i32 @SHA1_Init(i32* %6)
%14 = load i8*, i8** %3
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = call i32 @SHA1_Update(i32* %6, i8* %14, i32 %16)
%18 = load i8*, i8** %4
%19 = load i8*, i8** %4
%20 = call i32 @strlen(i8* %19)
%21 = call i32 @SHA1_Update(i32* %6, i8* %18, i32 %20)
%22 = call i32 @SHA1_Final(i8* %12, i32* %6)
store i32 0, i32* %5
br label %23
23: ; preds = %35, %2
%24 = load i32, i32* %5
%25 = load i32, i32* @SHA_DIGEST_LENGTH
%26 = icmp slt i32 %24, %25
br i1 %26, label %27, label %38
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = load i32, i32* %5
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %12, i64 %30
%32 = load i8, i8* %31
%33 = zext i8 %32 to i32
%34 = call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %27
%36 = load i32, i32* %5
%37 = add nsw i32 %36, 1
store i32 %37, i32* %5
br label %23
38: ; preds = %23
%39 = load i32, i32* @stderr
%40 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%41 = load i8*, i8** %7
ret void
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i32 0
@stderr = global i32 0
@.str = [5 x i8] c"%02x\00"
@.str.1 = [2 x i8] c"\0A\00"
define void @incr_sha1(i8* %0, i8* %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = load i32, i32* @SHA_DIGEST_LENGTH
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = call i32 @SHA1_Init(i32* %3)
%10 = call i32 @strlen(i8* %0)
%11 = call i32 @SHA1_Update(i32* %3, i8* %0, i32 %10)
%12 = call i32 @strlen(i8* %1)
%13 = call i32 @SHA1_Update(i32* %3, i8* %1, i32 %12)
%14 = call i32 @SHA1_Final(i8* %8, i32* %3)
%15 = load i32, i32* @SHA_DIGEST_LENGTH
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %28
17: ; preds = %2, %17
%18 = phi i64 [ %24, %17 ], [ 0, %2 ]
%19 = load i32, i32* @stderr
%20 = getelementptr inbounds i8, i8* %8, i64 %18
%21 = load i8, i8* %20
%22 = zext i8 %21 to i32
%23 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %22)
%24 = add nuw nsw i64 %18, 1
%25 = load i32, i32* @SHA_DIGEST_LENGTH
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %17, label %28
28: ; preds = %17, %2
%29 = load i32, i32* @stderr
%30 = call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
ret void
}