#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*/ y;
typedef int /*<<< orphan*/ x;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    printf("\nERROR: Function requires 2 inputs.\n");
    printf("Please try again.\n");
    printf("Enter the name of 1) the program file and 2) the file to be "
           "scrambled.\n");
    exit(0);
  } else {
    FILE *fp_read;
    FILE *fp_write;
    char x, y;
    char newfile[50];
    fp_read = fopen(argv[1], "r+");
    if (fp_read == NULL) {
      printf("\nERROR: File could not be opened for reading.\n");
      exit(0);
    } else {
      strcpy(newfile, (strcat(argv[1], ".sbl")));
      fp_write = fopen(newfile, "w");
      if (fp_read == NULL) {
        printf(
            "\nERROR: New scrambled file could not be opened for writing.\n");
        exit(0);
      } else {
        int i, j;
        while (feof(fp_read) == 0) {
          i = fread(&x, sizeof(x), 1, fp_read);
          j = fread(&y, sizeof(y), 1, fp_read);
          if (j == 1) {
            fwrite(&y, sizeof(char), 1, fp_write);
          }
          if (i == 1) {
            fwrite(&x, sizeof(char), 1, fp_write);
          }
        }
        printf("\nThe file has now been scrambled. \nSee file \"%s\" in the "
               "directory",
               newfile);
        fclose(fp_read);
        fclose(fp_write);
        printf("\nFiles closed. Program Terminated.\n");
        exit(0);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11e1 <main+0x51>
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe60(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe90(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1219 <main+0x89>
lea    0xe78(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
lea    -0x60(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe82(%rip),%rsi
call   1090 <strcat@plt>
mov    -0x70(%rbp),%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    -0x60(%rbp),%rdi
lea    0xe6c(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1274 <main+0xe4>
lea    0xe53(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
jmp    1279 <main+0xe9>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%rax
jne    12fb <main+0x16b>
mov    -0x18(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x64(%rbp)
mov    -0x18(%rbp),%rcx
lea    -0x22(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1040 <fread@plt>
mov    %eax,-0x68(%rbp)
cmpl   $0x1,-0x68(%rbp)
jne    12d8 <main+0x148>
mov    -0x20(%rbp),%rcx
lea    -0x22(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10b0 <fwrite@plt>
cmpl   $0x1,-0x64(%rbp)
jne    12f6 <main+0x166>
mov    -0x20(%rbp),%rcx
lea    -0x21(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   10b0 <fwrite@plt>
jmp    1279 <main+0xe9>
lea    -0x60(%rbp),%rsi
lea    0xdf0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x50,%rsp
cmp    $0x2,%edi
jne    11d5 <main+0x35>
mov    %rsi,%rbp
mov    0x8(%rsi),%rdi
lea    0xe41(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
jne    11f9 <main+0x59>
lea    0xe9f(%rip),%rdi
jmp    12d9 <main+0x139>
lea    0xec1(%rip),%rdi
call   1040 <puts@plt>
lea    0xed9(%rip),%rdi
call   1040 <puts@plt>
lea    0xedf(%rip),%rdi
jmp    12d9 <main+0x139>
mov    %rax,%rbx
mov    0x8(%rbp),%rdi
lea    0xdfc(%rip),%rsi
call   10b0 <strcat@plt>
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    %eax,%esi
call   1030 <strcpy@plt>
lea    0xde6(%rip),%rsi
mov    %rbp,%rdi
call   10a0 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    12af <main+0x10f>
lea    0xf(%rsp),%r15
lea    0xe(%rsp),%r12
jmp    125d <main+0xbd>
cs nopw 0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1090 <feof@plt>
test   %rax,%rax
jne    12af <main+0x10f>
mov    %r15,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %eax,%ebp
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1050 <fread@plt>
cmp    $0x1,%eax
jne    129b <main+0xfb>
movsbl 0xe(%rsp),%edi
mov    %r14,%rsi
call   1080 <fputc@plt>
cmp    $0x1,%ebp
jne    1250 <main+0xb0>
movsbl 0xf(%rsp),%edi
mov    %r14,%rsi
call   1080 <fputc@plt>
jmp    1250 <main+0xb0>
lea    0xd54(%rip),%rdi
lea    0x10(%rsp),%rsi
xor    %eax,%eax
call   1070 <printf@plt>
mov    %rbx,%rdi
call   1060 <fclose@plt>
mov    %r14,%rdi
call   1060 <fclose@plt>
lea    0xd73(%rip),%rdi
call   1040 <puts@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"\0AERROR: Function requires 2 inputs.\0A\00"
@.str.1 = [19 x i8] c"Please try again.\0A\00"
@.str.2 = [72 x i8] c"Enter the name of 1) the program file and 2) the file to be scrambled.\0A\00"
@.str.3 = [3 x i8] c"r+\00"
@.str.4 = [47 x i8] c"\0AERROR: File could not be opened for reading.\0A\00"
@.str.5 = [5 x i8] c".sbl\00"
@.str.6 = [2 x i8] c"w\00"
@.str.7 = [61 x i8] c"\0AERROR: New scrambled file could not be opened for writing.\0A\00"
@.str.8 = [66 x i8] c"\0AThe file has now been scrambled. \0ASee file \22%s\22 in the directory\00"
@.str.9 = [36 x i8] c"\0AFiles closed. Program Terminated.\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca i8
%9 = alloca i8
%10 = alloca [50 x i8]
%11 = alloca i32
%12 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%13 = load i32, i32* %4
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %20
15: ; preds = %2
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
%24 = call i32* @fopen(i8* %23, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %24, i32** %6
%25 = load i32*, i32** %6
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %20
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.4, i64 0, i64 0))
%29 = call i32 @exit(i32 0)
unreachable
30: ; preds = %20
%31 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 1
%34 = load i8*, i8** %33
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%36 = call i32 @strcpy(i8* %31, i32 %35)
%37 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
store i32* %38, i32** %7
%39 = load i32*, i32** %6
%40 = icmp eq i32* %39, null
br i1 %40, label %41, label %44
41: ; preds = %30
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([61 x i8], [61 x i8]* @.str.7, i64 0, i64 0))
%43 = call i32 @exit(i32 0)
unreachable
44: ; preds = %30
br label %45
45: ; preds = %65, %44
%46 = load i32*, i32** %6
%47 = call i64 @feof(i32* %46)
%48 = icmp eq i64 %47, 0
br i1 %48, label %49, label %66
49: ; preds = %45
%50 = load i32*, i32** %6
%51 = call i32 @fread(i8* %8, i32 1, i32 1, i32* %50)
store i32 %51, i32* %11
%52 = load i32*, i32** %6
%53 = call i32 @fread(i8* %9, i32 1, i32 1, i32* %52)
store i32 %53, i32* %12
%54 = load i32, i32* %12
%55 = icmp eq i32 %54, 1
br i1 %55, label %56, label %59
56: ; preds = %49
%57 = load i32*, i32** %7
%58 = call i32 @fwrite(i8* %9, i32 1, i32 1, i32* %57)
br label %59
59: ; preds = %56, %49
%60 = load i32, i32* %11
%61 = icmp eq i32 %60, 1
br i1 %61, label %62, label %65
62: ; preds = %59
%63 = load i32*, i32** %7
%64 = call i32 @fwrite(i8* %8, i32 1, i32 1, i32* %63)
br label %65
65: ; preds = %62, %59
br label %45
66: ; preds = %45
%67 = getelementptr inbounds [50 x i8], [50 x i8]* %10, i64 0, i64 0
%68 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0), i8* %67)
%69 = load i32*, i32** %6
%70 = call i32 @fclose(i32* %69)
%71 = load i32*, i32** %7
%72 = call i32 @fclose(i32* %71)
%73 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.9, i64 0, i64 0))
%74 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str.3 = [3 x i8] c"r+\00"
@.str.5 = [5 x i8] c".sbl\00"
@.str.6 = [2 x i8] c"w\00"
@.str.8 = [66 x i8] c"\0AThe file has now been scrambled. \0ASee file \22%s\22 in the directory\00"
@str = [35 x i8] c"\0AFiles closed. Program Terminated.\00"
@str.10 = [46 x i8] c"\0AERROR: File could not be opened for reading.\00"
@str.11 = [36 x i8] c"\0AERROR: Function requires 2 inputs.\00"
@str.12 = [18 x i8] c"Please try again.\00"
@str.13 = [71 x i8] c"Enter the name of 1) the program file and 2) the file to be scrambled.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = alloca i8
%5 = alloca [50 x i8]
%6 = icmp eq i32 %0, 2
br i1 %6, label %12, label %7
7: ; preds = %2
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @str.11, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.12, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.13, i64 0, i64 0))
%11 = tail call i32 @exit(i32 0)
unreachable
12: ; preds = %2
%13 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %12
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str.10, i64 0, i64 0))
%20 = tail call i32 @exit(i32 0)
unreachable
21: ; preds = %12
%22 = load i8*, i8** %14
%23 = tail call i32 @strcat(i8* %22, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0))
%24 = call i32 @strcpy(i8* %13, i32 %23)
%25 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i64 0, i64 0))
%26 = call i64 @feof(i32* %16)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %45
28: ; preds = %21, %42
%29 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %16)
%30 = call i32 @fread(i8* %4, i32 1, i32 1, i32* %16)
%31 = icmp eq i32 %30, 1
br i1 %31, label %32, label %36
32: ; preds = %28
%33 = load i8, i8* %4
%34 = sext i8 %33 to i32
%35 = call i32 @fputc(i32 %34, i32* %25)
br label %36
36: ; preds = %32, %28
%37 = icmp eq i32 %29, 1
br i1 %37, label %38, label %42
38: ; preds = %36
%39 = load i8, i8* %3
%40 = sext i8 %39 to i32
%41 = call i32 @fputc(i32 %40, i32* %25)
br label %42
42: ; preds = %38, %36
%43 = call i64 @feof(i32* %16)
%44 = icmp eq i64 %43, 0
br i1 %44, label %28, label %45
45: ; preds = %42, %21
%46 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([66 x i8], [66 x i8]* @.str.8, i64 0, i64 0), i8* %13)
%47 = call i32 @fclose(i32* %16)
%48 = call i32 @fclose(i32* %25)
%49 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
%50 = call i32 @exit(i32 0)
unreachable
}