#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 strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
unsigned long strtoul(char *, int /*<<< orphan*/ *, int);
int qcrack_checksum(char *challenge) {
  char str1[5];
  char str2[8];
  unsigned long a, x, y, z, breg, sreg;
  if (strlen(challenge) != 12) {
    return -1;
  }
  strncpy(str1, challenge + 1, 4);
  str1[4] = '\0';
  strncpy(str2, challenge + 5, 7);
  str2[7] = '\0';
  sreg = strtoul(str1, NULL, 10);
  breg = strtoul(str2, NULL, 10);
  x = (sreg * 0x3f) ^ breg;
  y = x / 0x103;
  z = y / 0x81;
  a = (z / 7) + (sreg >> 7) + (sreg & 0x7F) + (y % 0x81) + (z % 7);
  return a == x % 0x103;
}


x86 assembly (clang, -O0):
<qcrack_checksum>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xc,%eax
je     115a <qcrack_checksum+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    126d <qcrack_checksum+0x13d>
lea    -0x15(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x11(%rbp)
lea    -0x1d(%rbp),%rdi
mov    -0x10(%rbp),%rsi
add    $0x5,%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
movb   $0x0,-0x16(%rbp)
lea    -0x15(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x50(%rbp)
lea    -0x1d(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,-0x48(%rbp)
imul   $0x3f,-0x50(%rbp),%rax
xor    -0x48(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x103,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    $0x81,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    $0x7,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x50(%rbp),%rcx
shr    $0x7,%rcx
add    %rcx,%rax
mov    -0x50(%rbp),%rcx
and    $0x7f,%rcx
add    %rcx,%rax
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rax
mov    $0x81,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x68(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x60(%rbp)
mov    -0x40(%rbp),%rax
mov    $0x7,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x60(%rbp),%rax
add    %rdx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    $0x103,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x58(%rbp),%rax
cmp    %rdx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<qcrack_checksum>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    $0xc,%ecx
jne    1286 <qcrack_checksum+0x156>
lea    0x1(%rbx),%rsi
lea    0x3(%rsp),%r14
mov    %r14,%rdi
mov    $0x4,%edx
call   1030 <strncpy@plt>
movb   $0x0,0x7(%rsp)
add    $0x5,%rbx
lea    0x8(%rsp),%r15
mov    %r15,%rdi
mov    %rbx,%rsi
mov    $0x7,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xf(%rsp)
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rax,%rbx
mov    %r15,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1050 <strtoul@plt>
mov    %rbx,%rcx
shl    $0x6,%rcx
sub    %rbx,%rcx
xor    %rax,%rcx
movabs $0xfb12bfd06ef2a903,%rdx
bf 12 fb
mov    %rcx,%rax
mul    %rdx
mov    %rdx,%r9
movabs $0x1ef0db375a39e5bb,%rdx
db f0 1e
mov    %rcx,%rax
mul    %rdx
shr    $0xf,%r9
mov    %rcx,%rax
sub    %rdx,%rax
shr    %rax
add    %rdx,%rax
shr    $0x11,%rax
mov    %rbx,%rdx
shr    $0x7,%rdx
and    $0x7f,%ebx
add    %rdx,%rbx
add    %rax,%rbx
movabs $0xfa11caa01fa11cab,%rdx
ca 11 fa
mov    %rcx,%rax
mul    %rdx
mov    %rcx,%rdi
sub    %rdx,%rdi
shr    %rdi
add    %rdx,%rdi
shr    $0x8,%rdi
movabs $0xfe03f80fe03f80ff,%rdx
f8 03 fe
mov    %rdi,%rax
mul    %rdx
shr    $0x7,%rdx
mov    %rdx,%rax
shl    $0x7,%rax
add    %rdx,%rax
imul   $0x103,%rdi,%r8
sub    %rax,%rdi
add    %rbx,%rdi
movabs $0x2492492492492493,%rdx
49 92 24
mov    %r9,%rax
mul    %rdx
mov    %r9,%rsi
sub    %rdx,%rsi
shr    %rsi
add    %rdx,%rsi
shr    $0x2,%rsi
lea    0x0(,%rsi,8),%rax
sub    %rax,%rsi
add    %r9,%rsi
add    %rdi,%rsi
sub    %r8,%rcx
xor    %eax,%eax
cmp    %rcx,%rsi
sete   %al
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @qcrack_checksum(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca [5 x i8]
%5 = alloca [8 x i8]
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
store i8* %0, i8** %3
%12 = load i8*, i8** %3
%13 = call i32 @strlen(i8* %12)
%14 = icmp ne i32 %13, 12
br i1 %14, label %15, label %16
15: ; preds = %1
store i32 -1, i32* %2
br label %58
16: ; preds = %1
%17 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%18 = load i8*, i8** %3
%19 = getelementptr inbounds i8, i8* %18, i64 1
%20 = call i32 @strncpy(i8* %17, i8* %19, i32 4)
%21 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 4
store i8 0, i8* %21
%22 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%23 = load i8*, i8** %3
%24 = getelementptr inbounds i8, i8* %23, i64 5
%25 = call i32 @strncpy(i8* %22, i8* %24, i32 7)
%26 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 7
store i8 0, i8* %26
%27 = getelementptr inbounds [5 x i8], [5 x i8]* %4, i64 0, i64 0
%28 = call i64 @strtoul(i8* %27, i32* null, i32 10)
store i64 %28, i64* %11
%29 = getelementptr inbounds [8 x i8], [8 x i8]* %5, i64 0, i64 0
%30 = call i64 @strtoul(i8* %29, i32* null, i32 10)
store i64 %30, i64* %10
%31 = load i64, i64* %11
%32 = mul i64 %31, 63
%33 = load i64, i64* %10
%34 = xor i64 %32, %33
store i64 %34, i64* %7
%35 = load i64, i64* %7
%36 = udiv i64 %35, 259
store i64 %36, i64* %8
%37 = load i64, i64* %8
%38 = udiv i64 %37, 129
store i64 %38, i64* %9
%39 = load i64, i64* %9
%40 = udiv i64 %39, 7
%41 = load i64, i64* %11
%42 = lshr i64 %41, 7
%43 = add i64 %40, %42
%44 = load i64, i64* %11
%45 = and i64 %44, 127
%46 = add i64 %43, %45
%47 = load i64, i64* %8
%48 = urem i64 %47, 129
%49 = add i64 %46, %48
%50 = load i64, i64* %9
%51 = urem i64 %50, 7
%52 = add i64 %49, %51
store i64 %52, i64* %6
%53 = load i64, i64* %6
%54 = load i64, i64* %7
%55 = urem i64 %54, 259
%56 = icmp eq i64 %53, %55
%57 = zext i1 %56 to i32
store i32 %57, i32* %2
br label %58
58: ; preds = %16, %15
%59 = load i32, i32* %2
ret i32 %59
}

LLVM IR (-O2):
define i32 @qcrack_checksum(i8* %0) {
%2 = alloca [5 x i8]
%3 = alloca [8 x i8]
%4 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%6 = tail call i32 @strlen(i8* %0)
%7 = icmp eq i32 %6, 12
br i1 %7, label %8, label %33
8: ; preds = %1
%9 = getelementptr inbounds i8, i8* %0, i64 1
%10 = call i32 @strncpy(i8* %4, i8* %9, i32 4)
%11 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 4
store i8 0, i8* %11
%12 = getelementptr inbounds i8, i8* %0, i64 5
%13 = call i32 @strncpy(i8* %5, i8* %12, i32 7)
%14 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 7
store i8 0, i8* %14
%15 = call i64 @strtoul(i8* nocapture %4, i32* null, i32 10)
%16 = call i64 @strtoul(i8* nocapture %5, i32* null, i32 10)
%17 = mul i64 %15, 63
%18 = xor i64 %17, %16
%19 = udiv i64 %18, 259
%20 = udiv i64 %18, 33411
%21 = udiv i64 %18, 233877
%22 = lshr i64 %15, 7
%23 = and i64 %15, 127
%24 = urem i64 %19, 129
%25 = urem i64 %20, 7
%26 = add nuw nsw i64 %23, %22
%27 = add nuw nsw i64 %26, %21
%28 = add nuw nsw i64 %27, %24
%29 = add nuw nsw i64 %28, %25
%30 = urem i64 %18, 259
%31 = icmp eq i64 %29, %30
%32 = zext i1 %31 to i32
br label %33
33: ; preds = %1, %8
%34 = phi i32 [ %32, %8 ], [ -1, %1 ]
ret i32 %34
}