#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*/ calc_response(char *, char *);
int /*<<< orphan*/ call_hash(char *, char *, int);
int /*<<< orphan*/ put32_be(char *, int);
void calc_response_string(char *result, char *challenge) {
  char field[128];
  char zres[20];
  int i;
  put32_be(field, 0x01234567);
  put32_be(field + 4, 0x89abcdef);
  put32_be(field + 8, 0xfedcba98);
  put32_be(field + 12, 0x76543210);
  put32_be(field + 16, 0x00000000);
  put32_be(field + 20, 0x00000000);
  call_hash(field, challenge, 64);
  calc_response(zres, field);
  for (i = 0; i < 16; i++) {
    char a, b;
    a = (zres[i] >> 4) & 0x0f;
    b = zres[i] & 0x0f;
    result[i * 2] = ((a < 10) ? (a + 48) : (a + 87)) & 0xff;
    result[i * 2 + 1] = ((b < 10) ? (b + 48) : (b + 87)) & 0xff;
  }
}


x86 assembly (clang, -O0):
<calc_response_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
mov    $0x1234567,%esi
call   1040 <put32_be@plt>
lea    -0x90(%rbp),%rdi
add    $0x4,%rdi
mov    $0x89abcdef,%esi
call   1040 <put32_be@plt>
lea    -0x90(%rbp),%rdi
add    $0x8,%rdi
mov    $0xfedcba98,%esi
call   1040 <put32_be@plt>
lea    -0x90(%rbp),%rdi
add    $0xc,%rdi
mov    $0x76543210,%esi
call   1040 <put32_be@plt>
lea    -0x90(%rbp),%rdi
add    $0x10,%rdi
xor    %esi,%esi
call   1040 <put32_be@plt>
lea    -0x90(%rbp),%rdi
add    $0x14,%rdi
xor    %esi,%esi
call   1040 <put32_be@plt>
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0x40,%edx
call   1030 <call_hash@plt>
lea    -0xb0(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1050 <calc_response@plt>
movl   $0x0,-0xb4(%rbp)
cmpl   $0x10,-0xb4(%rbp)
jge    12ea <calc_response_string+0x1ba>
movslq -0xb4(%rbp),%rax
movsbl -0xb0(%rbp,%rax,1),%eax
ff
sar    $0x4,%eax
and    $0xf,%eax
mov    %al,-0xb5(%rbp)
movslq -0xb4(%rbp),%rax
movsbl -0xb0(%rbp,%rax,1),%eax
ff
and    $0xf,%eax
mov    %al,-0xb6(%rbp)
movsbl -0xb5(%rbp),%eax
cmp    $0xa,%eax
jge    124e <calc_response_string+0x11e>
movsbl -0xb5(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0xbc(%rbp)
jmp    125e <calc_response_string+0x12e>
movsbl -0xb5(%rbp),%eax
add    $0x57,%eax
mov    %eax,-0xbc(%rbp)
mov    -0xbc(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xb4(%rbp),%ecx
shl    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
movsbl -0xb6(%rbp),%eax
cmp    $0xa,%eax
jge    12a3 <calc_response_string+0x173>
movsbl -0xb6(%rbp),%eax
add    $0x30,%eax
mov    %eax,-0xc0(%rbp)
jmp    12b3 <calc_response_string+0x183>
movsbl -0xb6(%rbp),%eax
add    $0x57,%eax
mov    %eax,-0xc0(%rbp)
mov    -0xc0(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0xb4(%rbp),%ecx
shl    $0x1,%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0xb4(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xb4(%rbp)
jmp    11e9 <calc_response_string+0xb9>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<calc_response_string>:
push   %r15
push   %r14
push   %rbx
sub    $0xa0,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x20(%rsp),%r15
mov    %r15,%rdi
mov    $0x1234567,%esi
call   1040 <put32_be@plt>
lea    0x24(%rsp),%rdi
mov    $0x89abcdef,%esi
call   1040 <put32_be@plt>
lea    0x28(%rsp),%rdi
mov    $0xfedcba98,%esi
call   1040 <put32_be@plt>
lea    0x2c(%rsp),%rdi
mov    $0x76543210,%esi
call   1040 <put32_be@plt>
lea    0x30(%rsp),%rdi
xor    %esi,%esi
call   1040 <put32_be@plt>
lea    0x34(%rsp),%rdi
xor    %esi,%esi
call   1040 <put32_be@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x40,%edx
call   1030 <call_hash@plt>
mov    %rsp,%rdi
mov    %r15,%rsi
call   1050 <calc_response@plt>
movq   (%rsp),%xmm1
movdqa %xmm1,%xmm7
movdqa 0xe5b(%rip),%xmm0
movdqa %xmm1,%xmm6
pmaxub %xmm0,%xmm6
pcmpeqb %xmm1,%xmm6
movdqa %xmm1,%xmm4
psrlw  $0x4,%xmm4
movdqa 0xe1d(%rip),%xmm8
pand   %xmm8,%xmm4
movdqa 0xe20(%rip),%xmm1
pand   %xmm1,%xmm7
movdqa 0xe34(%rip),%xmm2
movdqa %xmm4,%xmm5
por    %xmm2,%xmm5
movdqa 0xe33(%rip),%xmm9
paddb  %xmm9,%xmm4
pand   %xmm6,%xmm4
pandn  %xmm5,%xmm6
por    %xmm4,%xmm6
movdqa 0xe2a(%rip),%xmm4
movdqa %xmm7,%xmm5
pmaxub %xmm4,%xmm5
pcmpeqb %xmm7,%xmm5
movdqa %xmm7,%xmm3
por    %xmm2,%xmm3
paddb  %xmm9,%xmm7
pand   %xmm5,%xmm7
pandn  %xmm3,%xmm5
por    %xmm7,%xmm5
punpcklbw %xmm5,%xmm6
movdqu %xmm6,(%r14)
movq   0x8(%rsp),%xmm3
pand   %xmm3,%xmm1
pmaxub %xmm3,%xmm0
pcmpeqb %xmm3,%xmm0
psrlw  $0x4,%xmm3
pand   %xmm8,%xmm3
movdqa %xmm3,%xmm5
por    %xmm2,%xmm5
paddb  %xmm9,%xmm3
pand   %xmm0,%xmm3
pandn  %xmm5,%xmm0
por    %xmm3,%xmm0
pmaxub %xmm1,%xmm4
pcmpeqb %xmm1,%xmm4
por    %xmm1,%xmm2
paddb  %xmm9,%xmm1
pand   %xmm4,%xmm1
pandn  %xmm2,%xmm4
por    %xmm1,%xmm4
punpcklbw %xmm4,%xmm0
movdqu %xmm0,0x10(%r14)
add    $0xa0,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @calc_response_string(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [128 x i8]
%6 = alloca [20 x i8]
%7 = alloca i32
%8 = alloca i8
%9 = alloca i8
store i8* %0, i8** %3
store i8* %1, i8** %4
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%11 = call i32 @put32_be(i8* %10, i32 19088743)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%13 = getelementptr inbounds i8, i8* %12, i64 4
%14 = call i32 @put32_be(i8* %13, i32 -1985229329)
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%16 = getelementptr inbounds i8, i8* %15, i64 8
%17 = call i32 @put32_be(i8* %16, i32 -19088744)
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%19 = getelementptr inbounds i8, i8* %18, i64 12
%20 = call i32 @put32_be(i8* %19, i32 1985229328)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 16
%23 = call i32 @put32_be(i8* %22, i32 0)
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds i8, i8* %24, i64 20
%26 = call i32 @put32_be(i8* %25, i32 0)
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%28 = load i8*, i8** %4
%29 = call i32 @call_hash(i8* %27, i8* %28, i32 64)
%30 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%31 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%32 = call i32 @calc_response(i8* %30, i8* %31)
store i32 0, i32* %7
br label %33
33: ; preds = %93, %2
%34 = load i32, i32* %7
%35 = icmp slt i32 %34, 16
br i1 %35, label %36, label %96
36: ; preds = %33
%37 = load i32, i32* %7
%38 = sext i32 %37 to i64
%39 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 %38
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = ashr i32 %41, 4
%43 = and i32 %42, 15
%44 = trunc i32 %43 to i8
store i8 %44, i8* %8
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = and i32 %49, 15
%51 = trunc i32 %50 to i8
store i8 %51, i8* %9
%52 = load i8, i8* %8
%53 = sext i8 %52 to i32
%54 = icmp slt i32 %53, 10
br i1 %54, label %55, label %59
55: ; preds = %36
%56 = load i8, i8* %8
%57 = sext i8 %56 to i32
%58 = add nsw i32 %57, 48
br label %63
59: ; preds = %36
%60 = load i8, i8* %8
%61 = sext i8 %60 to i32
%62 = add nsw i32 %61, 87
br label %63
63: ; preds = %59, %55
%64 = phi i32 [ %58, %55 ], [ %62, %59 ]
%65 = and i32 %64, 255
%66 = trunc i32 %65 to i8
%67 = load i8*, i8** %3
%68 = load i32, i32* %7
%69 = mul nsw i32 %68, 2
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8, i8* %67, i64 %70
store i8 %66, i8* %71
%72 = load i8, i8* %9
%73 = sext i8 %72 to i32
%74 = icmp slt i32 %73, 10
br i1 %74, label %75, label %79
75: ; preds = %63
%76 = load i8, i8* %9
%77 = sext i8 %76 to i32
%78 = add nsw i32 %77, 48
br label %83
79: ; preds = %63
%80 = load i8, i8* %9
%81 = sext i8 %80 to i32
%82 = add nsw i32 %81, 87
br label %83
83: ; preds = %79, %75
%84 = phi i32 [ %78, %75 ], [ %82, %79 ]
%85 = and i32 %84, 255
%86 = trunc i32 %85 to i8
%87 = load i8*, i8** %3
%88 = load i32, i32* %7
%89 = mul nsw i32 %88, 2
%90 = add nsw i32 %89, 1
%91 = sext i32 %90 to i64
%92 = getelementptr inbounds i8, i8* %87, i64 %91
store i8 %86, i8* %92
br label %93
93: ; preds = %83
%94 = load i32, i32* %7
%95 = add nsw i32 %94, 1
store i32 %95, i32* %7
br label %33
96: ; preds = %33
ret void
}

LLVM IR (-O2):
define void @calc_response_string(i8* nocapture writeonly %0, i8* %1) {
%3 = alloca [128 x i8]
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%7 = call i32 @put32_be(i8* %5, i32 19088743)
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 4
%9 = call i32 @put32_be(i8* %8, i32 -1985229329)
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 8
%11 = call i32 @put32_be(i8* %10, i32 -19088744)
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 12
%13 = call i32 @put32_be(i8* %12, i32 1985229328)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 16
%15 = call i32 @put32_be(i8* %14, i32 0)
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 20
%17 = call i32 @put32_be(i8* %16, i32 0)
%18 = call i32 @call_hash(i8* %5, i8* %1, i32 64)
%19 = call i32 @calc_response(i8* %6, i8* %5)
%20 = bitcast [20 x i8]* %4 to <8 x i8>*
%21 = load <8 x i8>, <8 x i8>* %20
%22 = lshr <8 x i8> %21, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>
%23 = and <8 x i8> %21, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%24 = icmp ult <8 x i8> %21, <i8 -96, i8 -96, i8 -96, i8 -96, i8 -96, i8 -96, i8 -96, i8 -96>
%25 = or <8 x i8> %22, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%26 = add nuw nsw <8 x i8> %22, <i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87>
%27 = select <8 x i1> %24, <8 x i8> %25, <8 x i8> %26
%28 = icmp ult <8 x i8> %23, <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
%29 = or <8 x i8> %23, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%30 = add nuw nsw <8 x i8> %23, <i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87>
%31 = select <8 x i1> %28, <8 x i8> %29, <8 x i8> %30
%32 = bitcast i8* %0 to <16 x i8>*
%33 = shufflevector <8 x i8> %27, <8 x i8> %31, <16 x i32> <i32 0, i32 8, i32 1, i32 9, i32 2, i32 10, i32 3, i32 11, i32 4, i32 12, i32 5, i32 13, i32 6, i32 14, i32 7, i32 15>
store <16 x i8> %33, <16 x i8>* %32
%34 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 8
%35 = bitcast i8* %34 to <8 x i8>*
%36 = load <8 x i8>, <8 x i8>* %35
%37 = lshr <8 x i8> %36, <i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4, i8 4>
%38 = and <8 x i8> %36, <i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15, i8 15>
%39 = icmp ult <8 x i8> %36, <i8 -96, i8 -96, i8 -96, i8 -96, i8 -96, i8 -96, i8 -96, i8 -96>
%40 = or <8 x i8> %37, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%41 = add nuw nsw <8 x i8> %37, <i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87>
%42 = select <8 x i1> %39, <8 x i8> %40, <8 x i8> %41
%43 = icmp ult <8 x i8> %38, <i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10, i8 10>
%44 = or <8 x i8> %38, <i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48, i8 48>
%45 = add nuw nsw <8 x i8> %38, <i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87, i8 87>
%46 = select <8 x i1> %43, <8 x i8> %44, <8 x i8> %45
%47 = getelementptr inbounds i8, i8* %0, i64 16
%48 = bitcast i8* %47 to <16 x i8>*
%49 = shufflevector <8 x i8> %42, <8 x i8> %46, <16 x i32> <i32 0, i32 8, i32 1, i32 9, i32 2, i32 10, i32 3, i32 11, i32 4, i32 12, i32 5, i32 13, i32 6, i32 14, i32 7, i32 15>
store <16 x i8> %49, <16 x i8>* %48
ret void
}