#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*/ correctAnswer();
int getRandomNum(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ wrongAnswer();
int answerTheQuestion(int a, int b, int typeOfQuestions) {
  int guess;
  int wrongGuesses = 0;
  int correct = 0;
  int result;
  if (typeOfQuestions > 4)
    typeOfQuestions = getRandomNum(4);
  switch (typeOfQuestions) {
  case 1:
    result = a + b;
    break;
  case 2:
    result = a - b;
    break;
  case 3:
    result = a * b;
    break;
  case 4:
    result = a / b;
    break;
  default:
    printf("Something went wrong\n");
    break;
  }
  do {
    switch (typeOfQuestions) {
    case 1:
      printf("What is %d + %d? ", a, b);
      break;
    case 2:
      printf("What is %d - %d? ", a, b);
      break;
    case 3:
      printf("What is %d x %d? ", a, b);
      break;
    case 4:
      printf("What is %d / %d? ", a, b);
      break;
    default:
      printf("Something went wrong\n");
      break;
    }
    scanf("%d", &guess);
    if (guess == result) {
      correct = 1;
      correctAnswer();
    } else {
      wrongAnswer();
      wrongGuesses++;
    }
  } while (!correct);
  return wrongGuesses;
}


x86 assembly (clang, -O0):
<answerTheQuestion>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0x4,-0xc(%rbp)
jle    1186 <answerTheQuestion+0x36>
mov    $0x4,%edi
call   1040 <getRandomNum@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x28(%rbp)
sub    $0x3,%eax
ja     11e9 <answerTheQuestion+0x99>
mov    -0x28(%rbp),%rax
lea    0xe5a(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11f7 <answerTheQuestion+0xa7>
mov    -0x4(%rbp),%eax
sub    -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11f7 <answerTheQuestion+0xa7>
mov    -0x4(%rbp),%eax
imul   -0x8(%rbp),%eax
mov    %eax,-0x1c(%rbp)
jmp    11f7 <answerTheQuestion+0xa7>
mov    -0x4(%rbp),%eax
cltd
idivl  -0x8(%rbp)
mov    %eax,-0x1c(%rbp)
jmp    11f7 <answerTheQuestion+0xa7>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    11fc <answerTheQuestion+0xac>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0x3,%eax
ja     1289 <answerTheQuestion+0x139>
mov    -0x30(%rbp),%rax
lea    0xdf4(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1297 <answerTheQuestion+0x147>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xdfd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1297 <answerTheQuestion+0x147>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xdf6(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1297 <answerTheQuestion+0x147>
mov    -0x4(%rbp),%esi
mov    -0x8(%rbp),%edx
lea    0xdef(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
jmp    1297 <answerTheQuestion+0x147>
lea    0xd90(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xde0(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1060 <scanf@plt>
mov    -0x10(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    12c6 <answerTheQuestion+0x176>
movl   $0x1,-0x18(%rbp)
mov    $0x0,%al
call   1070 <correctAnswer@plt>
jmp    12d6 <answerTheQuestion+0x186>
mov    $0x0,%al
call   1030 <wrongAnswer@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    12db <answerTheQuestion+0x18b>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11fc <answerTheQuestion+0xac>
mov    -0x14(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<answerTheQuestion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%ebx
mov    %esi,%r14d
mov    %edi,%r15d
cmp    $0x5,%edx
jl     1184 <answerTheQuestion+0x24>
mov    $0x4,%edi
call   1050 <getRandomNum@plt>
mov    %eax,%ebx
add    $0xffffffff,%ebx
cmp    $0x3,%ebx
ja     11a2 <answerTheQuestion+0x42>
lea    0xe6d(%rip),%rax
movslq (%rax,%rbx,4),%rcx
add    %rax,%rcx
jmp    *%rcx
lea    (%r14,%r15,1),%r13d
jmp    11cb <answerTheQuestion+0x6b>
lea    0xec2(%rip),%rdi
call   1040 <puts@plt>
jmp    11cb <answerTheQuestion+0x6b>
mov    %r15d,%r13d
sub    %r14d,%r13d
jmp    11cb <answerTheQuestion+0x6b>
mov    %r14d,%r13d
imul   %r15d,%r13d
jmp    11cb <answerTheQuestion+0x6b>
mov    %r15d,%eax
cltd
idiv   %r14d
mov    %eax,%r13d
lea    0xe3e(%rip),%r12
xor    %ebp,%ebp
cmp    $0x3,%ebx
ja     125b <answerTheQuestion+0xfb>
nopl   (%rax)
movslq (%r12,%rbx,4),%rax
add    %r12,%rax
jmp    *%rax
lea    0xe30(%rip),%rdi
jmp    1227 <answerTheQuestion+0xc7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    0xe2b(%rip),%rdi
jmp    1227 <answerTheQuestion+0xc7>
nopl   0x0(%rax)
lea    0xe2d(%rip),%rdi
jmp    1227 <answerTheQuestion+0xc7>
nopl   0x0(%rax)
lea    0xe2f(%rip),%rdi
mov    %r15d,%esi
mov    %r14d,%edx
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe2d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1070 <scanf@plt>
cmp    %r13d,0x4(%rsp)
je     1269 <answerTheQuestion+0x109>
xor    %eax,%eax
call   1030 <wrongAnswer@plt>
add    $0x1,%ebp
cmp    $0x3,%ebx
jbe    11e0 <answerTheQuestion+0x80>
lea    0xe09(%rip),%rdi
call   1040 <puts@plt>
jmp    1234 <answerTheQuestion+0xd4>
xor    %eax,%eax
call   1080 <correctAnswer@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Something went wrong\0A\00"
@.str.1 = [18 x i8] c"What is %d + %d? \00"
@.str.2 = [18 x i8] c"What is %d - %d? \00"
@.str.3 = [18 x i8] c"What is %d x %d? \00"
@.str.4 = [18 x i8] c"What is %d / %d? \00"
@.str.5 = [3 x i8] c"%d\00"
define i32 @answerTheQuestion(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %8
store i32 0, i32* %9
%11 = load i32, i32* %6
%12 = icmp sgt i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %3
%14 = call i32 @getRandomNum(i32 4)
store i32 %14, i32* %6
br label %15
15: ; preds = %13, %3
%16 = load i32, i32* %6
switch i32 %16, label %33 [
i32 1, label %17
i32 2, label %21
i32 3, label %25
i32 4, label %29
]
17: ; preds = %15
%18 = load i32, i32* %4
%19 = load i32, i32* %5
%20 = add nsw i32 %18, %19
store i32 %20, i32* %10
br label %35
21: ; preds = %15
%22 = load i32, i32* %4
%23 = load i32, i32* %5
%24 = sub nsw i32 %22, %23
store i32 %24, i32* %10
br label %35
25: ; preds = %15
%26 = load i32, i32* %4
%27 = load i32, i32* %5
%28 = mul nsw i32 %26, %27
store i32 %28, i32* %10
br label %35
29: ; preds = %15
%30 = load i32, i32* %4
%31 = load i32, i32* %5
%32 = sdiv i32 %30, %31
store i32 %32, i32* %10
br label %35
33: ; preds = %15
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %35
35: ; preds = %33, %29, %25, %21, %17
br label %36
36: ; preds = %68, %35
%37 = load i32, i32* %6
switch i32 %37, label %54 [
i32 1, label %38
i32 2, label %42
i32 3, label %46
i32 4, label %50
]
38: ; preds = %36
%39 = load i32, i32* %4
%40 = load i32, i32* %5
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %39, i32 %40)
br label %56
42: ; preds = %36
%43 = load i32, i32* %4
%44 = load i32, i32* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %43, i32 %44)
br label %56
46: ; preds = %36
%47 = load i32, i32* %4
%48 = load i32, i32* %5
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %47, i32 %48)
br label %56
50: ; preds = %36
%51 = load i32, i32* %4
%52 = load i32, i32* %5
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %51, i32 %52)
br label %56
54: ; preds = %36
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
br label %56
56: ; preds = %54, %50, %46, %42, %38
%57 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %7)
%58 = load i32, i32* %7
%59 = load i32, i32* %10
%60 = icmp eq i32 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %56
store i32 1, i32* %9
%62 = call i32 (...) @correctAnswer()
br label %67
63: ; preds = %56
%64 = call i32 (...) @wrongAnswer()
%65 = load i32, i32* %8
%66 = add nsw i32 %65, 1
store i32 %66, i32* %8
br label %67
67: ; preds = %63, %61
br label %68
68: ; preds = %67
%69 = load i32, i32* %9
%70 = icmp ne i32 %69, 0
%71 = xor i1 %70, true
br i1 %71, label %36, label %72
72: ; preds = %68
%73 = load i32, i32* %8
ret i32 %73
}

LLVM IR (-O2):
@.str.1 = [18 x i8] c"What is %d + %d? \00"
@.str.2 = [18 x i8] c"What is %d - %d? \00"
@.str.3 = [18 x i8] c"What is %d x %d? \00"
@.str.4 = [18 x i8] c"What is %d / %d? \00"
@.str.5 = [3 x i8] c"%d\00"
@str.6 = [21 x i8] c"Something went wrong\00"
define i32 @answerTheQuestion(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = bitcast i32* %4 to i8*
%6 = icmp sgt i32 %2, 4
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @getRandomNum(i32 4)
br label %9
9: ; preds = %7, %3
%10 = phi i32 [ %8, %7 ], [ %2, %3 ]
switch i32 %10, label %19 [
i32 1, label %11
i32 2, label %13
i32 3, label %15
i32 4, label %17
]
11: ; preds = %9
%12 = add nsw i32 %1, %0
br label %21
13: ; preds = %9
%14 = sub nsw i32 %0, %1
br label %21
15: ; preds = %9
%16 = mul nsw i32 %1, %0
br label %21
17: ; preds = %9
%18 = sdiv i32 %0, %1
br label %21
19: ; preds = %9
%20 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
br label %21
21: ; preds = %19, %17, %15, %13, %11
%22 = phi i32 [ undef, %19 ], [ %18, %17 ], [ %16, %15 ], [ %14, %13 ], [ %12, %11 ]
br label %23
23: ; preds = %39, %21
%24 = phi i32 [ 0, %21 ], [ %41, %39 ]
switch i32 %10, label %33 [
i32 1, label %25
i32 2, label %27
i32 3, label %29
i32 4, label %31
]
25: ; preds = %23
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i32 %0, i32 %1)
br label %35
27: ; preds = %23
%28 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i32 %0, i32 %1)
br label %35
29: ; preds = %23
%30 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.3, i64 0, i64 0), i32 %0, i32 %1)
br label %35
31: ; preds = %23
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 %0, i32 %1)
br label %35
33: ; preds = %23
%34 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0))
br label %35
35: ; preds = %33, %31, %29, %27, %25
%36 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0), i32* %4)
%37 = load i32, i32* %4
%38 = icmp eq i32 %37, %22
br i1 %38, label %42, label %39
39: ; preds = %35
%40 = call i32 (...) @wrongAnswer()
%41 = add nuw nsw i32 %24, 1
br label %23
42: ; preds = %35
%43 = call i32 (...) @correctAnswer()
ret i32 %24
}