#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 SHA_DIGEST_LENGTH;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ copy_contents(char *, char *);
int /*<<< orphan*/ create_dir(char *);
int /*<<< orphan*/ create_hash(char *, unsigned char *);
int /*<<< orphan*/ make_file_path(char *, char *);
int open_file(char *);
int /*<<< orphan*/ perror(char *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ string_to_hex(unsigned char *, char *);
int main(int argc, char *argv[]) {
  int fd;
  unsigned char hash[SHA_DIGEST_LENGTH];
  char hex_hash[SHA_DIGEST_LENGTH];
  char path[1000];
  char contents[10000];
  char *target = argv[1];
  create_dir(".wil");
  int target_fd = open_file(target);
  if (read(target_fd, contents, 10000) < 0) {
    perror("read");
  }
  create_hash(contents, hash);
  string_to_hex(hash, hex_hash);
  make_file_path(hex_hash, path);
  copy_contents(target, path);
  close(target_fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2b50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%rdx
mov    %rdx,-0x20(%rbp)
mov    %rcx,%rsi
add    $0xf,%rsi
and    $0xfffffffffffffff0,%rsi
mov    %rsp,%rdx
sub    %rsi,%rdx
mov    %rdx,-0x2b50(%rbp)
mov    %rdx,%rsp
mov    %rcx,-0x28(%rbp)
mov    (%rax),%eax
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x2b48(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x2b38(%rbp)
lea    0xdf1(%rip),%rdi
call   1070 <create_dir@plt>
mov    -0x2b38(%rbp),%rdi
call   1030 <open_file@plt>
mov    %eax,-0x2b3c(%rbp)
mov    -0x2b3c(%rbp),%edi
lea    -0x2b30(%rbp),%rsi
mov    $0x2710,%edx
call   1050 <read@plt>
cmp    $0x0,%rax
jge    1253 <main+0xc3>
lea    0xdb7(%rip),%rdi
call   10a0 <perror@plt>
mov    -0x2b50(%rbp),%rsi
lea    -0x2b30(%rbp),%rdi
call   1090 <create_hash@plt>
mov    -0x2b50(%rbp),%rdi
mov    -0x2b48(%rbp),%rsi
call   1080 <string_to_hex@plt>
mov    -0x2b48(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   10b0 <make_file_path@plt>
mov    -0x2b38(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1060 <copy_contents@plt>
mov    -0x2b3c(%rbp),%edi
call   1040 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x2b00,%rsp
mov    0x2e3f(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rbx
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rsp,%r15
sub    %rax,%r15
mov    %r15,%rsp
mov    0x8(%rsi),%r14
lea    0xe30(%rip),%rdi
call   1070 <create_dir@plt>
mov    %r14,%rdi
call   1030 <open_file@plt>
mov    %eax,%r12d
lea    -0x2b20(%rbp),%rsi
mov    %eax,%edi
mov    $0x2710,%edx
call   1050 <read@plt>
test   %rax,%rax
js     1246 <main+0xb6>
lea    -0x2b20(%rbp),%rdi
mov    %rbx,%rsi
call   1090 <create_hash@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1080 <string_to_hex@plt>
lea    -0x410(%rbp),%rbx
mov    %r15,%rdi
mov    %rbx,%rsi
call   10b0 <make_file_path@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1060 <copy_contents@plt>
mov    %r12d,%edi
call   1040 <close@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdb8(%rip),%rdi
call   10a0 <perror@plt>
jmp    11f8 <main+0x68>

LLVM IR (-O0):
@SHA_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c".wil\00"
@.str.1 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca [1000 x i8]
%11 = alloca [10000 x i8]
%12 = alloca i8*
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%14 = load i32, i32* @SHA_DIGEST_LENGTH
%15 = zext i32 %14 to i64
%16 = call i8* @llvm.stacksave()
store i8* %16, i8** %7
%17 = alloca i8, i64 %15
store i64 %15, i64* %8
%18 = load i32, i32* @SHA_DIGEST_LENGTH
%19 = zext i32 %18 to i64
%20 = alloca i8, i64 %19
store i64 %19, i64* %9
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %12
%24 = call i32 @create_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%25 = load i8*, i8** %12
%26 = call i32 @open_file(i8* %25)
store i32 %26, i32* %13
%27 = load i32, i32* %13
%28 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 0
%29 = call i64 @read(i32 %27, i8* %28, i32 10000)
%30 = icmp slt i64 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %2
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %33
33: ; preds = %31, %2
%34 = getelementptr inbounds [10000 x i8], [10000 x i8]* %11, i64 0, i64 0
%35 = call i32 @create_hash(i8* %34, i8* %17)
%36 = call i32 @string_to_hex(i8* %17, i8* %20)
%37 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%38 = call i32 @make_file_path(i8* %20, i8* %37)
%39 = load i8*, i8** %12
%40 = getelementptr inbounds [1000 x i8], [1000 x i8]* %10, i64 0, i64 0
%41 = call i32 @copy_contents(i8* %39, i8* %40)
%42 = load i32, i32* %13
%43 = call i32 @close(i32 %42)
store i32 0, i32* %3
%44 = load i8*, i8** %7
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@SHA_DIGEST_LENGTH = global i32 0
@.str = [5 x i8] c".wil\00"
@.str.1 = [5 x i8] c"read\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = alloca [10000 x i8]
%5 = load i32, i32* @SHA_DIGEST_LENGTH
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = alloca i8, i64 %6
%9 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [10000 x i8], [10000 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = tail call i32 @create_dir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @open_file(i8* %12)
%15 = call i64 @read(i32 %14, i8* %10, i32 10000)
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
br label %19
19: ; preds = %17, %2
%20 = call i32 @create_hash(i8* %10, i8* %7)
%21 = call i32 @string_to_hex(i8* %7, i8* %8)
%22 = call i32 @make_file_path(i8* %8, i8* %9)
%23 = call i32 @copy_contents(i8* %12, i8* %9)
%24 = call i32 @close(i32 %14)
ret i32 0
}