#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 game_num(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;
  return y % 0x81;
}


x86 assembly (clang, -O0):
<game_num>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0xc,%eax
je     115a <game_num+0x2a>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ec <game_num+0xbc>
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    %edx,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<game_num>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
call   1040 <strlen@plt>
mov    $0xffffffff,%ecx
cmp    $0xc,%eax
jne    11f0 <game_num+0xc0>
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 $0xfa11caa01fa11cab,%rdx
ca 11 fa
mov    %rcx,%rax
mul    %rdx
sub    %rdx,%rcx
shr    %rcx
add    %rdx,%rcx
shr    $0x8,%rcx
movabs $0xfe03f80fe03f80ff,%rdx
f8 03 fe
mov    %rcx,%rax
mul    %rdx
shr    $0x7,%rdx
mov    %edx,%eax
shl    $0x7,%eax
add    %edx,%eax
sub    %eax,%ecx
mov    %ecx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @game_num(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 %40
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 = urem i64 %37, 129
%39 = trunc i64 %38 to i32
store i32 %39, i32* %2
br label %40
40: ; preds = %16, %15
%41 = load i32, i32* %2
ret i32 %41
}

LLVM IR (-O2):
define i32 @game_num(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 %22
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 = urem i64 %19, 129
%21 = trunc i64 %20 to i32
br label %22
22: ; preds = %1, %8
%23 = phi i32 [ %21, %8 ], [ -1, %1 ]
ret i32 %23
}