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

/* Variables and functions */
int /*<<< orphan*/ dc_crypt_buffer(char *, int, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
void dc_crypt_stream(int src_fd, int dest_fd, int decrypt) {
  if (decrypt)
    printf("Decrypting file...\n");
  else
    printf("Encrypting file...\n");
  char buf[57];
  char *current = buf;
  int cur_no = 0;
  while (read(src_fd, current, 1) != 0) {
    if (*current == '\0')
      continue;
    if ((cur_no + 1) == 57) {
      dc_crypt_buffer(buf, 57, decrypt);
      write(dest_fd, buf, 57);
      memset(buf, 0, 57);
      current = buf;
      cur_no = 0;
    }
    current++;
    cur_no++;
  }
  if (cur_no != 0) {
    printf("Chars remaining: %i\n", cur_no);
    dc_crypt_buffer(buf, cur_no, decrypt);
    write(dest_fd, buf, cur_no);
  }
}


x86 assembly (clang, -O0):
<dc_crypt_stream>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %edx,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
je     117e <dc_crypt_stream+0x2e>
lea    0xe8e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    118c <dc_crypt_stream+0x3c>
lea    0xe8f(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x58(%rbp),%rsi
mov    $0x1,%edx
call   1060 <read@plt>
cmp    $0x0,%rax
je     1235 <dc_crypt_stream+0xe5>
mov    -0x58(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11cb <dc_crypt_stream+0x7b>
jmp    119b <dc_crypt_stream+0x4b>
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
cmp    $0x39,%eax
jne    121b <dc_crypt_stream+0xcb>
lea    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x39,%esi
call   1070 <dc_crypt_buffer@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x39,%edx
call   1030 <write@plt>
lea    -0x50(%rbp),%rdi
xor    %esi,%esi
mov    $0x39,%edx
call   1050 <memset@plt>
lea    -0x50(%rbp),%rax
mov    %rax,-0x58(%rbp)
movl   $0x0,-0x5c(%rbp)
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    119b <dc_crypt_stream+0x4b>
cmpl   $0x0,-0x5c(%rbp)
je     126e <dc_crypt_stream+0x11e>
mov    -0x5c(%rbp),%esi
lea    0xddf(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x50(%rbp),%rdi
mov    -0x5c(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1070 <dc_crypt_buffer@plt>
mov    -0x8(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    -0x5c(%rbp),%edx
call   1030 <write@plt>
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dc_crypt_stream>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %edx,%r15d
mov    %esi,%r14d
mov    %edi,%ebx
test   %edx,%edx
lea    0xe96(%rip),%rax
lea    0xea2(%rip),%rdi
cmove  %rax,%rdi
call   1030 <puts@plt>
mov    %rsp,%r12
xor    %r13d,%r13d
mov    %r12,%rbp
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x1,%edx
call   1070 <read@plt>
test   %rax,%rax
je     11ff <dc_crypt_stream+0x9f>
cmpb   $0x0,0x0(%rbp)
je     11a0 <dc_crypt_stream+0x40>
cmp    $0x38,%r13d
jne    11f5 <dc_crypt_stream+0x95>
mov    %r12,%rdi
mov    $0x39,%esi
mov    %r15d,%edx
call   1080 <dc_crypt_buffer@plt>
mov    %r14d,%edi
mov    %r12,%rsi
mov    $0x39,%edx
call   1040 <write@plt>
xor    %r13d,%r13d
mov    %r12,%rdi
xor    %esi,%esi
mov    $0x39,%edx
call   1060 <memset@plt>
mov    %r12,%rbp
add    $0x1,%rbp
add    $0x1,%r13d
jmp    11a0 <dc_crypt_stream+0x40>
test   %r13d,%r13d
je     1234 <dc_crypt_stream+0xd4>
lea    0xdf5(%rip),%rdi
mov    %r13d,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r15d,%edx
call   1080 <dc_crypt_buffer@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r13d,%edx
call   1040 <write@plt>
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Decrypting file...\0A\00"
@.str.1 = [20 x i8] c"Encrypting file...\0A\00"
@.str.2 = [21 x i8] c"Chars remaining: %i\0A\00"
define void @dc_crypt_stream(i32 %0, i32 %1, i32 %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [57 x i8]
%8 = alloca i8*
%9 = alloca i32
store i32 %0, i32* %4
store i32 %1, i32* %5
store i32 %2, i32* %6
%10 = load i32, i32* %6
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %16
14: ; preds = %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %12
%17 = getelementptr inbounds [57 x i8], [57 x i8]* %7, i64 0, i64 0
store i8* %17, i8** %8
store i32 0, i32* %9
br label %18
18: ; preds = %43, %28, %16
%19 = load i32, i32* %4
%20 = load i8*, i8** %8
%21 = call i64 @read(i32 %19, i8* %20, i32 1)
%22 = icmp ne i64 %21, 0
br i1 %22, label %23, label %48
23: ; preds = %18
%24 = load i8*, i8** %8
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %18
29: ; preds = %23
%30 = load i32, i32* %9
%31 = add nsw i32 %30, 1
%32 = icmp eq i32 %31, 57
br i1 %32, label %33, label %43
33: ; preds = %29
%34 = getelementptr inbounds [57 x i8], [57 x i8]* %7, i64 0, i64 0
%35 = load i32, i32* %6
%36 = call i32 @dc_crypt_buffer(i8* %34, i32 57, i32 %35)
%37 = load i32, i32* %5
%38 = getelementptr inbounds [57 x i8], [57 x i8]* %7, i64 0, i64 0
%39 = call i32 @write(i32 %37, i8* %38, i32 57)
%40 = getelementptr inbounds [57 x i8], [57 x i8]* %7, i64 0, i64 0
%41 = call i32 @memset(i8* %40, i32 0, i32 57)
%42 = getelementptr inbounds [57 x i8], [57 x i8]* %7, i64 0, i64 0
store i8* %42, i8** %8
store i32 0, i32* %9
br label %43
43: ; preds = %33, %29
%44 = load i8*, i8** %8
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %8
%46 = load i32, i32* %9
%47 = add nsw i32 %46, 1
store i32 %47, i32* %9
br label %18
48: ; preds = %18
%49 = load i32, i32* %9
%50 = icmp ne i32 %49, 0
br i1 %50, label %51, label %62
51: ; preds = %48
%52 = load i32, i32* %9
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %52)
%54 = getelementptr inbounds [57 x i8], [57 x i8]* %7, i64 0, i64 0
%55 = load i32, i32* %9
%56 = load i32, i32* %6
%57 = call i32 @dc_crypt_buffer(i8* %54, i32 %55, i32 %56)
%58 = load i32, i32* %5
%59 = getelementptr inbounds [57 x i8], [57 x i8]* %7, i64 0, i64 0
%60 = load i32, i32* %9
%61 = call i32 @write(i32 %58, i8* %59, i32 %60)
br label %62
62: ; preds = %51, %48
ret void
}

LLVM IR (-O2):
@.str.2 = [21 x i8] c"Chars remaining: %i\0A\00"
@str = [19 x i8] c"Encrypting file...\00"
@str.3 = [19 x i8] c"Decrypting file...\00"
define void @dc_crypt_stream(i32 %0, i32 %1, i32 %2) {
%4 = alloca [57 x i8]
%5 = icmp eq i32 %2, 0
%6 = select i1 %5, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @str.3, i64 0, i64 0)
%7 = tail call i32 @puts(i8* dereferenceable(1) %6)
%8 = getelementptr inbounds [57 x i8], [57 x i8]* %4, i64 0, i64 0
br label %9
9: ; preds = %24, %3
%10 = phi i8* [ %27, %24 ], [ %8, %3 ]
%11 = phi i32 [ %28, %24 ], [ 0, %3 ]
br label %12
12: ; preds = %9, %15
%13 = call i64 @read(i32 %0, i8* %10, i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %29, label %15
15: ; preds = %12
%16 = load i8, i8* %10
%17 = icmp eq i8 %16, 0
br i1 %17, label %12, label %18
18: ; preds = %15
%19 = icmp eq i32 %11, 56
br i1 %19, label %20, label %24
20: ; preds = %18
%21 = call i32 @dc_crypt_buffer(i8* %8, i32 57, i32 %2)
%22 = call i32 @write(i32 %1, i8* %8, i32 57)
%23 = call i32 @memset(i8* %8, i32 0, i32 57)
br label %24
24: ; preds = %20, %18
%25 = phi i8* [ %8, %20 ], [ %10, %18 ]
%26 = phi i32 [ 0, %20 ], [ %11, %18 ]
%27 = getelementptr inbounds i8, i8* %25, i64 1
%28 = add nsw i32 %26, 1
br label %9
29: ; preds = %12
%30 = icmp eq i32 %11, 0
br i1 %30, label %35, label %31
31: ; preds = %29
%32 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%33 = call i32 @dc_crypt_buffer(i8* %8, i32 %11, i32 %2)
%34 = call i32 @write(i32 %1, i8* %8, i32 %11)
br label %35
35: ; preds = %31, %29
ret void
}