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

/* Variables and functions */
int /*<<< orphan*/ encrypt(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ sscanf(char *, char *, char *);
void encryptfile() {
  FILE *infile;
  FILE *outfile;
  infile = fopen("test.ini", "r");
  outfile = fopen("encrypted-test.ini", "w+");
  char file_read_buff[1024];
  char write_buff[1024] = {'\0'};
  printf("encryptfile():\n\n");
  while (fgets(file_read_buff, sizeof(file_read_buff), infile) != NULL) {
    char line_buff[sizeof(file_read_buff)];
    sscanf(file_read_buff, " %[^\n]", line_buff);
    printf("\n  Plain Text Line:\t%s\n", line_buff);
    encrypt(write_buff, line_buff);
    printf("\n  Encrypted Line:\t%s\n", write_buff);
    fputs(write_buff, outfile);
    fputs("\n", outfile);
  }
  fclose(infile);
  fclose(outfile);
}


x86 assembly (clang, -O0):
<encryptfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc10,%rsp
lea    0xe7a(%rip),%rdi
lea    0xe67(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x8(%rbp)
lea    0xe59(%rip),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x810(%rbp),%rdi
xor    %esi,%esi
mov    $0x400,%edx
call   1070 <memset@plt>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x400,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
je     1275 <encryptfile+0xf5>
lea    -0x410(%rbp),%rdi
lea    -0xc10(%rbp),%rdx
lea    0xe1b(%rip),%rsi
call   1090 <sscanf@plt>
lea    -0xc10(%rbp),%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x810(%rbp),%rdi
lea    -0xc10(%rbp),%rsi
call   1050 <encrypt@plt>
lea    -0x810(%rbp),%rsi
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x810(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <fputs@plt>
mov    -0x10(%rbp),%rsi
lea    0xdbc(%rip),%rdi
call   1060 <fputs@plt>
jmp    11da <encryptfile+0x5a>
mov    -0x8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
add    $0xc10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<encryptfile>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xc08,%rsp
lea    0xe54(%rip),%rdi
lea    0xe41(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r14
lea    0xe34(%rip),%rdi
lea    0xe40(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,%r13
mov    %rsp,%rdi
mov    $0x400,%edx
xor    %esi,%esi
call   1080 <memset@plt>
lea    0xe5b(%rip),%rdi
call   1030 <puts@plt>
lea    0x400(%rsp),%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
je     1298 <encryptfile+0xf8>
lea    0x400(%rsp),%r12
lea    0x800(%rsp),%rbx
mov    %rsp,%r15
lea    0xe07(%rip),%rbp
mov    %r12,%rdi
lea    0xdde(%rip),%rsi
mov    %rbx,%rdx
call   10b0 <sscanf@plt>
lea    0xdd6(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1060 <encrypt@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1070 <fputs@plt>
mov    $0xa,%edi
mov    %r13,%rsi
call   1090 <fputc@plt>
mov    %r12,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   10a0 <fgets@plt>
test   %rax,%rax
jne    1230 <encryptfile+0x90>
mov    %r14,%rdi
call   1040 <fclose@plt>
mov    %r13,%rdi
call   1040 <fclose@plt>
add    $0xc08,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"test.ini\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"encrypted-test.ini\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.4 = [17 x i8] c"encryptfile():\0A\0A\00"
@.str.5 = [7 x i8] c" %[^\0A]\00"
@.str.6 = [24 x i8] c"\0A Plain Text Line:\09%s\0A\00"
@.str.7 = [23 x i8] c"\0A Encrypted Line:\09%s\0A\00"
@.str.8 = [2 x i8] c"\0A\00"
define void @encryptfile() {
%1 = alloca i32*
%2 = alloca i32*
%3 = alloca [1024 x i8]
%4 = alloca [1024 x i8]
%5 = alloca [1024 x i8]
%6 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %1
%7 = call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
store i32* %7, i32** %2
%8 = bitcast [1024 x i8]* %4 to i8*
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %10
10: ; preds = %15, %0
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%12 = load i32*, i32** %1
%13 = call i32* @fgets(i8* %11, i32 1024, i32* %12)
%14 = icmp ne i32* %13, null
br i1 %14, label %15, label %31
15: ; preds = %10
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%18 = call i32 @sscanf(i8* %16, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %17)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%23 = call i32 @encrypt(i8* %21, i8* %22)
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %24)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%27 = load i32*, i32** %2
%28 = call i32 @fputs(i8* %26, i32* %27)
%29 = load i32*, i32** %2
%30 = call i32 @fputs(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.8, i64 0, i64 0), i32* %29)
br label %10
31: ; preds = %10
%32 = load i32*, i32** %1
%33 = call i32 @fclose(i32* %32)
%34 = load i32*, i32** %2
%35 = call i32 @fclose(i32* %34)
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"test.ini\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [19 x i8] c"encrypted-test.ini\00"
@.str.3 = [3 x i8] c"w+\00"
@.str.5 = [7 x i8] c" %[^\0A]\00"
@.str.6 = [24 x i8] c"\0A Plain Text Line:\09%s\0A\00"
@.str.7 = [23 x i8] c"\0A Encrypted Line:\09%s\0A\00"
@str = [16 x i8] c"encryptfile():\0A\00"
define void @encryptfile() {
%1 = alloca [1024 x i8]
%2 = alloca [1024 x i8]
%3 = alloca [1024 x i8]
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%9 = call i32* @fgets(i8* %6, i32 1024, i32* %4)
%10 = icmp eq i32* %9, null
br i1 %10, label %22, label %11
11: ; preds = %0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
br label %13
13: ; preds = %11, %13
%14 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %12)
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0), i8* %12)
%16 = call i32 @encrypt(i8* %7, i8* %12)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.7, i64 0, i64 0), i8* %7)
%18 = call i32 @fputs(i8* %7, i32* %5)
%19 = call i32 @fputc(i32 10, i32* %5)
%20 = call i32* @fgets(i8* %6, i32 1024, i32* %4)
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %13
22: ; preds = %13, %0
%23 = call i32 @fclose(i32* %4)
%24 = call i32 @fclose(i32* %5)
ret void
}