#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
void askFileName(char *fileName) {
  char i;
  char input[30 + 10];
  do {
    i = 0;
    printf("[IMPORTANT!] in current directory the file to be created will "
           "overwrite existing files with same name\n");
    printf("Give filename for output file without the file type extension> ");
    scanf("%s", input);
    while (input[i] != '\0') {
      i++;
    }
    if (i > 30) {
      printf(
          "\nGiven filename is too long. Maximum length for filename is %d\n\n",
          30);
    }
  } while (i > 30);
  i = 0;
  while (input[i] != '\0') {
    fileName[i] = input[i];
    i++;
  }
  fileName[i] = '.';
  fileName[i + 1] = 'b';
  fileName[i + 2] = 'i';
  fileName[i + 3] = 'n';
  fileName[i + 4] = '\0';
}


x86 assembly (clang, -O0):
<askFileName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
movb   $0x0,-0x9(%rbp)
lea    0xec9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xf22(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xf50(%rip),%rdi
call   1040 <scanf@plt>
movsbq -0x9(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     117c <askFileName+0x5c>
mov    -0x9(%rbp),%al
add    $0x1,%al
mov    %al,-0x9(%rbp)
jmp    115c <askFileName+0x3c>
movsbl -0x9(%rbp),%eax
cmp    $0x1e,%eax
jle    119c <askFileName+0x7c>
lea    0xf1a(%rip),%rdi
mov    $0x1e,%esi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a1 <askFileName+0x81>
movsbl -0x9(%rbp),%eax
cmp    $0x1e,%eax
jg     112c <askFileName+0xc>
movb   $0x0,-0x9(%rbp)
movsbq -0x9(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     11e7 <askFileName+0xc7>
movsbq -0x9(%rbp),%rax
mov    -0x40(%rbp,%rax,1),%dl
mov    -0x8(%rbp),%rax
movsbq -0x9(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x9(%rbp),%al
add    $0x1,%al
mov    %al,-0x9(%rbp)
jmp    11b2 <askFileName+0x92>
mov    -0x8(%rbp),%rax
movsbq -0x9(%rbp),%rcx
movb   $0x2e,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movsbl -0x9(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x62,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movsbl -0x9(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x69,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movsbl -0x9(%rbp),%ecx
add    $0x3,%ecx
movslq %ecx,%rcx
movb   $0x6e,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movsbl -0x9(%rbp),%ecx
add    $0x4,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<askFileName>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0xf3c(%rip),%r15
lea    0xeb1(%rip),%r12
lea    0xeea(%rip),%r13
mov    %rsp,%rbx
lea    0xee3(%rip),%rbp
mov    %r15,%rdi
call   1030 <puts@plt>
mov    %r12,%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %rbx,%rsi
call   1050 <scanf@plt>
mov    $0xff,%al
nop
add    $0x1,%al
movsbq %al,%rcx
cmpb   $0x0,(%rsp,%rcx,1)
jne    1180 <askFileName+0x50>
cmp    $0x1e,%al
jle    11a1 <askFileName+0x71>
mov    %rbp,%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1160 <askFileName+0x30>
mov    (%rsp),%cl
test   %cl,%cl
je     11c7 <askFileName+0x97>
xor    %eax,%eax
nopw   0x0(%rax,%rax,1)
mov    %cl,(%r14,%rax,1)
add    $0x1,%eax
movsbq %al,%rax
movzbl (%rsp,%rax,1),%ecx
test   %cl,%cl
jne    11b0 <askFileName+0x80>
mov    %eax,%ecx
jmp    11cb <askFileName+0x9b>
xor    %ecx,%ecx
xor    %eax,%eax
movb   $0x2e,(%r14,%rax,1)
movslq %ecx,%rax
movl   $0x6e6962,0x1(%rax,%r14,1)
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [103 x i8] c"[IMPORTANT!] in current directory the file to be created will overwrite existing files with same name\0A\00"
@.str.1 = [64 x i8] c"Give filename for output file without the file type extension> \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [65 x i8] c"\0AGiven filename is too long. Maximum length for filename is %d\0A\0A\00"
define void @askFileName(i8* %0) {
%2 = alloca i8*
%3 = alloca i8
%4 = alloca [40 x i8]
store i8* %0, i8** %2
br label %5
5: ; preds = %27, %1
store i8 0, i8* %3
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([103 x i8], [103 x i8]* @.str, i64 0, i64 0))
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%8 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 0
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %10
10: ; preds = %17, %5
%11 = load i8, i8* %3
%12 = sext i8 %11 to i64
%13 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 %12
%14 = load i8, i8* %13
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %10
%18 = load i8, i8* %3
%19 = add i8 %18, 1
store i8 %19, i8* %3
br label %10
20: ; preds = %10
%21 = load i8, i8* %3
%22 = sext i8 %21 to i32
%23 = icmp sgt i32 %22, 30
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 30)
br label %26
26: ; preds = %24, %20
br label %27
27: ; preds = %26
%28 = load i8, i8* %3
%29 = sext i8 %28 to i32
%30 = icmp sgt i32 %29, 30
br i1 %30, label %5, label %31
31: ; preds = %27
store i8 0, i8* %3
br label %32
32: ; preds = %39, %31
%33 = load i8, i8* %3
%34 = sext i8 %33 to i64
%35 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 %34
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = icmp ne i32 %37, 0
br i1 %38, label %39, label %50
39: ; preds = %32
%40 = load i8, i8* %3
%41 = sext i8 %40 to i64
%42 = getelementptr inbounds [40 x i8], [40 x i8]* %4, i64 0, i64 %41
%43 = load i8, i8* %42
%44 = load i8*, i8** %2
%45 = load i8, i8* %3
%46 = sext i8 %45 to i64
%47 = getelementptr inbounds i8, i8* %44, i64 %46
store i8 %43, i8* %47
%48 = load i8, i8* %3
%49 = add i8 %48, 1
store i8 %49, i8* %3
br label %32
50: ; preds = %32
%51 = load i8*, i8** %2
%52 = load i8, i8* %3
%53 = sext i8 %52 to i64
%54 = getelementptr inbounds i8, i8* %51, i64 %53
store i8 46, i8* %54
%55 = load i8*, i8** %2
%56 = load i8, i8* %3
%57 = sext i8 %56 to i32
%58 = add nsw i32 %57, 1
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8, i8* %55, i64 %59
store i8 98, i8* %60
%61 = load i8*, i8** %2
%62 = load i8, i8* %3
%63 = sext i8 %62 to i32
%64 = add nsw i32 %63, 2
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds i8, i8* %61, i64 %65
store i8 105, i8* %66
%67 = load i8*, i8** %2
%68 = load i8, i8* %3
%69 = sext i8 %68 to i32
%70 = add nsw i32 %69, 3
%71 = sext i32 %70 to i64
%72 = getelementptr inbounds i8, i8* %67, i64 %71
store i8 110, i8* %72
%73 = load i8*, i8** %2
%74 = load i8, i8* %3
%75 = sext i8 %74 to i32
%76 = add nsw i32 %75, 4
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %73, i64 %77
store i8 0, i8* %78
ret void
}

LLVM IR (-O2):
@.str.1 = [64 x i8] c"Give filename for output file without the file type extension> \00"
@.str.2 = [3 x i8] c"%s\00"
@.str.3 = [65 x i8] c"\0AGiven filename is too long. Maximum length for filename is %d\0A\0A\00"
@str = [102 x i8] c"[IMPORTANT!] in current directory the file to be created will overwrite existing files with same name\00"
define void @askFileName(i8* nocapture writeonly %0) {
%2 = alloca [40 x i8]
%3 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %20, %1
%5 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([102 x i8], [102 x i8]* @str, i64 0, i64 0))
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([64 x i8], [64 x i8]* @.str.1, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* %3)
br label %8
8: ; preds = %8, %4
%9 = phi i8 [ 0, %4 ], [ %14, %8 ]
%10 = sext i8 %9 to i64
%11 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 %10
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 0
%14 = add i8 %9, 1
br i1 %13, label %15, label %8
15: ; preds = %8
%16 = icmp sgt i8 %9, 30
br i1 %16, label %20, label %17
17: ; preds = %15
%18 = load i8, i8* %3
%19 = icmp eq i8 %18, 0
br i1 %19, label %34, label %22
20: ; preds = %15
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([65 x i8], [65 x i8]* @.str.3, i64 0, i64 0), i32 30)
br label %4
22: ; preds = %17, %22
%23 = phi i8 [ %30, %22 ], [ %18, %17 ]
%24 = phi i64 [ %28, %22 ], [ 0, %17 ]
%25 = trunc i64 %24 to i8
%26 = getelementptr inbounds i8, i8* %0, i64 %24
store i8 %23, i8* %26
%27 = add i8 %25, 1
%28 = sext i8 %27 to i64
%29 = getelementptr inbounds [40 x i8], [40 x i8]* %2, i64 0, i64 %28
%30 = load i8, i8* %29
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %22
32: ; preds = %22
%33 = sext i8 %27 to i32
br label %34
34: ; preds = %32, %17
%35 = phi i32 [ 0, %17 ], [ %33, %32 ]
%36 = phi i64 [ 0, %17 ], [ %28, %32 ]
%37 = getelementptr inbounds i8, i8* %0, i64 %36
store i8 46, i8* %37
%38 = add nsw i32 %35, 1
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %0, i64 %39
store i8 98, i8* %40
%41 = add nsw i32 %35, 2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %0, i64 %42
store i8 105, i8* %43
%44 = add nsw i32 %35, 3
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %0, i64 %45
store i8 110, i8* %46
%47 = add nsw i32 %35, 4
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %0, i64 %48
store i8 0, i8* %49
ret void
}