#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 */
int /*<<< orphan*/ EXIT_FAILURE;
size_t digmd5(char *, unsigned char *, size_t);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
size_t fwrite(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int write_digest_file(FILE *src, FILE *digsfile) {
  size_t fread_src_length;
  size_t fwrite_dest_length;
  size_t md5_length;
  char buffer[131072];
  unsigned char digest[16];
  if (src == NULL || digsfile == NULL)
    return -1;
  rewind(src);
  rewind(digsfile);
  while ((fread_src_length = fread(buffer, 1, 131072, src)) > 0) {
    md5_length = digmd5(buffer, digest, fread_src_length);
    fwrite_dest_length = fwrite(digest, 1, md5_length, digsfile);
    if (fwrite_dest_length < md5_length) {
      do {
        perror("fwrite");
        exit(EXIT_FAILURE);
      } while (0);
      ;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<write_digest_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20040,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1189 <write_digest_file+0x29>
cmpq   $0x0,-0x18(%rbp)
jne    1195 <write_digest_file+0x35>
movl   $0xffffffff,-0x4(%rbp)
jmp    1240 <write_digest_file+0xe0>
mov    -0x10(%rbp),%rdi
call   1040 <rewind@plt>
mov    -0x18(%rbp),%rdi
call   1040 <rewind@plt>
lea    -0x20030(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x20000,%edx
call   1030 <fread@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jbe    1239 <write_digest_file+0xd9>
lea    -0x20030(%rbp),%rdi
lea    -0x20040(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1050 <digmd5@plt>
mov    %rax,-0x30(%rbp)
lea    -0x20040(%rbp),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1080 <fwrite@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x30(%rbp),%rax
jae    1234 <write_digest_file+0xd4>
jmp    121a <write_digest_file+0xba>
lea    0xddf(%rip),%rdi
call   1060 <perror@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
jmp    11a7 <write_digest_file+0x47>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<write_digest_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20010,%rsp
mov    $0xffffffff,%eax
test   %rdi,%rdi
je     11ff <write_digest_file+0x9f>
mov    %rsi,%r14
test   %rsi,%rsi
je     11ff <write_digest_file+0x9f>
mov    %rdi,%r15
call   1040 <rewind@plt>
mov    %r14,%rdi
call   1040 <rewind@plt>
lea    0x10(%rsp),%r12
mov    %rsp,%r13
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x1,%esi
mov    $0x20000,%edx
mov    %r15,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11fd <write_digest_file+0x9d>
mov    %r12,%rdi
mov    %r13,%rsi
mov    %rax,%rdx
call   1050 <digmd5@plt>
mov    %rax,%rbx
mov    %r13,%rdi
mov    $0x1,%esi
mov    %rax,%rdx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    %rbx,%rax
jae    11a0 <write_digest_file+0x40>
lea    0xe16(%rip),%rdi
call   1060 <perror@plt>
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
xor    %eax,%eax
add    $0x20010,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"fwrite\00"
@EXIT_FAILURE = global i32 0
define i32 @write_digest_file(i32* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca [131072 x i8]
%10 = alloca [16 x i8]
store i32* %0, i32** %4
store i32* %1, i32** %5
%11 = load i32*, i32** %4
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = icmp eq i32* %14, null
br i1 %15, label %16, label %17
16: ; preds = %13, %2
store i32 -1, i32* %3
br label %47
17: ; preds = %13
%18 = load i32*, i32** %4
%19 = call i32 @rewind(i32* %18)
%20 = load i32*, i32** %5
%21 = call i32 @rewind(i32* %20)
br label %22
22: ; preds = %45, %17
%23 = getelementptr inbounds [131072 x i8], [131072 x i8]* %9, i64 0, i64 0
%24 = load i32*, i32** %4
%25 = call i64 @fread(i8* %23, i32 1, i32 131072, i32* %24)
store i64 %25, i64* %6
%26 = icmp ugt i64 %25, 0
br i1 %26, label %27, label %46
27: ; preds = %22
%28 = getelementptr inbounds [131072 x i8], [131072 x i8]* %9, i64 0, i64 0
%29 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%30 = load i64, i64* %6
%31 = call i64 @digmd5(i8* %28, i8* %29, i64 %30)
store i64 %31, i64* %8
%32 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%33 = load i64, i64* %8
%34 = load i32*, i32** %5
%35 = call i64 @fwrite(i8* %32, i32 1, i64 %33, i32* %34)
store i64 %35, i64* %7
%36 = load i64, i64* %7
%37 = load i64, i64* %8
%38 = icmp ult i64 %36, %37
br i1 %38, label %39, label %45
39: ; preds = %27
br label %40
40: ; preds = %39
%41 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
%43 = call i32 @exit(i32 %42)
unreachable
44: ; No predecessors!
br label %45
45: ; preds = %44, %27
br label %22
46: ; preds = %22
store i32 0, i32* %3
br label %47
47: ; preds = %46, %16
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [7 x i8] c"fwrite\00"
@EXIT_FAILURE = global i32 0
define i32 @write_digest_file(i32* %0, i32* %1) {
%3 = alloca [131072 x i8]
%4 = alloca [16 x i8]
%5 = getelementptr inbounds [131072 x i8], [131072 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %4, i64 0, i64 0
%7 = icmp eq i32* %0, null
%8 = icmp eq i32* %1, null
%9 = or i1 %7, %8
br i1 %9, label %24, label %10
10: ; preds = %2
%11 = tail call i32 @rewind(i32* %0)
%12 = tail call i32 @rewind(i32* %1)
br label %13
13: ; preds = %16, %10
%14 = call i64 @fread(i8* %5, i32 1, i32 131072, i32* %0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %24, label %16
16: ; preds = %13
%17 = call i64 @digmd5(i8* %5, i8* %6, i64 %14)
%18 = call i64 @fwrite(i8* %6, i32 1, i64 %17, i32* %1)
%19 = icmp ult i64 %18, %17
br i1 %19, label %20, label %13
20: ; preds = %16
%21 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = call i32 @exit(i32 %22)
unreachable
24: ; preds = %13, %2
%25 = phi i32 [ -1, %2 ], [ 0, %13 ]
ret i32 %25
}