#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 */
scalar_t__ MD4(unsigned char *, int, unsigned char *);
int MD4_DIGEST_LENGTH;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ write_file(char *, unsigned char *, int);
int task3(unsigned char *plain, int plain_bytes, char *file_name) {
  printf("\nAufgabe 3:\n");
  unsigned char buf_digest[MD4_DIGEST_LENGTH];
  char output[16384];
  int ret = 0;
  if (MD4(plain, plain_bytes, buf_digest) == 0) {
    strcpy(output, "\tError when hashing plaintext\n");
  } else if (write_file(file_name, buf_digest, MD4_DIGEST_LENGTH)) {
    strcpy(output, "\tSuccessfully hashed plaintext to file ");
    strcat(output, file_name);
    strcat(output, "\n");
    ret = 1;
  } else {
    strcpy(output, "\tError when writing hash to file ");
    strcat(output, file_name);
    strcat(output, "\n");
  }
  printf(output);
  return ret;
}


x86 assembly (clang, -O0):
<task3>:
push   %rbp
mov    %rsp,%rbp
sub    $0x4040,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    0xe93(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e7f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x20(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdx
sub    %rcx,%rdx
mov    %rdx,-0x4040(%rbp)
mov    %rdx,%rsp
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x4034(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
call   1040 <MD4@plt>
cmp    $0x0,%rax
jne    11d9 <task3+0x89>
lea    -0x4030(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1030 <strcpy@plt>
jmp    127c <task3+0x12c>
mov    -0x4040(%rbp),%rsi
mov    -0x18(%rbp),%rdi
mov    0x2e0d(%rip),%rax
mov    (%rax),%edx
call   1060 <write_file@plt>
cmp    $0x0,%rax
je     1241 <task3+0xf1>
lea    -0x4030(%rbp),%rdi
lea    0xe22(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x4030(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x4030(%rbp),%rdi
lea    0xdde(%rip),%rsi
call   1070 <strcat@plt>
movl   $0x1,-0x4034(%rbp)
jmp    1277 <task3+0x127>
lea    -0x4030(%rbp),%rdi
lea    0xe05(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x4030(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strcat@plt>
lea    -0x4030(%rbp),%rdi
lea    0xd99(%rip),%rsi
call   1070 <strcat@plt>
jmp    127c <task3+0x12c>
lea    -0x4030(%rbp),%rdi
call   1050 <printf@plt>
mov    -0x4034(%rbp),%eax
mov    -0x20(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<task3>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x4008,%rsp
mov    %rdx,%r14
mov    %esi,%r15d
mov    %rdi,%r12
lea    0xee5(%rip),%rdi
call   1040 <puts@plt>
mov    0x2e68(%rip),%r13
mov    0x0(%r13),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %r12,%rdi
mov    %r15d,%esi
mov    %rbx,%rdx
call   1050 <MD4@plt>
test   %rax,%rax
je     1203 <task3+0xa3>
mov    0x0(%r13),%edx
mov    %r14,%rdi
mov    %rbx,%rsi
call   1070 <write_file@plt>
test   %rax,%rax
je     1218 <task3+0xb8>
lea    0xe4c(%rip),%rsi
lea    -0x4030(%rbp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
mov    $0x1,%ebx
jmp    124a <task3+0xea>
lea    0xdf6(%rip),%rsi
lea    -0x4030(%rbp),%rdi
call   1030 <strcpy@plt>
jmp    1248 <task3+0xe8>
lea    0xe28(%rip),%rsi
lea    -0x4030(%rbp),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1080 <strcat@plt>
lea    0xddd(%rip),%rsi
mov    %rbx,%rdi
call   1080 <strcat@plt>
xor    %ebx,%ebx
lea    -0x4030(%rbp),%rdi
call   1060 <printf@plt>
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"\0AAufgabe 3:\0A\00"
@MD4_DIGEST_LENGTH = global i32 0
@.str.1 = [31 x i8] c"\09Error when hashing plaintext\0A\00"
@.str.2 = [40 x i8] c"\09Successfully hashed plaintext to file \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [34 x i8] c"\09Error when writing hash to file \00"
define i32 @task3(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca [16384 x i8]
%10 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%11 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = load i32, i32* @MD4_DIGEST_LENGTH
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %7
%15 = alloca i8, i64 %13
store i64 %13, i64* %8
store i32 0, i32* %10
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = call i64 @MD4(i8* %16, i32 %17, i8* %15)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %3
%21 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %45
23: ; preds = %3
%24 = load i8*, i8** %6
%25 = load i32, i32* @MD4_DIGEST_LENGTH
%26 = call i64 @write_file(i8* %24, i8* %15, i32 %25)
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %23
%29 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%30 = call i32 @strcpy(i8* %29, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%31 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%32 = load i8*, i8** %6
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %10
br label %44
36: ; preds = %23
%37 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%38 = call i32 @strcpy(i8* %37, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%39 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%40 = load i8*, i8** %6
%41 = call i32 @strcat(i8* %39, i8* %40)
%42 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%43 = call i32 @strcat(i8* %42, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %44
44: ; preds = %36, %28
br label %45
45: ; preds = %44, %20
%46 = getelementptr inbounds [16384 x i8], [16384 x i8]* %9, i64 0, i64 0
%47 = call i32 @printf(i8* %46)
%48 = load i32, i32* %10
%49 = load i8*, i8** %7
ret i32 %48
}

LLVM IR (-O2):
@MD4_DIGEST_LENGTH = global i32 0
@.str.1 = [31 x i8] c"\09Error when hashing plaintext\0A\00"
@.str.2 = [40 x i8] c"\09Successfully hashed plaintext to file \00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [34 x i8] c"\09Error when writing hash to file \00"
@str = [12 x i8] c"\0AAufgabe 3:\00"
define i32 @task3(i8* %0, i32 %1, i8* %2) {
%4 = alloca [16384 x i8]
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%6 = load i32, i32* @MD4_DIGEST_LENGTH
%7 = zext i32 %6 to i64
%8 = alloca i8, i64 %7
%9 = getelementptr inbounds [16384 x i8], [16384 x i8]* %4, i64 0, i64 0
%10 = call i64 @MD4(i8* %0, i32 %1, i8* %8)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %14
12: ; preds = %3
%13 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0))
br label %26
14: ; preds = %3
%15 = load i32, i32* @MD4_DIGEST_LENGTH
%16 = call i64 @write_file(i8* %2, i8* %8, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.2, i64 0, i64 0))
%20 = call i32 @strcat(i8* %9, i8* %2)
%21 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %26
22: ; preds = %14
%23 = call i32 @strcpy(i8* %9, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0))
%24 = call i32 @strcat(i8* %9, i8* %2)
%25 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %18, %22, %12
%27 = phi i32 [ 0, %12 ], [ 1, %18 ], [ 0, %22 ]
%28 = call i32 @printf(i8* %9)
ret i32 %27
}