#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 */
scalar_t__ createFile(char *, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ generateDNA(char *, int);
int /*<<< orphan*/ isDNAFileExtension(char *);
scalar_t__ isValidFilePath(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ printlnString(char *);
scalar_t__ scanInt(int *);
char *scanString();
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
scalar_t__ writeOnFile(char *, char *, int);
int main2() {
  int lenght;
  int rightValue = 0;
  while (!rightValue) {
    printf("Specify the length of the DNA sequence: ");
    rightValue = scanInt(&lenght) && lenght >= 7 && lenght <= 1000000;
    if (!rightValue)
      printlnString("Error: try again.");
  }
  rightValue = 0;
  char *filename = 0;
  char *dna = malloc(sizeof(char) * (lenght + 1));
  while (!rightValue) {
    printf("Type the name of the file: ");
    filename = scanString();
    if (!isDNAFileExtension(filename)) {
      char *newfilename;
      newfilename = malloc(sizeof(char) * (strlen(filename) + 5));
      newfilename[0] = '\0';
      strcat(newfilename, filename);
      strcat(newfilename, ".dna");
      free(filename);
      filename = newfilename;
    }
    if (isValidFilePath(filename) && createFile(filename, 1)) {
      generateDNA(dna, lenght);
      dna[lenght] = '\0';
      if (writeOnFile(filename, dna, 1))
        rightValue = 1;
    } else {
      printlnString("Error. Try again.");
    }
    free(filename);
  }
  printf("File %s has been generated successfully with the following content: "
         "\n\n",
         filename);
  printf("%s\n", dna);
  printf("\n");
  free(dna);
  return 0;
}


x86 assembly (clang, -O0):
<main2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11f5 <main2+0x25>
jmp    1260 <main2+0x90>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x4(%rbp),%rdi
call   1080 <scanInt@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    $0x0,%rcx
mov    %al,-0x21(%rbp)
je     123a <main2+0x6a>
xor    %eax,%eax
cmpl   $0x7,-0x4(%rbp)
mov    %al,-0x21(%rbp)
jl     123a <main2+0x6a>
cmpl   $0xf4240,-0x4(%rbp)
setle  %al
mov    %al,-0x21(%rbp)
mov    -0x21(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jne    125b <main2+0x8b>
lea    0xdd3(%rip),%rdi
call   1090 <printlnString@plt>
jmp    11df <main2+0xf>
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x4(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpl   $0x0,-0x8(%rbp)
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    129c <main2+0xcc>
jmp    139e <main2+0x1ce>
lea    0xd98(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   10e0 <scanString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   10f0 <isDNAFileExtension@plt>
cmp    $0x0,%eax
jne    1319 <main2+0x149>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x5,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   10a0 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   10d0 <strcat@plt>
mov    -0x20(%rbp),%rdi
lea    0xd54(%rip),%rsi
call   10d0 <strcat@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <isValidFilePath@plt>
cmp    $0x0,%rax
je     1384 <main2+0x1b4>
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
call   1070 <createFile@plt>
cmp    $0x0,%rax
je     1384 <main2+0x1b4>
mov    -0x18(%rbp),%rdi
mov    -0x4(%rbp),%esi
call   10b0 <generateDNA@plt>
mov    -0x18(%rbp),%rax
movslq -0x4(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   10c0 <writeOnFile@plt>
cmp    $0x0,%rax
je     137f <main2+0x1af>
movl   $0x1,-0x8(%rbp)
jmp    1390 <main2+0x1c0>
lea    0xcd1(%rip),%rdi
call   1090 <printlnString@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
jmp    1286 <main2+0xb6>
mov    -0x10(%rbp),%rsi
lea    0xcc5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rsi
lea    0xcfa(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xcea(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
lea    0x4(%rsp),%rdi
call   10a0 <scanInt@plt>
test   %rax,%rax
je     1228 <main2+0x38>
mov    0x4(%rsp),%eax
cmp    $0x7,%eax
jl     1228 <main2+0x38>
cmp    $0xf4241,%eax
jl     126f <main2+0x7f>
lea    0xdfa(%rip),%r14
lea    0xdca(%rip),%r15
lea    0x4(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   10b0 <printlnString@plt>
mov    %r15,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   10a0 <scanInt@plt>
test   %rax,%rax
je     1240 <main2+0x50>
mov    0x4(%rsp),%eax
cmp    $0x7,%eax
jl     1240 <main2+0x50>
cmp    $0xf4240,%eax
jg     1240 <main2+0x50>
mov    0x4(%rsp),%edi
add    $0x1,%edi
call   10c0 <malloc@plt>
mov    %rax,%r13
lea    0xdb6(%rip),%r14
lea    0xdcb(%rip),%r15
lea    0xdc9(%rip),%r12
jmp    12ba <main2+0xca>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r12,%rdi
call   10b0 <printlnString@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
test   %ebp,%ebp
jne    1369 <main2+0x179>
mov    %r14,%rdi
xor    %eax,%eax
call   1070 <printf@plt>
xor    %eax,%eax
call   1100 <scanString@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1110 <isDNAFileExtension@plt>
test   %eax,%eax
jne    1311 <main2+0x121>
mov    %rbx,%rdi
call   1060 <strlen@plt>
lea    0x5(%rax),%edi
call   10c0 <malloc@plt>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %rax,%rdi
mov    %rbx,%rsi
call   10f0 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
call   10f0 <strcat@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rbx
mov    %rbx,%rdi
call   1080 <isValidFilePath@plt>
test   %rax,%rax
je     12a0 <main2+0xb0>
mov    %rbx,%rdi
mov    $0x1,%esi
call   1090 <createFile@plt>
test   %rax,%rax
je     12a0 <main2+0xb0>
mov    0x4(%rsp),%esi
mov    %r13,%rdi
call   10d0 <generateDNA@plt>
movslq 0x4(%rsp),%rax
movb   $0x0,0x0(%r13,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
mov    $0x1,%edx
call   10e0 <writeOnFile@plt>
xor    %ebp,%ebp
test   %rax,%rax
setne  %bpl
jmp    12aa <main2+0xba>
lea    0xcfe(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %r13,%rdi
call   1050 <puts@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
mov    %r13,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"Specify the length of the DNA sequence: \00"
@.str.1 = [18 x i8] c"Error: try again.\00"
@.str.2 = [28 x i8] c"Type the name of the file: \00"
@.str.3 = [5 x i8] c".dna\00"
@.str.4 = [18 x i8] c"Error. Try again.\00"
@.str.5 = [71 x i8] c"File %s has been generated successfully with the following content: \0A\0A\00"
@.str.6 = [4 x i8] c"%s\0A\00"
@.str.7 = [2 x i8] c"\0A\00"
define i32 @main2() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i32 0, i32* %2
br label %6
6: ; preds = %27, %0
%7 = load i32, i32* %2
%8 = icmp ne i32 %7, 0
%9 = xor i1 %8, true
br i1 %9, label %10, label %28
10: ; preds = %6
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%12 = call i64 @scanInt(i32* %1)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = load i32, i32* %1
%16 = icmp sge i32 %15, 7
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %1
%19 = icmp sle i32 %18, 1000000
br label %20
20: ; preds = %17, %14, %10
%21 = phi i1 [ false, %14 ], [ false, %10 ], [ %19, %17 ]
%22 = zext i1 %21 to i32
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 @printlnString(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %27
27: ; preds = %25, %20
br label %6
28: ; preds = %6
store i32 0, i32* %2
store i8* null, i8** %3
%29 = load i32, i32* %1
%30 = add nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = mul i64 1, %31
%33 = trunc i64 %32 to i32
%34 = call i8* @malloc(i32 %33)
store i8* %34, i8** %4
br label %35
35: ; preds = %87, %28
%36 = load i32, i32* %2
%37 = icmp ne i32 %36, 0
%38 = xor i1 %37, true
br i1 %38, label %39, label %90
39: ; preds = %35
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%41 = call i8* (...) @scanString()
store i8* %41, i8** %3
%42 = load i8*, i8** %3
%43 = call i32 @isDNAFileExtension(i8* %42)
%44 = icmp ne i32 %43, 0
br i1 %44, label %63, label %45
45: ; preds = %39
%46 = load i8*, i8** %3
%47 = call i32 @strlen(i8* %46)
%48 = add nsw i32 %47, 5
%49 = sext i32 %48 to i64
%50 = mul i64 1, %49
%51 = trunc i64 %50 to i32
%52 = call i8* @malloc(i32 %51)
store i8* %52, i8** %5
%53 = load i8*, i8** %5
%54 = getelementptr inbounds i8, i8* %53, i64 0
store i8 0, i8* %54
%55 = load i8*, i8** %5
%56 = load i8*, i8** %3
%57 = call i32 @strcat(i8* %55, i8* %56)
%58 = load i8*, i8** %5
%59 = call i32 @strcat(i8* %58, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%60 = load i8*, i8** %3
%61 = call i32 @free(i8* %60)
%62 = load i8*, i8** %5
store i8* %62, i8** %3
br label %63
63: ; preds = %45, %39
%64 = load i8*, i8** %3
%65 = call i64 @isValidFilePath(i8* %64)
%66 = icmp ne i64 %65, 0
br i1 %66, label %67, label %85
67: ; preds = %63
%68 = load i8*, i8** %3
%69 = call i64 @createFile(i8* %68, i32 1)
%70 = icmp ne i64 %69, 0
br i1 %70, label %71, label %85
71: ; preds = %67
%72 = load i8*, i8** %4
%73 = load i32, i32* %1
%74 = call i32 @generateDNA(i8* %72, i32 %73)
%75 = load i8*, i8** %4
%76 = load i32, i32* %1
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds i8, i8* %75, i64 %77
store i8 0, i8* %78
%79 = load i8*, i8** %3
%80 = load i8*, i8** %4
%81 = call i64 @writeOnFile(i8* %79, i8* %80, i32 1)
%82 = icmp ne i64 %81, 0
br i1 %82, label %83, label %84
83: ; preds = %71
store i32 1, i32* %2
br label %84
84: ; preds = %83, %71
br label %87
85: ; preds = %67, %63
%86 = call i32 @printlnString(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %87
87: ; preds = %85, %84
%88 = load i8*, i8** %3
%89 = call i32 @free(i8* %88)
br label %35
90: ; preds = %35
%91 = load i8*, i8** %3
%92 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0), i8* %91)
%93 = load i8*, i8** %4
%94 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* %93)
%95 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%96 = load i8*, i8** %4
%97 = call i32 @free(i8* %96)
ret i32 0
}

LLVM IR (-O2):
@.str = [41 x i8] c"Specify the length of the DNA sequence: \00"
@.str.1 = [18 x i8] c"Error: try again.\00"
@.str.2 = [28 x i8] c"Type the name of the file: \00"
@.str.3 = [5 x i8] c".dna\00"
@.str.4 = [18 x i8] c"Error. Try again.\00"
@.str.5 = [71 x i8] c"File %s has been generated successfully with the following content: \0A\0A\00"
define i32 @main2() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%4 = call i64 @scanInt(i32* %1)
%5 = icmp ne i64 %4, 0
%6 = load i32, i32* %1
%7 = icmp sgt i32 %6, 6
%8 = select i1 %5, i1 %7, i1 false
%9 = icmp slt i32 %6, 1000001
%10 = select i1 %8, i1 %9, i1 false
br i1 %10, label %21, label %11
11: ; preds = %0, %11
%12 = call i32 @printlnString(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0))
%14 = call i64 @scanInt(i32* %1)
%15 = icmp ne i64 %14, 0
%16 = load i32, i32* %1
%17 = icmp sgt i32 %16, 6
%18 = select i1 %15, i1 %17, i1 false
%19 = icmp slt i32 %16, 1000001
%20 = select i1 %18, i1 %19, i1 false
br i1 %20, label %21, label %11
21: ; preds = %11, %0
%22 = load i32, i32* %1
%23 = add nsw i32 %22, 1
%24 = call i8* @malloc(i32 %23)
br label %25
25: ; preds = %21, %55
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0))
%27 = call i8* (...) @scanString()
%28 = call i32 @isDNAFileExtension(i8* %27)
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %37
30: ; preds = %25
%31 = call i32 @strlen(i8* %27)
%32 = add nsw i32 %31, 5
%33 = call i8* @malloc(i32 %32)
store i8 0, i8* %33
%34 = call i32 @strcat(i8* %33, i8* %27)
%35 = call i32 @strcat(i8* %33, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%36 = call i32 @free(i8* %27)
br label %37
37: ; preds = %30, %25
%38 = phi i8* [ %27, %25 ], [ %33, %30 ]
%39 = call i64 @isValidFilePath(i8* %38)
%40 = icmp eq i64 %39, 0
br i1 %40, label %53, label %41
41: ; preds = %37
%42 = call i64 @createFile(i8* %38, i32 1)
%43 = icmp eq i64 %42, 0
br i1 %43, label %53, label %44
44: ; preds = %41
%45 = load i32, i32* %1
%46 = call i32 @generateDNA(i8* %24, i32 %45)
%47 = load i32, i32* %1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %24, i64 %48
store i8 0, i8* %49
%50 = call i64 @writeOnFile(i8* %38, i8* %24, i32 1)
%51 = icmp ne i64 %50, 0
%52 = zext i1 %51 to i32
br label %55
53: ; preds = %41, %37
%54 = call i32 @printlnString(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0))
br label %55
55: ; preds = %44, %53
%56 = phi i32 [ 0, %53 ], [ %52, %44 ]
%57 = call i32 @free(i8* %38)
%58 = icmp eq i32 %56, 0
br i1 %58, label %25, label %59
59: ; preds = %55
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @.str.5, i64 0, i64 0), i8* %38)
%61 = call i32 @puts(i8* dereferenceable(1) %24)
%62 = call i32 @putchar(i32 10)
%63 = call i32 @free(i8* %24)
ret i32 0
}