#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 */
typedef int /*<<< orphan*/ buff;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ stdin;
int strtol(char *, int /*<<< orphan*/ *, int);
int set_diff(void) {
  char buff[5];
  do {
    printf("Choose your game difficulty:\n");
    printf("(1) Easy     (2) Medium     (3) Hard     (4) Extreme\n");
    printf("Choose: ");
    if (fgets(buff, sizeof(buff), stdin) != NULL) {
      switch (strtol(buff, NULL, 10)) {
      case 1:
        return 5;
      case 2:
        return 6;
      case 3:
        return 7;
      case 4:
        return 8;
      default:
        printf("Invalid choice (no match), try again\n");
      }
    }
  } while (1);
}


x86 assembly (clang, -O0):
<set_diff>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
call   1030 <printf@plt>
lea    0xee3(%rip),%rdi
call   1030 <printf@plt>
lea    0xf0d(%rip),%rdi
call   1030 <printf@plt>
lea    -0x9(%rbp),%rdi
mov    0x2e81(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11f6 <set_diff+0xc6>
xor    %eax,%eax
mov    %eax,%esi
lea    -0x9(%rbp),%rdi
mov    $0xa,%edx
call   1050 <strtol@plt>
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x18(%rbp)
sub    $0x3,%eax
ja     11e5 <set_diff+0xb5>
mov    -0x18(%rbp),%rax
lea    0xe54(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
movl   $0x5,-0x4(%rbp)
jmp    120a <set_diff+0xda>
movl   $0x6,-0x4(%rbp)
jmp    120a <set_diff+0xda>
movl   $0x7,-0x4(%rbp)
jmp    120a <set_diff+0xda>
movl   $0x8,-0x4(%rbp)
jmp    120a <set_diff+0xda>
lea    0xe81(%rip),%rdi
call   1030 <printf@plt>
jmp    11f6 <set_diff+0xc6>
jmp    11fb <set_diff+0xcb>
mov    $0x1,%al
test   $0x1,%al
jne    1138 <set_diff+0x8>
jmp    120a <set_diff+0xda>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_diff>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xeb7(%rip),%r14
lea    0xecd(%rip),%r15
lea    0xea0(%rip),%r12
mov    0x2e81(%rip),%rbp
lea    0x3(%rsp),%rbx
lea    0xee8(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
call   1040 <printf@plt>
mov    0x0(%rbp),%edx
mov    %rbx,%rdi
mov    $0x5,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     1180 <set_diff+0x40>
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
lea    -0x1(%rax),%ecx
cmp    $0x4,%ecx
jb     11ce <set_diff+0x8e>
mov    %r13,%rdi
call   1030 <puts@plt>
jmp    1180 <set_diff+0x40>
add    $0x4,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"Choose your game difficulty:\0A\00"
@.str.1 = [54 x i8] c"(1) Easy (2) Medium (3) Hard (4) Extreme\0A\00"
@.str.2 = [9 x i8] c"Choose: \00"
@stdin = global i32 0
@.str.3 = [38 x i8] c"Invalid choice (no match), try again\0A\00"
define i32 @set_diff() {
%1 = alloca i32
%2 = alloca [5 x i8]
br label %3
3: ; preds = %22, %0
%4 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @printf(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0))
%6 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%7 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%8 = load i32, i32* @stdin
%9 = call i32* @fgets(i8* %7, i32 5, i32 %8)
%10 = icmp ne i32* %9, null
br i1 %10, label %11, label %21
11: ; preds = %3
%12 = getelementptr inbounds [5 x i8], [5 x i8]* %2, i64 0, i64 0
%13 = call i32 @strtol(i8* %12, i32* null, i32 10)
switch i32 %13, label %18 [
i32 1, label %14
i32 2, label %15
i32 3, label %16
i32 4, label %17
]
14: ; preds = %11
store i32 5, i32* %1
br label %23
15: ; preds = %11
store i32 6, i32* %1
br label %23
16: ; preds = %11
store i32 7, i32* %1
br label %23
17: ; preds = %11
store i32 8, i32* %1
br label %23
18: ; preds = %11
%19 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.3, i64 0, i64 0))
br label %20
20: ; preds = %18
br label %21
21: ; preds = %20, %3
br label %22
22: ; preds = %21
br i1 true, label %3, label %23
23: ; preds = %14, %15, %16, %17, %22
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str.2 = [9 x i8] c"Choose: \00"
@stdin = global i32 0
@str = [29 x i8] c"Choose your game difficulty:\00"
@str.4 = [53 x i8] c"(1) Easy (2) Medium (3) Hard (4) Extreme\00"
@str.5 = [37 x i8] c"Invalid choice (no match), try again\00"
define i32 @set_diff() {
%1 = alloca [5 x i8]
%2 = getelementptr inbounds [5 x i8], [5 x i8]* %1, i64 0, i64 0
br label %3
3: ; preds = %10, %0
%4 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([29 x i8], [29 x i8]* @str, i64 0, i64 0))
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([53 x i8], [53 x i8]* @str.4, i64 0, i64 0))
%6 = call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%7 = load i32, i32* @stdin
%8 = call i32* @fgets(i8* %2, i32 5, i32 %7)
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %11
10: ; preds = %3, %15
br label %3
11: ; preds = %3
%12 = call i32 @strtol(i8* nocapture %2, i32* null, i32 10)
%13 = add i32 %12, -1
%14 = icmp ult i32 %13, 4
br i1 %14, label %17, label %15
15: ; preds = %11
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.5, i64 0, i64 0))
br label %10
17: ; preds = %11
%18 = add i32 %12, 4
ret i32 %18
}