#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*/ FILE;

/* Variables and functions */
int conv32_8(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int conv8_32(int /*<<< orphan*/ *, int /*<<< orphan*/ *, char);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, char *);
int main() {
  FILE *file;
  FILE *fileOut;
  char fileName[100];
  char convertionOption = '0';
  int state = 0;
  printf("\n\nEnter '1' for convertion from UTF-8 to UTF-32 or '2' for "
         "convertion from UTF-32 to UTF-8: ");
  scanf(" %c", &convertionOption);
  printf("\n\nDigite o nome do arquivo de entrada: ");
  scanf(" %s", fileName);
  file = fopen(fileName, "r");
  if (file == NULL) {
    printf("ERROR: File %s cannot be opened.", fileName);
    exit(1);
  }
  fileOut = fopen("ConvertedFile.txt", "w");
  if (fileOut == NULL) {
    printf("ERROR: File %s cannot be opened.", fileName);
    exit(1);
  }
  if (convertionOption == '1') {
    printf("\n\nChoose 'L' for Little Endian or 'B' for Big Endian: ");
    scanf(" %c", &convertionOption);
    state = conv8_32(file, fileOut, convertionOption);
  } else if (convertionOption == '2') {
    state = conv32_8(file, fileOut);
  } else {
    printf("\n\nERROR: invalid option.\n\n");
    fclose(file);
    fclose(fileOut);
    return 0;
  }
  fclose(file);
  fclose(fileOut);
  if (state == 0)
    printf("\n\nConvertedFile created successfully.\n\n");
  else if (state == -1)
    printf("\n\nConvertedFile created full of errors. Read report of errors "
           "above for more detail. \n\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
movb   $0x30,-0x81(%rbp)
movl   $0x0,-0x88(%rbp)
lea    0xe66(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb5(%rip),%rdi
lea    -0x81(%rbp),%rsi
call   1050 <scanf@plt>
lea    0xea6(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xebc(%rip),%rdi
call   1050 <scanf@plt>
lea    -0x80(%rbp),%rdi
lea    0xeb0(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    120d <main+0x9d>
lea    -0x80(%rbp),%rsi
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
lea    0xe9c(%rip),%rdi
lea    0xea7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    124b <main+0xdb>
lea    -0x80(%rbp),%rsi
lea    0xe55(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
movsbl -0x81(%rbp),%eax
cmp    $0x31,%eax
jne    129b <main+0x12b>
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xded(%rip),%rdi
lea    -0x81(%rbp),%rsi
call   1050 <scanf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
movsbl -0x81(%rbp),%edx
call   1060 <conv8_32@plt>
mov    %eax,-0x88(%rbp)
jmp    12f4 <main+0x184>
movsbl -0x81(%rbp),%eax
cmp    $0x32,%eax
jne    12c3 <main+0x153>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1080 <conv32_8@plt>
mov    %eax,-0x88(%rbp)
jmp    12ef <main+0x17f>
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    134d <main+0x1dd>
jmp    12f4 <main+0x184>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x88(%rbp)
jne    1326 <main+0x1b6>
lea    0xdfc(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1346 <main+0x1d6>
cmpl   $0xffffffff,-0x88(%rbp)
jne    1341 <main+0x1d1>
lea    0xe04(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1346 <main+0x1d6>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x80,%rsp
movb   $0x30,0xf(%rsp)
lea    0xe69(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xeb8(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <scanf@plt>
lea    0xeab(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xec5(%rip),%rdi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
call   1060 <scanf@plt>
lea    0xeb5(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     12af <main+0x12f>
mov    %rax,%r14
lea    0xebd(%rip),%rdi
lea    0xec8(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     12af <main+0x12f>
mov    %rax,%rbx
mov    0xf(%rsp),%al
cmp    $0x32,%al
je     1248 <main+0xc8>
cmp    $0x31,%al
jne    1277 <main+0xf7>
lea    0xea6(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe31(%rip),%rdi
lea    0xf(%rsp),%rsi
call   1060 <scanf@plt>
movsbl 0xf(%rsp),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <conv8_32@plt>
jmp    1253 <main+0xd3>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <conv32_8@plt>
mov    %eax,%ebp
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
cmp    $0xffffffff,%ebp
je     1295 <main+0x115>
test   %ebp,%ebp
jne    12a1 <main+0x121>
lea    0xef7(%rip),%rdi
jmp    129c <main+0x11c>
lea    0xe7d(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    12a1 <main+0x121>
lea    0xe79(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xdd9(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [93 x i8] c"\0A\0AEnter '1' for convertion from UTF-8 to UTF-32 or '2' for convertion from UTF-32 to UTF-8: \00"
@.str.1 = [4 x i8] c" %c\00"
@.str.2 = [40 x i8] c"\0A\0ADigite o nome do arquivo de entrada: \00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [33 x i8] c"ERROR: File %s cannot be opened.\00"
@.str.6 = [18 x i8] c"ConvertedFile.txt\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [55 x i8] c"\0A\0AChoose 'L' for Little Endian or 'B' for Big Endian: \00"
@.str.9 = [27 x i8] c"\0A\0AERROR: invalid option.\0A\0A\00"
@.str.10 = [40 x i8] c"\0A\0AConvertedFile created successfully.\0A\0A\00"
@.str.11 = [88 x i8] c"\0A\0AConvertedFile created full of errors. Read report of errors above for more detail. \0A\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [100 x i8]
%5 = alloca i8
%6 = alloca i32
store i32 0, i32* %1
store i8 48, i8* %5
store i32 0, i32* %6
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%10 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%11 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %20
16: ; preds = %0
%17 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 1)
unreachable
20: ; preds = %0
%21 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
store i32* %21, i32** %3
%22 = load i32*, i32** %3
%23 = icmp eq i32* %22, null
br i1 %23, label %24, label %28
24: ; preds = %20
%25 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %25)
%27 = call i32 @exit(i32 1)
unreachable
28: ; preds = %20
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = icmp eq i32 %30, 49
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0))
%34 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %5)
%35 = load i32*, i32** %2
%36 = load i32*, i32** %3
%37 = load i8, i8* %5
%38 = call i32 @conv8_32(i32* %35, i32* %36, i8 signext %37)
store i32 %38, i32* %6
br label %54
39: ; preds = %28
%40 = load i8, i8* %5
%41 = sext i8 %40 to i32
%42 = icmp eq i32 %41, 50
br i1 %42, label %43, label %47
43: ; preds = %39
%44 = load i32*, i32** %2
%45 = load i32*, i32** %3
%46 = call i32 @conv32_8(i32* %44, i32* %45)
store i32 %46, i32* %6
br label %53
47: ; preds = %39
%48 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.9, i64 0, i64 0))
%49 = load i32*, i32** %2
%50 = call i32 @fclose(i32* %49)
%51 = load i32*, i32** %3
%52 = call i32 @fclose(i32* %51)
store i32 0, i32* %1
br label %70
53: ; preds = %43
br label %54
54: ; preds = %53, %32
%55 = load i32*, i32** %2
%56 = call i32 @fclose(i32* %55)
%57 = load i32*, i32** %3
%58 = call i32 @fclose(i32* %57)
%59 = load i32, i32* %6
%60 = icmp eq i32 %59, 0
br i1 %60, label %61, label %63
61: ; preds = %54
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.10, i64 0, i64 0))
br label %69
63: ; preds = %54
%64 = load i32, i32* %6
%65 = icmp eq i32 %64, -1
br i1 %65, label %66, label %68
66: ; preds = %63
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([88 x i8], [88 x i8]* @.str.11, i64 0, i64 0))
br label %68
68: ; preds = %66, %63
br label %69
69: ; preds = %68, %61
store i32 0, i32* %1
br label %70
70: ; preds = %69, %47
%71 = load i32, i32* %1
ret i32 %71
}

LLVM IR (-O2):
@.str = [93 x i8] c"\0A\0AEnter '1' for convertion from UTF-8 to UTF-32 or '2' for convertion from UTF-32 to UTF-8: \00"
@.str.1 = [4 x i8] c" %c\00"
@.str.2 = [40 x i8] c"\0A\0ADigite o nome do arquivo de entrada: \00"
@.str.3 = [4 x i8] c" %s\00"
@.str.4 = [2 x i8] c"r\00"
@.str.5 = [33 x i8] c"ERROR: File %s cannot be opened.\00"
@.str.6 = [18 x i8] c"ConvertedFile.txt\00"
@.str.7 = [2 x i8] c"w\00"
@.str.8 = [55 x i8] c"\0A\0AChoose 'L' for Little Endian or 'B' for Big Endian: \00"
@str = [26 x i8] c"\0A\0AERROR: invalid option.\0A\00"
@str.12 = [87 x i8] c"\0A\0AConvertedFile created full of errors. Read report of errors above for more detail. \0A\00"
@str.13 = [39 x i8] c"\0A\0AConvertedFile created successfully.\0A\00"
define i32 @main() {
%1 = alloca [100 x i8]
%2 = alloca i8
%3 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
store i8 48, i8* %2
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([93 x i8], [93 x i8]* @.str, i64 0, i64 0))
%5 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%6 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%7 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %3)
%8 = call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %13
10: ; preds = %0
%11 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%12 = call i32 @exit(i32 1)
unreachable
13: ; preds = %0
%14 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i64 0, i64 0))
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([33 x i8], [33 x i8]* @.str.5, i64 0, i64 0), i8* %3)
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %13
%20 = load i8, i8* %2
switch i8 %20, label %28 [
i8 49, label %21
i8 50, label %26
]
21: ; preds = %19
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([55 x i8], [55 x i8]* @.str.8, i64 0, i64 0))
%23 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%24 = load i8, i8* %2
%25 = call i32 @conv8_32(i32* %8, i32* %14, i8 signext %24)
br label %32
26: ; preds = %19
%27 = call i32 @conv32_8(i32* %8, i32* %14)
br label %32
28: ; preds = %19
%29 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str, i64 0, i64 0))
%30 = call i32 @fclose(i32* %8)
%31 = call i32 @fclose(i32* %14)
br label %40
32: ; preds = %26, %21
%33 = phi i32 [ %25, %21 ], [ %27, %26 ]
%34 = call i32 @fclose(i32* %8)
%35 = call i32 @fclose(i32* %14)
switch i32 %33, label %40 [
i32 0, label %36
i32 -1, label %38
]
36: ; preds = %32
%37 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.13, i64 0, i64 0))
br label %40
38: ; preds = %32
%39 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([87 x i8], [87 x i8]* @str.12, i64 0, i64 0))
br label %40
40: ; preds = %36, %38, %32, %28
ret i32 0
}