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

/* Variables and functions */
int /*<<< orphan*/ SHA1(char *, int /*<<< orphan*/, unsigned char *);
int /*<<< orphan*/ sprintf(char *, char *, unsigned char);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *sha1_hash(char *input_url, char *hashed_url) {
  unsigned char hashed_160bits[20];
  char hashed_hex[41];
  int i;
  SHA1(input_url, strlen(input_url), hashed_160bits);
  for (i = 0; i < sizeof(hashed_160bits); i++)
    sprintf(hashed_hex + i * 2, "%02x", hashed_160bits[i]);
  strcpy(hashed_url, hashed_hex);
  return hashed_url;
}


x86 assembly (clang, -O0):
<sha1_hash>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
lea    -0x30(%rbp),%rdx
call   1050 <SHA1@plt>
movl   $0x0,-0x64(%rbp)
movslq -0x64(%rbp),%rax
cmp    $0x14,%rax
jae    11b7 <sha1_hash+0x77>
lea    -0x60(%rbp),%rdi
mov    -0x64(%rbp),%eax
shl    $0x1,%eax
cltq
add    %rax,%rdi
movslq -0x64(%rbp),%rax
lea    0xe61(%rip),%rsi
movzbl -0x30(%rbp,%rax,1),%edx
call   1060 <sprintf@plt>
mov    -0x64(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x64(%rbp)
jmp    1177 <sha1_hash+0x37>
mov    -0x10(%rbp),%rdi
lea    -0x60(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sha1_hash>:
push   %r15
push   %r14
push   %rbx
sub    $0x50,%rsp
mov    %rsi,%r15
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %rsp,%rdx
mov    %rbx,%rdi
mov    %eax,%esi
call   1050 <SHA1@plt>
movzbl (%rsp),%edx
lea    0xe94(%rip),%rbx
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x22(%rsp),%rdi
movzbl 0x1(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x24(%rsp),%rdi
movzbl 0x2(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x26(%rsp),%rdi
movzbl 0x3(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x28(%rsp),%rdi
movzbl 0x4(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x2a(%rsp),%rdi
movzbl 0x5(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x2c(%rsp),%rdi
movzbl 0x6(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x2e(%rsp),%rdi
movzbl 0x7(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x30(%rsp),%rdi
movzbl 0x8(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x32(%rsp),%rdi
movzbl 0x9(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x34(%rsp),%rdi
movzbl 0xa(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x36(%rsp),%rdi
movzbl 0xb(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x38(%rsp),%rdi
movzbl 0xc(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x3a(%rsp),%rdi
movzbl 0xd(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x3c(%rsp),%rdi
movzbl 0xe(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x3e(%rsp),%rdi
movzbl 0xf(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x40(%rsp),%rdi
movzbl 0x10(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x42(%rsp),%rdi
movzbl 0x11(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x44(%rsp),%rdi
movzbl 0x12(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
lea    0x46(%rsp),%rdi
movzbl 0x13(%rsp),%edx
mov    %rbx,%rsi
call   1060 <sprintf@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
mov    %r15,%rax
add    $0x50,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%02x\00"
define i8* @sha1_hash(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [20 x i8]
%6 = alloca [41 x i8]
%7 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
%8 = load i8*, i8** %3
%9 = load i8*, i8** %3
%10 = call i32 @strlen(i8* %9)
%11 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 0
%12 = call i32 @SHA1(i8* %8, i32 %10, i8* %11)
store i32 0, i32* %7
br label %13
13: ; preds = %28, %2
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = icmp ult i64 %15, 20
br i1 %16, label %17, label %31
17: ; preds = %13
%18 = getelementptr inbounds [41 x i8], [41 x i8]* %6, i64 0, i64 0
%19 = load i32, i32* %7
%20 = mul nsw i32 %19, 2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %18, i64 %21
%23 = load i32, i32* %7
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds [20 x i8], [20 x i8]* %5, i64 0, i64 %24
%26 = load i8, i8* %25
%27 = call i32 @sprintf(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %26)
br label %28
28: ; preds = %17
%29 = load i32, i32* %7
%30 = add nsw i32 %29, 1
store i32 %30, i32* %7
br label %13
31: ; preds = %13
%32 = load i8*, i8** %4
%33 = getelementptr inbounds [41 x i8], [41 x i8]* %6, i64 0, i64 0
%34 = call i32 @strcpy(i8* %32, i8* %33)
%35 = load i8*, i8** %4
ret i8* %35
}

LLVM IR (-O2):
@.str = [5 x i8] c"%02x\00"
define i8* @sha1_hash(i8* %0, i8* returned %1) {
%3 = alloca [20 x i8]
%4 = alloca [41 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %0)
%8 = call i32 @SHA1(i8* %0, i32 %7, i8* %5)
%9 = load i8, i8* %5
%10 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %9)
%11 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 2
%12 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 1
%13 = load i8, i8* %12
%14 = call i32 @sprintf(i8* %11, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %13)
%15 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 4
%16 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 2
%17 = load i8, i8* %16
%18 = call i32 @sprintf(i8* %15, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %17)
%19 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 6
%20 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 3
%21 = load i8, i8* %20
%22 = call i32 @sprintf(i8* %19, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %21)
%23 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 8
%24 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 4
%25 = load i8, i8* %24
%26 = call i32 @sprintf(i8* %23, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %25)
%27 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 10
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 5
%29 = load i8, i8* %28
%30 = call i32 @sprintf(i8* %27, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %29)
%31 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 12
%32 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 6
%33 = load i8, i8* %32
%34 = call i32 @sprintf(i8* %31, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %33)
%35 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 14
%36 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 7
%37 = load i8, i8* %36
%38 = call i32 @sprintf(i8* %35, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %37)
%39 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 16
%40 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 8
%41 = load i8, i8* %40
%42 = call i32 @sprintf(i8* %39, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %41)
%43 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 18
%44 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 9
%45 = load i8, i8* %44
%46 = call i32 @sprintf(i8* %43, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %45)
%47 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 20
%48 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 10
%49 = load i8, i8* %48
%50 = call i32 @sprintf(i8* %47, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %49)
%51 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 22
%52 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 11
%53 = load i8, i8* %52
%54 = call i32 @sprintf(i8* %51, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %53)
%55 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 24
%56 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 12
%57 = load i8, i8* %56
%58 = call i32 @sprintf(i8* %55, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %57)
%59 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 26
%60 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 13
%61 = load i8, i8* %60
%62 = call i32 @sprintf(i8* %59, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %61)
%63 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 28
%64 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 14
%65 = load i8, i8* %64
%66 = call i32 @sprintf(i8* %63, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %65)
%67 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 30
%68 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 15
%69 = load i8, i8* %68
%70 = call i32 @sprintf(i8* %67, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %69)
%71 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 32
%72 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 16
%73 = load i8, i8* %72
%74 = call i32 @sprintf(i8* %71, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %73)
%75 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 34
%76 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 17
%77 = load i8, i8* %76
%78 = call i32 @sprintf(i8* %75, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %77)
%79 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 36
%80 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 18
%81 = load i8, i8* %80
%82 = call i32 @sprintf(i8* %79, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %81)
%83 = getelementptr inbounds [41 x i8], [41 x i8]* %4, i64 0, i64 38
%84 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 19
%85 = load i8, i8* %84
%86 = call i32 @sprintf(i8* %83, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 zeroext %85)
%87 = call i32 @strcpy(i8* %1, i8* %6)
ret i8* %1
}