#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*/ EXIT_FAILURE;
int /*<<< orphan*/ clear_stdin();
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, ...);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncpy(char *, char *, int);
void get_input_filename(char *fileName) {
  int flag, choice, fname_len;
  char input[200];
  char specifier[200 + 1];
  printf("\nThe following model files are avaible:\n"
         "  1: buddha_n.ply\n"
         "  2: bunny_n.ply\n"
         "  3: cube_n.ply\n"
         "  4: heli_n.ply\n"
         "  5: swirl_n.ply\n"
         "  6: insert another filename manually\n");
  do {
    flag = 0;
    printf("\x1b["
           "1"
           "m"
           "Chose a file to edit, then press Return [1-6]: "
           "\x1b[0m");
    scanf("%d", &choice);
    clear_stdin();
    if (choice < 1 || choice > 6) {
      printf("\x1b["
             "1"
             ";3"
             "1"
             "m"
             "\nInvalid file number. Please retry.\n"
             "\x1b[0m");
      flag = 1;
    }
  } while (flag);
  switch (choice) {
  case 1:
    strncpy(fileName,
            "Model/"
            "buddha_n.ply",
            200);
    break;
  case 2:
    strncpy(fileName,
            "Model/"
            "bunny_n.ply",
            200);
    break;
  case 3:
    strncpy(fileName,
            "Model/"
            "cube_n.ply",
            200);
    break;
  case 4:
    strncpy(fileName,
            "Model/"
            "heli_n.ply",
            200);
    break;
  case 5:
    strncpy(fileName,
            "Model/"
            "swirl_n.ply",
            200);
    break;
  case 6:
    fname_len = 200 - strlen("Model/");
    printf("\x1b["
           "1"
           "m"
           "Insert filename (max. %d chars): "
           "\x1b[0m",
           fname_len);
    sprintf(specifier, "%%%ds", fname_len);
    scanf(specifier, &input);
    sprintf(fileName, "%s%s", "Model/", input);
    break;
  default:
    perror("Something went seriously wrong");
    exit(EXIT_FAILURE);
    break;
  }
}


x86 assembly (clang, -O0):
<get_input_filename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1c0,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xe82(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0xc(%rbp)
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xf3a(%rip),%rdi
lea    -0x10(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    $0x0,%al
call   1040 <clear_stdin@plt>
cmpl   $0x1,-0x10(%rbp)
jl     11df <get_input_filename+0x5f>
cmpl   $0x6,-0x10(%rbp)
jle    11f4 <get_input_filename+0x74>
lea    0xf10(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x1,-0xc(%rbp)
jmp    11f9 <get_input_filename+0x79>
cmpl   $0x0,-0xc(%rbp)
jne    119d <get_input_filename+0x1d>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x1b8(%rbp)
sub    $0x5,%eax
ja     132f <get_input_filename+0x1af>
mov    -0x1b8(%rbp),%rax
lea    0xdd7(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x8(%rbp),%rdi
lea    0xee9(%rip),%rsi
mov    $0xc8,%edx
call   1030 <strncpy@plt>
jmp    1349 <get_input_filename+0x1c9>
mov    -0x8(%rbp),%rdi
lea    0xee2(%rip),%rsi
mov    $0xc8,%edx
call   1030 <strncpy@plt>
jmp    1349 <get_input_filename+0x1c9>
mov    -0x8(%rbp),%rdi
lea    0xeda(%rip),%rsi
mov    $0xc8,%edx
call   1030 <strncpy@plt>
jmp    1349 <get_input_filename+0x1c9>
mov    -0x8(%rbp),%rdi
lea    0xed1(%rip),%rsi
mov    $0xc8,%edx
call   1030 <strncpy@plt>
jmp    1349 <get_input_filename+0x1c9>
mov    -0x8(%rbp),%rdi
lea    0xec8(%rip),%rsi
mov    $0xc8,%edx
call   1030 <strncpy@plt>
jmp    1349 <get_input_filename+0x1c9>
lea    0xec4(%rip),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
mov    $0xc8,%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%esi
lea    0xeb0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    -0x1b0(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xec2(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
lea    -0x1b0(%rbp),%rdi
lea    -0xe0(%rbp),%rsi
mov    $0x0,%al
call   1070 <scanf@plt>
mov    -0x8(%rbp),%rdi
lea    -0xe0(%rbp),%rcx
lea    0xe9a(%rip),%rsi
lea    0xe5c(%rip),%rdx
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    1349 <get_input_filename+0x1c9>
lea    0xe85(%rip),%rdi
call   1080 <perror@plt>
mov    0x2c9e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
add    $0x1c0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_input_filename>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1b0,%rsp
mov    %rdi,%r15
lea    0xf8d(%rip),%rdi
call   1050 <puts@plt>
lea    0xe62(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe8c(%rip),%rdi
lea    0xc(%rsp),%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
xor    %eax,%eax
call   1040 <clear_stdin@plt>
mov    0xc(%rsp),%eax
lea    -0x7(%rax),%ecx
cmp    $0xfffffff9,%ecx
ja     1234 <get_input_filename+0xa4>
lea    0xe69(%rip),%r14
lea    0xe27(%rip),%r12
lea    0xe58(%rip),%r13
lea    0xc(%rsp),%rbx
nopl   (%rax)
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
xor    %eax,%eax
call   1040 <clear_stdin@plt>
mov    0xc(%rsp),%eax
lea    -0x7(%rax),%ecx
cmp    $0xfffffffa,%ecx
jb     1200 <get_input_filename+0x70>
add    $0xffffffff,%eax
cmp    $0x5,%eax
ja     1305 <get_input_filename+0x175>
lea    0xdb9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe2c(%rip),%rsi
jmp    127b <get_input_filename+0xeb>
lea    0xe36(%rip),%rsi
jmp    127b <get_input_filename+0xeb>
lea    0xe3f(%rip),%rsi
jmp    127b <get_input_filename+0xeb>
lea    0xe47(%rip),%rsi
jmp    127b <get_input_filename+0xeb>
lea    0xe4f(%rip),%rsi
mov    %r15,%rdi
mov    $0xc8,%edx
call   1030 <strncpy@plt>
add    $0x1b0,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xe3c(%rip),%r14
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    $0xc8,%ebx
sub    %eax,%ebx
lea    0xe2d(%rip),%rdi
mov    %ebx,%esi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0xe47(%rip),%rsi
lea    0xe0(%rsp),%r12
mov    %r12,%rdi
mov    %ebx,%edx
xor    %eax,%eax
call   10a0 <sprintf@plt>
lea    0x10(%rsp),%rbx
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1080 <scanf@plt>
lea    0xe20(%rip),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rbx,%rcx
xor    %eax,%eax
call   10a0 <sprintf@plt>
jmp    1288 <get_input_filename+0xf8>
lea    0xe0c(%rip),%rdi
call   1090 <perror@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [163 x i8] c"\0AThe following model files are avaible:\0A 1: buddha_n.ply\0A 2: bunny_n.ply\0A 3: cube_n.ply\0A 4: heli_n.ply\0A 5: swirl_n.ply\0A 6: insert another filename manually\0A\00"
@.str.1 = [56 x i8] c"\1B[1mChose a file to edit, then press Return [1-6]: \1B[0m\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [48 x i8] c"\1B[1;31m\0AInvalid file number. Please retry.\0A\1B[0m\00"
@.str.4 = [19 x i8] c"Model/buddha_n.ply\00"
@.str.5 = [18 x i8] c"Model/bunny_n.ply\00"
@.str.6 = [17 x i8] c"Model/cube_n.ply\00"
@.str.7 = [17 x i8] c"Model/heli_n.ply\00"
@.str.8 = [18 x i8] c"Model/swirl_n.ply\00"
@.str.9 = [7 x i8] c"Model/\00"
@.str.10 = [42 x i8] c"\1B[1mInsert filename (max. %d chars): \1B[0m\00"
@.str.11 = [6 x i8] c"%%%ds\00"
@.str.12 = [5 x i8] c"%s%s\00"
@.str.13 = [31 x i8] c"Something went seriously wrong\00"
@EXIT_FAILURE = global i32 0
define void @get_input_filename(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [200 x i8]
%7 = alloca [201 x i8]
store i8* %0, i8** %2
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([163 x i8], [163 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %21, %1
store i32 0, i32* %3
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%11 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %4)
%12 = call i32 (...) @clear_stdin()
%13 = load i32, i32* %4
%14 = icmp slt i32 %13, 1
br i1 %14, label %18, label %15
15: ; preds = %9
%16 = load i32, i32* %4
%17 = icmp sgt i32 %16, 6
br i1 %17, label %18, label %20
18: ; preds = %15, %9
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %20
20: ; preds = %18, %15
br label %21
21: ; preds = %20
%22 = load i32, i32* %3
%23 = icmp ne i32 %22, 0
br i1 %23, label %9, label %24
24: ; preds = %21
%25 = load i32, i32* %4
switch i32 %25, label %54 [
i32 1, label %26
i32 2, label %29
i32 3, label %32
i32 4, label %35
i32 5, label %38
i32 6, label %41
]
26: ; preds = %24
%27 = load i8*, i8** %2
%28 = call i32 @strncpy(i8* %27, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 200)
br label %58
29: ; preds = %24
%30 = load i8*, i8** %2
%31 = call i32 @strncpy(i8* %30, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 200)
br label %58
32: ; preds = %24
%33 = load i8*, i8** %2
%34 = call i32 @strncpy(i8* %33, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 200)
br label %58
35: ; preds = %24
%36 = load i8*, i8** %2
%37 = call i32 @strncpy(i8* %36, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 200)
br label %58
38: ; preds = %24
%39 = load i8*, i8** %2
%40 = call i32 @strncpy(i8* %39, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 200)
br label %58
41: ; preds = %24
%42 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%43 = sub nsw i32 200, %42
store i32 %43, i32* %5
%44 = load i32, i32* %5
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i32 %44)
%46 = getelementptr inbounds [201 x i8], [201 x i8]* %7, i64 0, i64 0
%47 = load i32, i32* %5
%48 = call i32 (i8*, i8*, ...) @sprintf(i8* %46, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %47)
%49 = getelementptr inbounds [201 x i8], [201 x i8]* %7, i64 0, i64 0
%50 = call i32 (i8*, ...) @scanf(i8* %49, [200 x i8]* %6)
%51 = load i8*, i8** %2
%52 = getelementptr inbounds [200 x i8], [200 x i8]* %6, i64 0, i64 0
%53 = call i32 (i8*, i8*, ...) @sprintf(i8* %51, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %52)
br label %58
54: ; preds = %24
%55 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
%56 = load i32, i32* @EXIT_FAILURE
%57 = call i32 @exit(i32 %56)
unreachable
58: ; preds = %41, %38, %35, %32, %29, %26
ret void
}

LLVM IR (-O2):
@.str.1 = [56 x i8] c"\1B[1mChose a file to edit, then press Return [1-6]: \1B[0m\00"
@.str.2 = [3 x i8] c"%d\00"
@.str.3 = [48 x i8] c"\1B[1;31m\0AInvalid file number. Please retry.\0A\1B[0m\00"
@.str.4 = [19 x i8] c"Model/buddha_n.ply\00"
@.str.5 = [18 x i8] c"Model/bunny_n.ply\00"
@.str.6 = [17 x i8] c"Model/cube_n.ply\00"
@.str.7 = [17 x i8] c"Model/heli_n.ply\00"
@.str.8 = [18 x i8] c"Model/swirl_n.ply\00"
@.str.9 = [7 x i8] c"Model/\00"
@.str.10 = [42 x i8] c"\1B[1mInsert filename (max. %d chars): \1B[0m\00"
@.str.11 = [6 x i8] c"%%%ds\00"
@.str.12 = [5 x i8] c"%s%s\00"
@.str.13 = [31 x i8] c"Something went seriously wrong\00"
@EXIT_FAILURE = global i32 0
@str = [162 x i8] c"\0AThe following model files are avaible:\0A 1: buddha_n.ply\0A 2: bunny_n.ply\0A 3: cube_n.ply\0A 4: heli_n.ply\0A 5: swirl_n.ply\0A 6: insert another filename manually\00"
define void @get_input_filename(i8* %0) {
%2 = alloca i32
%3 = alloca [200 x i8]
%4 = alloca [201 x i8]
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [200 x i8], [200 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [201 x i8], [201 x i8]* %4, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([162 x i8], [162 x i8]* @str, i64 0, i64 0))
%9 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%10 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%11 = call i32 (...) @clear_stdin()
%12 = load i32, i32* %2
%13 = add i32 %12, -7
%14 = icmp ult i32 %13, -6
br i1 %14, label %15, label %23
15: ; preds = %1, %15
%16 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32* %2)
%19 = call i32 (...) @clear_stdin()
%20 = load i32, i32* %2
%21 = add i32 %20, -7
%22 = icmp ult i32 %21, -6
br i1 %22, label %15, label %23
23: ; preds = %15, %1
%24 = phi i32 [ %12, %1 ], [ %20, %15 ]
switch i32 %24, label %42 [
i32 1, label %25
i32 2, label %27
i32 3, label %29
i32 4, label %31
i32 5, label %33
i32 6, label %35
]
25: ; preds = %23
%26 = call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 200)
br label %46
27: ; preds = %23
%28 = call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.5, i64 0, i64 0), i32 200)
br label %46
29: ; preds = %23
%30 = call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0), i32 200)
br label %46
31: ; preds = %23
%32 = call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.7, i64 0, i64 0), i32 200)
br label %46
33: ; preds = %23
%34 = call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.8, i64 0, i64 0), i32 200)
br label %46
35: ; preds = %23
%36 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0))
%37 = sub nsw i32 200, %36
%38 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.10, i64 0, i64 0), i32 %37)
%39 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.11, i64 0, i64 0), i32 %37)
%40 = call i32 (i8*, ...) @scanf(i8* %7, [200 x i8]* %3)
%41 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.9, i64 0, i64 0), i8* %6)
br label %46
42: ; preds = %23
%43 = call i32 @perror(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.13, i64 0, i64 0))
%44 = load i32, i32* @EXIT_FAILURE
%45 = call i32 @exit(i32 %44)
unreachable
46: ; preds = %35, %33, %31, %29, %27, %25
ret void
}