#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 */
scalar_t__ EOF;
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int strlen(char *);
char *strrev(char *);
int main(int argc, char *argv[]) {
  if (argc == 2) {
    int i;
    char *word = (char *)malloc(sizeof(char) * 100);
    FILE *fp = fopen(argv[1], "r");
    FILE *out = fopen("output.txt", "w");
    if (fp) {
      while (fscanf(fp, "%s", word) != EOF) {
        word = strrev(word);
        for (i = 0; i < strlen(word); i++) {
          word[i] = ~word[i];
        }
        fprintf(out, "%s ", word);
      }
    } else
      printf("%s does not exist\n", argv[1]);
  } else
    printf("Usage: encrypt input_file_name\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1294 <main+0x124>
mov    $0x64,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe53(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x28(%rbp)
lea    0xe45(%rip),%rdi
lea    0xe49(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1279 <main+0x109>
jmp    11dd <main+0x6d>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xe23(%rip),%rsi
call   1050 <fscanf@plt>
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%rax
je     1274 <main+0x104>
mov    -0x20(%rbp),%rdi
call   1080 <strrev@plt>
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x34(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x34(%rbp),%eax
cmp    %ecx,%eax
jge    125b <main+0xeb>
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
xor    $0xffffffff,%eax
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1215 <main+0xa5>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xda8(%rip),%rsi
call   1060 <fprintf@plt>
jmp    11dd <main+0x6d>
jmp    128f <main+0x11f>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12a2 <main+0x132>
lea    0xd8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jne    1278 <main+0xf8>
mov    %rsi,%r12
mov    $0x64,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
mov    0x8(%r12),%rdi
lea    0xe50(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%r14
lea    0xe43(%rip),%rdi
lea    0xe47(%rip),%rsi
call   10a0 <fopen@plt>
test   %r14,%r14
je     1286 <main+0x106>
mov    %rax,%r15
lea    0xe31(%rip),%rsi
mov    %r14,%rdi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
mov    0x2df8(%rip),%rcx
cmp    (%rcx),%rax
je     1299 <main+0x119>
lea    0xe12(%rip),%r12
lea    0xe08(%rip),%r13
jmp    1238 <main+0xb8>
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
mov    %rbx,%rdx
call   1060 <fscanf@plt>
mov    0x2db5(%rip),%rcx
cmp    (%rcx),%rax
je     1299 <main+0x119>
mov    %rbx,%rdi
call   1090 <strrev@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
jle    1210 <main+0x90>
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
notb   (%rbx,%rbp,1)
add    $0x1,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1260 <main+0xe0>
jmp    1210 <main+0x90>
lea    0xdaa(%rip),%rdi
call   1030 <puts@plt>
jmp    1299 <main+0x119>
mov    0x8(%r12),%rsi
lea    0xd84(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"output.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.4 = [4 x i8] c"%s \00"
@.str.5 = [19 x i8] c"%s does not exist\0A\00"
@.str.6 = [32 x i8] c"Usage: encrypt input_file_name\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %64
12: ; preds = %2
%13 = call i64 @malloc(i32 100)
%14 = inttoptr i64 %13 to i8*
store i8* %14, i8** %7
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %8
%19 = call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %8
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %58
22: ; preds = %12
br label %23
23: ; preds = %53, %22
%24 = load i32*, i32** %8
%25 = load i8*, i8** %7
%26 = call i64 @fscanf(i32* %24, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %25)
%27 = load i64, i64* @EOF
%28 = icmp ne i64 %26, %27
br i1 %28, label %29, label %57
29: ; preds = %23
%30 = load i8*, i8** %7
%31 = call i8* @strrev(i8* %30)
store i8* %31, i8** %7
store i32 0, i32* %6
br label %32
32: ; preds = %50, %29
%33 = load i32, i32* %6
%34 = load i8*, i8** %7
%35 = call i32 @strlen(i8* %34)
%36 = icmp slt i32 %33, %35
br i1 %36, label %37, label %53
37: ; preds = %32
%38 = load i8*, i8** %7
%39 = load i32, i32* %6
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = xor i32 %43, -1
%45 = trunc i32 %44 to i8
%46 = load i8*, i8** %7
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 %45, i8* %49
br label %50
50: ; preds = %37
%51 = load i32, i32* %6
%52 = add nsw i32 %51, 1
store i32 %52, i32* %6
br label %32
53: ; preds = %32
%54 = load i32*, i32** %9
%55 = load i8*, i8** %7
%56 = call i32 @fprintf(i32* %54, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %55)
br label %23
57: ; preds = %23
br label %63
58: ; preds = %12
%59 = load i8**, i8*** %5
%60 = getelementptr inbounds i8*, i8** %59, i64 1
%61 = load i8*, i8** %60
%62 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %61)
br label %63
63: ; preds = %58, %57
br label %66
64: ; preds = %2
%65 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.6, i64 0, i64 0))
br label %66
66: ; preds = %64, %63
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [11 x i8] c"output.txt\00"
@.str.2 = [2 x i8] c"w\00"
@.str.3 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.4 = [4 x i8] c"%s \00"
@.str.5 = [19 x i8] c"%s does not exist\0A\00"
@str = [31 x i8] c"Usage: encrypt input_file_name\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %38
4: ; preds = %2
%5 = tail call i64 @malloc(i32 100)
%6 = inttoptr i64 %5 to i8*
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32* @fopen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = icmp eq i32* %9, null
br i1 %11, label %35, label %12
12: ; preds = %4
%13 = tail call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %6)
%14 = load i64, i64* @EOF
%15 = icmp eq i64 %13, %14
br i1 %15, label %40, label %16
16: ; preds = %12, %30
%17 = phi i8* [ %18, %30 ], [ %6, %12 ]
%18 = tail call i8* @strrev(i8* %17)
%19 = tail call i32 @strlen(i8* %18)
%20 = icmp sgt i32 %19, 0
br i1 %20, label %21, label %30
21: ; preds = %16, %21
%22 = phi i64 [ %26, %21 ], [ 0, %16 ]
%23 = getelementptr inbounds i8, i8* %18, i64 %22
%24 = load i8, i8* %23
%25 = xor i8 %24, -1
store i8 %25, i8* %23
%26 = add nuw nsw i64 %22, 1
%27 = tail call i32 @strlen(i8* %18)
%28 = sext i32 %27 to i64
%29 = icmp slt i64 %26, %28
br i1 %29, label %21, label %30
30: ; preds = %21, %16
%31 = tail call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* %18)
%32 = tail call i64 @fscanf(i32* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%33 = load i64, i64* @EOF
%34 = icmp eq i64 %32, %33
br i1 %34, label %40, label %16
35: ; preds = %4
%36 = load i8*, i8** %7
%37 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.5, i64 0, i64 0), i8* %36)
br label %40
38: ; preds = %2
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([31 x i8], [31 x i8]* @str, i64 0, i64 0))
br label %40
40: ; preds = %30, %12, %35, %38
ret i32 0
}