#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 */
unsigned int atoi(char *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, unsigned int,
                           unsigned int);
int rand();
int /*<<< orphan*/ srand(unsigned int);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
scalar_t__ time(int /*<<< orphan*/ *);
int challenge() {
  unsigned int seed = (unsigned int)(time(NULL));
  unsigned int a, b, result;
  char user_input[49];
  srand(seed);
  a = ((rand() % (9999 - 1000 + 1)) + 1000);
  b = ((rand() % (9999 - 1000 + 1)) + 1000);
  result = a + b;
  do {
    fprintf(stdout, "%u + %u ?\n", a, b);
    fgets(user_input, 49, stdin);
  } while (atoi(user_input) != result);
  return atoi(user_input) == result ? 0 : -1;
}


x86 assembly (clang, -O0):
<challenge>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
xor    %eax,%eax
mov    %eax,%edi
call   1060 <time@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <srand@plt>
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x2328,%ecx
cltd
idiv   %ecx
add    $0x3e8,%edx
mov    %edx,-0x8(%rbp)
mov    $0x0,%al
call   1080 <rand@plt>
mov    $0x2328,%ecx
cltd
idiv   %ecx
add    $0x3e8,%edx
mov    %edx,-0xc(%rbp)
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%edx
mov    -0xc(%rbp),%ecx
lea    0xe35(%rip),%rsi
call   1050 <fprintf@plt>
lea    -0x50(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
mov    $0x31,%esi
call   1040 <fgets@plt>
lea    -0x50(%rbp),%rdi
call   1070 <atoi@plt>
cmp    -0x10(%rbp),%eax
jne    11b5 <challenge+0x55>
lea    -0x50(%rbp),%rdi
call   1070 <atoi@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%esi
mov    $0xffffffff,%eax
xor    %ecx,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<challenge>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
xor    %edi,%edi
call   1060 <time@plt>
mov    %eax,%edi
call   1030 <srand@plt>
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x7482296b,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2328,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r14d
add    $0x3e8,%r14d
xor    %eax,%eax
call   1080 <rand@plt>
cltq
imul   $0x7482296b,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x2c,%rcx
add    %edx,%ecx
imul   $0x2328,%ecx,%ecx
neg    %ecx
lea    (%rax,%rcx,1),%r12d
add    $0x3e8,%r12d
lea    (%r12,%r14,1),%ebp
lea    0xe19(%rip),%r15
mov    0x2dfa(%rip),%r13
mov    %rsp,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    %r15,%rsi
mov    %r14d,%edx
mov    %r12d,%ecx
call   1050 <fprintf@plt>
mov    0x0(%r13),%edx
mov    %rbx,%rdi
mov    $0x31,%esi
call   1040 <fgets@plt>
mov    %rbx,%rdi
call   1070 <atoi@plt>
cmp    %ebp,%eax
jne    1200 <challenge+0xa0>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [11 x i8] c"%u + %u ?\0A\00"
@stdin = global i32 0
define i32 @challenge() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [49 x i8]
%6 = call i64 @time(i32* null)
%7 = trunc i64 %6 to i32
store i32 %7, i32* %1
%8 = load i32, i32* %1
%9 = call i32 @srand(i32 %8)
%10 = call i32 (...) @rand()
%11 = srem i32 %10, 9000
%12 = add nsw i32 %11, 1000
store i32 %12, i32* %2
%13 = call i32 (...) @rand()
%14 = srem i32 %13, 9000
%15 = add nsw i32 %14, 1000
store i32 %15, i32* %3
%16 = load i32, i32* %2
%17 = load i32, i32* %3
%18 = add i32 %16, %17
store i32 %18, i32* %4
br label %19
19: ; preds = %27, %0
%20 = load i32, i32* @stdout
%21 = load i32, i32* %2
%22 = load i32, i32* %3
%23 = call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %21, i32 %22)
%24 = getelementptr inbounds [49 x i8], [49 x i8]* %5, i64 0, i64 0
%25 = load i32, i32* @stdin
%26 = call i32 @fgets(i8* %24, i32 49, i32 %25)
br label %27
27: ; preds = %19
%28 = getelementptr inbounds [49 x i8], [49 x i8]* %5, i64 0, i64 0
%29 = call i32 @atoi(i8* %28)
%30 = load i32, i32* %4
%31 = icmp ne i32 %29, %30
br i1 %31, label %19, label %32
32: ; preds = %27
%33 = getelementptr inbounds [49 x i8], [49 x i8]* %5, i64 0, i64 0
%34 = call i32 @atoi(i8* %33)
%35 = load i32, i32* %4
%36 = icmp eq i32 %34, %35
%37 = zext i1 %36 to i64
%38 = select i1 %36, i32 0, i32 -1
ret i32 %38
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [11 x i8] c"%u + %u ?\0A\00"
@stdin = global i32 0
define i32 @challenge() {
%1 = alloca [49 x i8]
%2 = tail call i64 @time(i32* null)
%3 = trunc i64 %2 to i32
%4 = getelementptr inbounds [49 x i8], [49 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @srand(i32 %3)
%6 = tail call i32 (...) @rand()
%7 = srem i32 %6, 9000
%8 = add nsw i32 %7, 1000
%9 = tail call i32 (...) @rand()
%10 = srem i32 %9, 9000
%11 = add nsw i32 %10, 1000
%12 = add nsw i32 %11, %8
br label %13
13: ; preds = %13, %0
%14 = load i32, i32* @stdout
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %8, i32 %11)
%16 = load i32, i32* @stdin
%17 = call i32 @fgets(i8* %4, i32 49, i32 %16)
%18 = call i32 @atoi(i8* %4)
%19 = icmp eq i32 %18, %12
br i1 %19, label %20, label %13
20: ; preds = %13
ret i32 0
}