#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 getchar();
int /*<<< orphan*/ printf(char *, ...);
int randomChance(double);
int randomInteger(int, int);
int /*<<< orphan*/ randomize();
int /*<<< orphan*/ sayCorrect(int);
int scanf(char *, int *);
void questions(int times) {
  randomize();
  int x, y, sum, answer, correct, loop;
  int op;
  int ref, c;
  while (times) {
    x = randomInteger(1, 20);
    y = randomInteger(1, 20);
    op = randomChance(0.5);
    correct = 1;
    sum = (op) ? x + y : x - y;
    loop = 0;
    if (sum > 0 && sum < 20) {
      printf("What is %d %s %d? ", x, (op) ? "+" : "-", y);
      while (correct) {
        ref = scanf("%d", &answer);
        while ((c = getchar()) != '\n')
          ;
        if (loop == 2) {
          printf("No, the answer is %d.\n", sum);
          times--;
          break;
        }
        if (ref != 0) {
          if (answer == sum) {
            sayCorrect(sum);
            correct = 0;
            times--;
          } else {
            printf("That's incorrect. Try a different answer: ");
            loop++;
          }
        } else {
          printf("That's incorrect. Try a different answer: ");
          loop++;
        }
      }
    }
  }
}


x86 assembly (clang, -O0):
<questions>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    $0x0,%al
call   1080 <randomize@plt>
cmpl   $0x0,-0x4(%rbp)
je     1308 <questions+0x198>
mov    $0x1,%edi
mov    $0x14,%esi
call   1040 <randomInteger@plt>
mov    %eax,-0x8(%rbp)
mov    $0x1,%edi
mov    $0x14,%esi
call   1040 <randomInteger@plt>
mov    %eax,-0xc(%rbp)
movsd  0xe48(%rip),%xmm0
call   1090 <randomChance@plt>
mov    %eax,-0x20(%rbp)
movl   $0x1,-0x18(%rbp)
cmpl   $0x0,-0x20(%rbp)
je     11df <questions+0x6f>
mov    -0x8(%rbp),%eax
add    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
jmp    11e8 <questions+0x78>
mov    -0x8(%rbp),%eax
sub    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
mov    %eax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x10(%rbp)
jle    1303 <questions+0x193>
cmpl   $0x14,-0x10(%rbp)
jge    1303 <questions+0x193>
mov    -0x8(%rbp),%esi
mov    -0x20(%rbp),%ecx
lea    0xe07(%rip),%rdx
lea    0xdfe(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
mov    -0xc(%rbp),%ecx
lea    0xdda(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x0,-0x18(%rbp)
je     12fe <questions+0x18e>
lea    0xdd9(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    %eax,-0x28(%rbp)
cmp    $0xa,%eax
je     126a <questions+0xfa>
jmp    1252 <questions+0xe2>
cmpl   $0x2,-0x1c(%rbp)
jne    1293 <questions+0x123>
mov    -0x10(%rbp),%esi
lea    0xda4(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    12fe <questions+0x18e>
cmpl   $0x0,-0x24(%rbp)
je     12e2 <questions+0x172>
mov    -0x14(%rbp),%eax
cmp    -0x10(%rbp),%eax
jne    12c6 <questions+0x156>
mov    -0x10(%rbp),%edi
call   1060 <sayCorrect@plt>
movl   $0x0,-0x18(%rbp)
mov    -0x4(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x4(%rbp)
jmp    12dd <questions+0x16d>
lea    0xd6c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12f9 <questions+0x189>
lea    0xd50(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1235 <questions+0xc5>
jmp    1303 <questions+0x193>
jmp    1182 <questions+0x12>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<questions>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edi,%r15d
xor    %eax,%eax
call   1080 <randomize@plt>
test   %r15d,%r15d
je     12e1 <questions+0x171>
lea    0x4(%rsp),%r12
jmp    11b4 <questions+0x44>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %ebp,%edi
call   1060 <sayCorrect@plt>
add    $0xffffffff,%r15d
test   %r15d,%r15d
je     12e1 <questions+0x171>
mov    $0x1,%edi
mov    $0x14,%esi
call   1040 <randomInteger@plt>
mov    %eax,%r13d
mov    $0x1,%edi
mov    $0x14,%esi
call   1040 <randomInteger@plt>
mov    %eax,%r14d
movsd  0xe20(%rip),%xmm0
call   1090 <randomChance@plt>
mov    %r14d,%ebp
neg    %ebp
test   %eax,%eax
cmovne %r14d,%ebp
lea    -0x1(%rbp,%r13,1),%ecx
cmp    $0x12,%ecx
ja     11ab <questions+0x3b>
add    %r13d,%ebp
test   %eax,%eax
lea    0xe15(%rip),%rdx
lea    0xe10(%rip),%rax
cmove  %rax,%rdx
lea    0xdf0(%rip),%rdi
mov    %r13d,%esi
mov    %r14d,%ecx
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdf3(%rip),%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
mov    %eax,%ebx
cs nopw 0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
jne    1240 <questions+0xd0>
test   %ebx,%ebx
je     125a <questions+0xea>
cmp    %ebp,0x4(%rsp)
je     11a0 <questions+0x30>
lea    0xdd8(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xdb0(%rip),%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
mov    %eax,%ebx
nopl   0x0(%rax)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
jne    1280 <questions+0x110>
test   %ebx,%ebx
je     129a <questions+0x12a>
cmp    %ebp,0x4(%rsp)
je     11a0 <questions+0x30>
lea    0xd98(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xd70(%rip),%rdi
mov    %r12,%rsi
call   1070 <scanf@plt>
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <getchar@plt>
cmp    $0xa,%eax
jne    12c0 <questions+0x150>
lea    0xd4f(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    11a7 <questions+0x37>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"What is %d %s %d? \00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [23 x i8] c"No, the answer is %d.\0A\00"
@.str.5 = [43 x i8] c"That's incorrect. Try a different answer: \00"
define void @questions(i32 %0) {
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %2
%12 = call i32 (...) @randomize()
br label %13
13: ; preds = %85, %1
%14 = load i32, i32* %2
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %86
16: ; preds = %13
%17 = call i32 @randomInteger(i32 1, i32 20)
store i32 %17, i32* %3
%18 = call i32 @randomInteger(i32 1, i32 20)
store i32 %18, i32* %4
%19 = call i32 @randomChance(double 5.000000e-01)
store i32 %19, i32* %9
store i32 1, i32* %7
%20 = load i32, i32* %9
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* %3
%24 = load i32, i32* %4
%25 = add nsw i32 %23, %24
br label %30
26: ; preds = %16
%27 = load i32, i32* %3
%28 = load i32, i32* %4
%29 = sub nsw i32 %27, %28
br label %30
30: ; preds = %26, %22
%31 = phi i32 [ %25, %22 ], [ %29, %26 ]
store i32 %31, i32* %5
store i32 0, i32* %8
%32 = load i32, i32* %5
%33 = icmp sgt i32 %32, 0
br i1 %33, label %34, label %85
34: ; preds = %30
%35 = load i32, i32* %5
%36 = icmp slt i32 %35, 20
br i1 %36, label %37, label %85
37: ; preds = %34
%38 = load i32, i32* %3
%39 = load i32, i32* %9
%40 = icmp ne i32 %39, 0
%41 = zext i1 %40 to i64
%42 = select i1 %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%43 = load i32, i32* %4
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %38, i8* %42, i32 %43)
br label %45
45: ; preds = %83, %37
%46 = load i32, i32* %7
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %84
48: ; preds = %45
%49 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %6)
store i32 %49, i32* %10
br label %50
50: ; preds = %53, %48
%51 = call i32 (...) @getchar()
store i32 %51, i32* %11
%52 = icmp ne i32 %51, 10
br i1 %52, label %53, label %54
53: ; preds = %50
br label %50
54: ; preds = %50
%55 = load i32, i32* %8
%56 = icmp eq i32 %55, 2
br i1 %56, label %57, label %62
57: ; preds = %54
%58 = load i32, i32* %5
%59 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %58)
%60 = load i32, i32* %2
%61 = add nsw i32 %60, -1
store i32 %61, i32* %2
br label %84
62: ; preds = %54
%63 = load i32, i32* %10
%64 = icmp ne i32 %63, 0
br i1 %64, label %65, label %79
65: ; preds = %62
%66 = load i32, i32* %6
%67 = load i32, i32* %5
%68 = icmp eq i32 %66, %67
br i1 %68, label %69, label %74
69: ; preds = %65
%70 = load i32, i32* %5
%71 = call i32 @sayCorrect(i32 %70)
store i32 0, i32* %7
%72 = load i32, i32* %2
%73 = add nsw i32 %72, -1
store i32 %73, i32* %2
br label %78
74: ; preds = %65
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %78
78: ; preds = %74, %69
br label %83
79: ; preds = %62
%80 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%81 = load i32, i32* %8
%82 = add nsw i32 %81, 1
store i32 %82, i32* %8
br label %83
83: ; preds = %79, %78
br label %45
84: ; preds = %57, %45
br label %85
85: ; preds = %84, %34, %30
br label %13
86: ; preds = %13
ret void
}

LLVM IR (-O2):
@.str = [19 x i8] c"What is %d %s %d? \00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [2 x i8] c"-\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [23 x i8] c"No, the answer is %d.\0A\00"
@.str.5 = [43 x i8] c"That's incorrect. Try a different answer: \00"
define void @questions(i32 %0) {
%2 = alloca i32
%3 = tail call i32 (...) @randomize()
%4 = bitcast i32* %2 to i8*
%5 = icmp eq i32 %0, 0
br i1 %5, label %55, label %6
6: ; preds = %1, %52
%7 = phi i32 [ %53, %52 ], [ %0, %1 ]
%8 = call i32 @randomInteger(i32 1, i32 20)
%9 = call i32 @randomInteger(i32 1, i32 20)
%10 = call i32 @randomChance(double 5.000000e-01)
%11 = icmp eq i32 %10, 0
%12 = sub i32 0, %9
%13 = select i1 %11, i32 %12, i32 %9
%14 = add i32 %13, %8
%15 = add i32 %14, -1
%16 = icmp ult i32 %15, 19
br i1 %16, label %17, label %52
17: ; preds = %6
%18 = select i1 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %8, i8* %18, i32 %9)
%20 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %21
21: ; preds = %21, %17
%22 = call i32 (...) @getchar()
%23 = icmp eq i32 %22, 10
br i1 %23, label %24, label %21
24: ; preds = %21
%25 = icmp ne i32 %20, 0
%26 = load i32, i32* %2
%27 = icmp eq i32 %26, %14
%28 = select i1 %25, i1 %27, i1 false
br i1 %28, label %49, label %29
29: ; preds = %24
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %32
32: ; preds = %32, %29
%33 = call i32 (...) @getchar()
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %32
35: ; preds = %32
%36 = icmp ne i32 %31, 0
%37 = load i32, i32* %2
%38 = icmp eq i32 %37, %14
%39 = select i1 %36, i1 %38, i1 false
br i1 %39, label %49, label %40
40: ; preds = %35
%41 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%42 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
br label %43
43: ; preds = %43, %40
%44 = call i32 (...) @getchar()
%45 = icmp eq i32 %44, 10
br i1 %45, label %46, label %43
46: ; preds = %43
%47 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i32 %14)
%48 = add nsw i32 %7, -1
br label %52
49: ; preds = %35, %24
%50 = call i32 @sayCorrect(i32 %14)
%51 = add nsw i32 %7, -1
br label %52
52: ; preds = %49, %46, %6
%53 = phi i32 [ %48, %46 ], [ %7, %6 ], [ %51, %49 ]
%54 = icmp eq i32 %53, 0
br i1 %54, label %55, label %6
55: ; preds = %52, %1
ret void
}