#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 EOF;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ stderr;
int main() {
  FILE *input_file = fopen("alphabet.txt", "r");
  if (input_file == NULL) {
    fprintf(stderr, "Can't open input file!\n");
    exit(1);
  }
  char *alphabet = malloc(26 * sizeof(char));
  int i = 0;
  int c;
  while ((c = fgetc(input_file)) != EOF) {
    alphabet[i] = (char)c;
    i++;
  }
  fclose(input_file);
  FILE *output_file = fopen("reverse_alphabet.txt", "w");
  if (output_file == NULL) {
    fprintf(stderr, "Can't open output file!\n");
    exit(1);
  }
  for (int j = 25; j >= 0; j--) {
    fputc(alphabet[j], output_file);
  }
  free(alphabet);
  fclose(output_file);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe8c(%rip),%rdi
lea    0xe63(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11d0 <main+0x50>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
lea    0xe41(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    $0x1a,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x20(%rbp)
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
je     121e <main+0x9e>
mov    -0x20(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11e5 <main+0x65>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xdec(%rip),%rdi
lea    0xdfa(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1268 <main+0xe8>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
lea    0xdd8(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
movl   $0x19,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jl     129e <main+0x11e>
mov    -0x18(%rbp),%rax
movslq -0x2c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    -0x28(%rbp),%rsi
movsbl %al,%edi
call   1060 <fputc@plt>
mov    -0x2c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x2c(%rbp)
jmp    126f <main+0xef>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe93(%rip),%rdi
lea    0xe6a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1379 <main+0x1f9>
mov    %rax,%r12
mov    $0x1a,%edi
call   1080 <malloc@plt>
mov    %rax,%r14
mov    %r12,%rdi
call   1050 <fgetc@plt>
mov    0x2e25(%rip),%r15
cmp    (%r15),%eax
je     11e3 <main+0x63>
mov    %r14,%rbx
nopl   0x0(%rax,%rax,1)
mov    %al,(%rbx)
mov    %r12,%rdi
call   1050 <fgetc@plt>
add    $0x1,%rbx
cmp    (%r15),%eax
jne    11d0 <main+0x50>
mov    %r12,%rdi
call   1040 <fclose@plt>
lea    0xe28(%rip),%rdi
lea    0xe36(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     138b <main+0x20b>
mov    %rax,%rbx
movsbl 0x19(%r14),%edi
mov    %rax,%rsi
call   1060 <fputc@plt>
movsbl 0x18(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x17(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x16(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x15(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x14(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x13(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x12(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x11(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x10(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0xf(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0xe(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0xd(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0xc(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0xb(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0xa(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x9(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x8(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x7(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x6(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x5(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x4(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x3(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x2(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl 0x1(%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
movsbl (%r14),%edi
mov    %rbx,%rsi
call   1060 <fputc@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
lea    0xc79(%rip),%rsi
jmp    139b <main+0x21b>
mov    0x2c46(%rip),%rax
mov    (%rax),%edi
lea    0xc96(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"alphabet.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Can't open input file!\0A\00"
@EOF = global i32 0
@.str.3 = [21 x i8] c"reverse_alphabet.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"Can't open output file!\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
store i32 0, i32* %1
%8 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %15
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %0
%16 = call i8* @malloc(i32 26)
store i8* %16, i8** %3
store i32 0, i32* %4
br label %17
17: ; preds = %22, %15
%18 = load i32*, i32** %2
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %5
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %31
22: ; preds = %17
%23 = load i32, i32* %5
%24 = trunc i32 %23 to i8
%25 = load i8*, i8** %3
%26 = load i32, i32* %4
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
store i8 %24, i8* %28
%29 = load i32, i32* %4
%30 = add nsw i32 %29, 1
store i32 %30, i32* %4
br label %17
31: ; preds = %17
%32 = load i32*, i32** %2
%33 = call i32 @fclose(i32* %32)
%34 = call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %34, i32** %6
%35 = load i32*, i32** %6
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %31
store i32 25, i32* %7
br label %42
42: ; preds = %53, %41
%43 = load i32, i32* %7
%44 = icmp sge i32 %43, 0
br i1 %44, label %45, label %56
45: ; preds = %42
%46 = load i8*, i8** %3
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
%50 = load i8, i8* %49
%51 = load i32*, i32** %6
%52 = call i32 @fputc(i8 signext %50, i32* %51)
br label %53
53: ; preds = %45
%54 = load i32, i32* %7
%55 = add nsw i32 %54, -1
store i32 %55, i32* %7
br label %42
56: ; preds = %42
%57 = load i8*, i8** %3
%58 = call i32 @free(i8* %57)
%59 = load i32*, i32** %6
%60 = call i32 @fclose(i32* %59)
%61 = load i32, i32* %1
ret i32 %61
}

LLVM IR (-O2):
@.str = [13 x i8] c"alphabet.txt\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [24 x i8] c"Can't open input file!\0A\00"
@EOF = global i32 0
@.str.3 = [21 x i8] c"reverse_alphabet.txt\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [25 x i8] c"Can't open output file!\0A\00"
define i32 @main() {
%1 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%2 = icmp eq i32* %1, null
br i1 %2, label %3, label %7
3: ; preds = %0
%4 = load i32, i32* @stderr
%5 = tail call i32 @fprintf(i32 %4, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i32 @exit(i32 1)
unreachable
7: ; preds = %0
%8 = tail call dereferenceable_or_null(26) i8* @malloc(i32 26)
%9 = tail call i32 @fgetc(i32* %1)
%10 = load i32, i32* @EOF
%11 = icmp eq i32 %9, %10
br i1 %11, label %21, label %12
12: ; preds = %7, %12
%13 = phi i64 [ %17, %12 ], [ 0, %7 ]
%14 = phi i32 [ %18, %12 ], [ %9, %7 ]
%15 = trunc i32 %14 to i8
%16 = getelementptr inbounds i8, i8* %8, i64 %13
store i8 %15, i8* %16
%17 = add nuw i64 %13, 1
%18 = tail call i32 @fgetc(i32* %1)
%19 = load i32, i32* @EOF
%20 = icmp eq i32 %18, %19
br i1 %20, label %21, label %12
21: ; preds = %12, %7
%22 = tail call i32 @fclose(i32* %1)
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i32* %23, null
br i1 %24, label %105, label %25
25: ; preds = %21
%26 = getelementptr inbounds i8, i8* %8, i64 25
%27 = load i8, i8* %26
%28 = tail call i32 @fputc(i8 signext %27, i32* %23)
%29 = getelementptr inbounds i8, i8* %8, i64 24
%30 = load i8, i8* %29
%31 = tail call i32 @fputc(i8 signext %30, i32* %23)
%32 = getelementptr inbounds i8, i8* %8, i64 23
%33 = load i8, i8* %32
%34 = tail call i32 @fputc(i8 signext %33, i32* %23)
%35 = getelementptr inbounds i8, i8* %8, i64 22
%36 = load i8, i8* %35
%37 = tail call i32 @fputc(i8 signext %36, i32* %23)
%38 = getelementptr inbounds i8, i8* %8, i64 21
%39 = load i8, i8* %38
%40 = tail call i32 @fputc(i8 signext %39, i32* %23)
%41 = getelementptr inbounds i8, i8* %8, i64 20
%42 = load i8, i8* %41
%43 = tail call i32 @fputc(i8 signext %42, i32* %23)
%44 = getelementptr inbounds i8, i8* %8, i64 19
%45 = load i8, i8* %44
%46 = tail call i32 @fputc(i8 signext %45, i32* %23)
%47 = getelementptr inbounds i8, i8* %8, i64 18
%48 = load i8, i8* %47
%49 = tail call i32 @fputc(i8 signext %48, i32* %23)
%50 = getelementptr inbounds i8, i8* %8, i64 17
%51 = load i8, i8* %50
%52 = tail call i32 @fputc(i8 signext %51, i32* %23)
%53 = getelementptr inbounds i8, i8* %8, i64 16
%54 = load i8, i8* %53
%55 = tail call i32 @fputc(i8 signext %54, i32* %23)
%56 = getelementptr inbounds i8, i8* %8, i64 15
%57 = load i8, i8* %56
%58 = tail call i32 @fputc(i8 signext %57, i32* %23)
%59 = getelementptr inbounds i8, i8* %8, i64 14
%60 = load i8, i8* %59
%61 = tail call i32 @fputc(i8 signext %60, i32* %23)
%62 = getelementptr inbounds i8, i8* %8, i64 13
%63 = load i8, i8* %62
%64 = tail call i32 @fputc(i8 signext %63, i32* %23)
%65 = getelementptr inbounds i8, i8* %8, i64 12
%66 = load i8, i8* %65
%67 = tail call i32 @fputc(i8 signext %66, i32* %23)
%68 = getelementptr inbounds i8, i8* %8, i64 11
%69 = load i8, i8* %68
%70 = tail call i32 @fputc(i8 signext %69, i32* %23)
%71 = getelementptr inbounds i8, i8* %8, i64 10
%72 = load i8, i8* %71
%73 = tail call i32 @fputc(i8 signext %72, i32* %23)
%74 = getelementptr inbounds i8, i8* %8, i64 9
%75 = load i8, i8* %74
%76 = tail call i32 @fputc(i8 signext %75, i32* %23)
%77 = getelementptr inbounds i8, i8* %8, i64 8
%78 = load i8, i8* %77
%79 = tail call i32 @fputc(i8 signext %78, i32* %23)
%80 = getelementptr inbounds i8, i8* %8, i64 7
%81 = load i8, i8* %80
%82 = tail call i32 @fputc(i8 signext %81, i32* %23)
%83 = getelementptr inbounds i8, i8* %8, i64 6
%84 = load i8, i8* %83
%85 = tail call i32 @fputc(i8 signext %84, i32* %23)
%86 = getelementptr inbounds i8, i8* %8, i64 5
%87 = load i8, i8* %86
%88 = tail call i32 @fputc(i8 signext %87, i32* %23)
%89 = getelementptr inbounds i8, i8* %8, i64 4
%90 = load i8, i8* %89
%91 = tail call i32 @fputc(i8 signext %90, i32* %23)
%92 = getelementptr inbounds i8, i8* %8, i64 3
%93 = load i8, i8* %92
%94 = tail call i32 @fputc(i8 signext %93, i32* %23)
%95 = getelementptr inbounds i8, i8* %8, i64 2
%96 = load i8, i8* %95
%97 = tail call i32 @fputc(i8 signext %96, i32* %23)
%98 = getelementptr inbounds i8, i8* %8, i64 1
%99 = load i8, i8* %98
%100 = tail call i32 @fputc(i8 signext %99, i32* %23)
%101 = load i8, i8* %8
%102 = tail call i32 @fputc(i8 signext %101, i32* %23)
%103 = tail call i32 @free(i8* %8)
%104 = tail call i32 @fclose(i32* %23)
ret i32 0
105: ; preds = %21
%106 = load i32, i32* @stderr
%107 = tail call i32 @fprintf(i32 %106, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.5, i64 0, i64 0))
%108 = tail call i32 @exit(i32 1)
unreachable
}