#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 */
struct t_safeu_struct {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ free(char *);
scalar_t__ read_file(char const *, char **, unsigned int *);
scalar_t__ safeu_encrypt_block(struct t_safeu_struct *, char *, unsigned int,
                               char **, unsigned int *);
scalar_t__ write_file(char const *, char *, unsigned int);
int safeu_encrypt_a_file(struct t_safeu_struct *ac, const char *src_fname,
                         const char *dest_fname) {
  int ok = 1;
  char *file_in_data = NULL;
  char *file_out_data = NULL;
  unsigned file_in_size = 0;
  unsigned file_out_size = 0;
  ok = ok && read_file(src_fname, &file_in_data, &file_in_size);
  ok = ok && safeu_encrypt_block(ac, file_in_data, file_in_size, &file_out_data,
                                 &file_out_size);
  ok = ok && write_file(dest_fname, file_out_data, file_out_size);
  free(file_in_data);
  free(file_out_data);
  return ok;
}


x86 assembly (clang, -O0):
<safeu_encrypt_a_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
movq   $0x0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
movl   $0x0,-0x38(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x39(%rbp)
je     11a3 <safeu_encrypt_a_file+0x63>
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
lea    -0x34(%rbp),%rdx
call   1050 <read_file@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x39(%rbp)
mov    -0x39(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x3a(%rbp)
je     11df <safeu_encrypt_a_file+0x9f>
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x34(%rbp),%edx
lea    -0x30(%rbp),%rcx
lea    -0x38(%rbp),%r8
call   1060 <safeu_encrypt_block@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x3a(%rbp)
mov    -0x3a(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0x1c(%rbp)
mov    %al,-0x3b(%rbp)
je     1213 <safeu_encrypt_a_file+0xd3>
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x38(%rbp),%edx
call   1040 <write_file@plt>
cmp    $0x0,%rax
setne  %al
mov    %al,-0x3b(%rbp)
mov    -0x3b(%rbp),%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<safeu_encrypt_a_file>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%rax
mov    %rdi,%r15
movq   $0x0,0x18(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x0,0xc(%rsp)
movl   $0x0,0x8(%rsp)
lea    0x18(%rsp),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1050 <read_file@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     11c6 <safeu_encrypt_a_file+0x86>
mov    0x18(%rsp),%rsi
mov    0xc(%rsp),%edx
lea    0x10(%rsp),%rcx
lea    0x8(%rsp),%r8
mov    %r15,%rdi
call   1060 <safeu_encrypt_block@plt>
test   %rax,%rax
je     11c6 <safeu_encrypt_a_file+0x86>
mov    0x10(%rsp),%rsi
mov    0x8(%rsp),%edx
mov    %r14,%rdi
call   1040 <write_file@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    0x18(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.t_safeu_struct = type { i32 }
define i32 @safeu_encrypt_a_file(%struct.t_safeu_struct* %0, i8* %1, i8* %2) {
%4 = alloca %struct.t_safeu_struct*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i32
store %struct.t_safeu_struct* %0, %struct.t_safeu_struct** %4
store i8* %1, i8** %5
store i8* %2, i8** %6
store i32 1, i32* %7
store i8* null, i8** %8
store i8* null, i8** %9
store i32 0, i32* %10
store i32 0, i32* %11
%12 = load i32, i32* %7
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %18
14: ; preds = %3
%15 = load i8*, i8** %5
%16 = call i64 @read_file(i8* %15, i8** %8, i32* %10)
%17 = icmp ne i64 %16, 0
br label %18
18: ; preds = %14, %3
%19 = phi i1 [ false, %3 ], [ %17, %14 ]
%20 = zext i1 %19 to i32
store i32 %20, i32* %7
%21 = load i32, i32* %7
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %18
%24 = load %struct.t_safeu_struct*, %struct.t_safeu_struct** %4
%25 = load i8*, i8** %8
%26 = load i32, i32* %10
%27 = call i64 @safeu_encrypt_block(%struct.t_safeu_struct* %24, i8* %25, i32 %26, i8** %9, i32* %11)
%28 = icmp ne i64 %27, 0
br label %29
29: ; preds = %23, %18
%30 = phi i1 [ false, %18 ], [ %28, %23 ]
%31 = zext i1 %30 to i32
store i32 %31, i32* %7
%32 = load i32, i32* %7
%33 = icmp ne i32 %32, 0
br i1 %33, label %34, label %40
34: ; preds = %29
%35 = load i8*, i8** %6
%36 = load i8*, i8** %9
%37 = load i32, i32* %11
%38 = call i64 @write_file(i8* %35, i8* %36, i32 %37)
%39 = icmp ne i64 %38, 0
br label %40
40: ; preds = %34, %29
%41 = phi i1 [ false, %29 ], [ %39, %34 ]
%42 = zext i1 %41 to i32
store i32 %42, i32* %7
%43 = load i8*, i8** %8
%44 = call i32 @free(i8* %43)
%45 = load i8*, i8** %9
%46 = call i32 @free(i8* %45)
%47 = load i32, i32* %7
ret i32 %47
}

LLVM IR (-O2):
%struct.t_safeu_struct = type { i32 }
define i32 @safeu_encrypt_a_file(%struct.t_safeu_struct* %0, i8* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = bitcast i8** %4 to i8*
store i8* null, i8** %4
%9 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%10 = bitcast i32* %6 to i8*
store i32 0, i32* %6
%11 = bitcast i32* %7 to i8*
store i32 0, i32* %7
%12 = call i64 @read_file(i8* %1, i8** %4, i32* %6)
%13 = icmp eq i64 %12, 0
br i1 %13, label %25, label %14
14: ; preds = %3
%15 = load i8*, i8** %4
%16 = load i32, i32* %6
%17 = call i64 @safeu_encrypt_block(%struct.t_safeu_struct* %0, i8* %15, i32 %16, i8** %5, i32* %7)
%18 = icmp eq i64 %17, 0
br i1 %18, label %25, label %19
19: ; preds = %14
%20 = load i8*, i8** %5
%21 = load i32, i32* %7
%22 = call i64 @write_file(i8* %2, i8* %20, i32 %21)
%23 = icmp ne i64 %22, 0
%24 = zext i1 %23 to i32
br label %25
25: ; preds = %3, %19, %14
%26 = phi i32 [ 0, %14 ], [ %24, %19 ], [ 0, %3 ]
%27 = load i8*, i8** %4
%28 = call i32 @free(i8* %27)
%29 = load i8*, i8** %5
%30 = call i32 @free(i8* %29)
ret i32 %26
}