#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 Duckfile(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
char EOF;
int /*<<< orphan*/ *OpenFile(char const *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char const *);
int main(int argc, const char *argv[]) {
  if (argc < 2) {
    printf("Bad argument\n");
    return 0;
  }
  FILE *fptr_in = OpenFile(argv[1], "rb");
  char *outputname = malloc(sizeof(char) * 5 + sizeof(char) * 10);
  strcpy(outputname, argv[1]);
  strcat(outputname, ".d");
  if (fptr_in == NULL) {
    printf("Unable to read file. File may not exist.\n");
    return 0;
  }
  FILE *fptr_out = OpenFile(outputname, "wb");
  if (fptr_out == NULL) {
    printf("Unable to write file. Check folder permission.\n");
    return 0;
  }
  int ducking_mode = Duckfile(fptr_in, fptr_out);
  printf("Saved encrypted file as %s\n", outputname);
  fclose(fptr_in);
  fclose(fptr_out);
  if (ducking_mode == 0) {
    char prev;
    FILE *preview_ptr = OpenFile(outputname, "rb");
    printf("\n\n ======== Unducked Contents ========\n\n");
    do {
      prev = fgetc(preview_ptr);
      printf("%c", prev);
    } while (prev != EOF);
    fclose(preview_ptr);
  }
  printf("\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11ba <main+0x3a>
lea    0xe59(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <main+0x191>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe45(%rip),%rsi
call   1030 <OpenFile@plt>
mov    %rax,-0x18(%rbp)
mov    $0xf,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1040 <strcpy@plt>
mov    -0x20(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   10a0 <strcat@plt>
cmpq   $0x0,-0x18(%rbp)
jne    1226 <main+0xa6>
lea    0xe01(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <main+0x191>
mov    -0x20(%rbp),%rdi
lea    0xe0d(%rip),%rsi
call   1030 <OpenFile@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    125f <main+0xdf>
lea    0xdf5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1311 <main+0x191>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <Duckfile@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rsi
lea    0xdf7(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x0,-0x2c(%rbp)
jne    12fc <main+0x17c>
mov    -0x20(%rbp),%rdi
lea    0xd66(%rip),%rsi
call   1030 <OpenFile@plt>
mov    %rax,-0x38(%rbp)
lea    0xdd5(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x38(%rbp),%rdi
call   1070 <fgetc@plt>
mov    %al,-0x2d(%rbp)
movsbl -0x2d(%rbp),%esi
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movsbl -0x2d(%rbp),%eax
mov    0x2d00(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
jne    12bf <main+0x13f>
mov    -0x38(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xdb1(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x1,%edi
jg     11b9 <main+0x19>
lea    0xef1(%rip),%rdi
jmp    12bb <main+0x11b>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe39(%rip),%rsi
call   1040 <OpenFile@plt>
mov    %rax,%r14
mov    $0xf,%edi
call   10b0 <malloc@plt>
mov    %rax,%r12
mov    0x8(%rbx),%rsi
mov    %rax,%rdi
call   1050 <strcpy@plt>
lea    0xe14(%rip),%rsi
mov    %r12,%rdi
call   10c0 <strcat@plt>
test   %r14,%r14
je     12ab <main+0x10b>
lea    0xdff(%rip),%rsi
mov    %r12,%rdi
call   1040 <OpenFile@plt>
test   %rax,%rax
je     12b4 <main+0x114>
mov    %rax,%r15
mov    %r14,%rdi
mov    %rax,%rsi
call   10a0 <Duckfile@plt>
mov    %eax,%ebx
lea    0xdda(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1080 <printf@plt>
mov    %r14,%rdi
call   1070 <fclose@plt>
mov    %r15,%rdi
call   1070 <fclose@plt>
test   %ebx,%ebx
jne    129f <main+0xff>
lea    0xdac(%rip),%rsi
mov    %r12,%rdi
call   1040 <OpenFile@plt>
mov    %rax,%rbx
lea    0xdbf(%rip),%rdi
call   1060 <puts@plt>
mov    0x2d76(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
call   1090 <fgetc@plt>
movsbl %al,%ebp
mov    %ebp,%edi
call   1030 <putchar@plt>
cmp    (%r14),%bpl
jne    1280 <main+0xe0>
mov    %rbx,%rdi
call   1070 <fclose@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
jmp    12c0 <main+0x120>
lea    0xdca(%rip),%rdi
jmp    12bb <main+0x11b>
lea    0xd92(%rip),%rdi
call   1060 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"Bad argument\0A\00"
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c".d\00"
@.str.3 = [42 x i8] c"Unable to read file. File may not exist.\0A\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.5 = [48 x i8] c"Unable to write file. Check folder permission.\0A\00"
@.str.6 = [28 x i8] c"Saved encrypted file as %s\0A\00"
@.str.7 = [41 x i8] c"\0A\0A ======== Unducked Contents ========\0A\0A\00"
@.str.8 = [3 x i8] c"%c\00"
@EOF = global i8 0
@.str.9 = [2 x i8] c"\0A\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 i32*
%9 = alloca i32
%10 = alloca i8
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %16
14: ; preds = %2
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
br label %73
16: ; preds = %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32* @OpenFile(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %6
%21 = call i8* @malloc(i32 15)
store i8* %21, i8** %7
%22 = load i8*, i8** %7
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = call i32 @strcpy(i8* %22, i8* %25)
%27 = load i8*, i8** %7
%28 = call i32 @strcat(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%29 = load i32*, i32** %6
%30 = icmp eq i32* %29, null
br i1 %30, label %31, label %33
31: ; preds = %16
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
br label %73
33: ; preds = %16
%34 = load i8*, i8** %7
%35 = call i32* @OpenFile(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32* %35, i32** %8
%36 = load i32*, i32** %8
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %40
38: ; preds = %33
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %3
br label %73
40: ; preds = %33
%41 = load i32*, i32** %6
%42 = load i32*, i32** %8
%43 = call i32 @Duckfile(i32* %41, i32* %42)
store i32 %43, i32* %9
%44 = load i8*, i8** %7
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %44)
%46 = load i32*, i32** %6
%47 = call i32 @fclose(i32* %46)
%48 = load i32*, i32** %8
%49 = call i32 @fclose(i32* %48)
%50 = load i32, i32* %9
%51 = icmp eq i32 %50, 0
br i1 %51, label %52, label %71
52: ; preds = %40
%53 = load i8*, i8** %7
%54 = call i32* @OpenFile(i8* %53, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %54, i32** %11
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.7, i64 0, i64 0))
br label %56
56: ; preds = %62, %52
%57 = load i32*, i32** %11
%58 = call signext i8 @fgetc(i32* %57)
store i8 %58, i8* %10
%59 = load i8, i8* %10
%60 = sext i8 %59 to i32
%61 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i32 %60)
br label %62
62: ; preds = %56
%63 = load i8, i8* %10
%64 = sext i8 %63 to i32
%65 = load i8, i8* @EOF
%66 = sext i8 %65 to i32
%67 = icmp ne i32 %64, %66
br i1 %67, label %56, label %68
68: ; preds = %62
%69 = load i32*, i32** %11
%70 = call i32 @fclose(i32* %69)
br label %71
71: ; preds = %68, %40
%72 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.9, i64 0, i64 0))
store i32 0, i32* %3
br label %73
73: ; preds = %71, %38, %31, %14
%74 = load i32, i32* %3
ret i32 %74
}

LLVM IR (-O2):
@.str.1 = [3 x i8] c"rb\00"
@.str.2 = [3 x i8] c".d\00"
@.str.4 = [3 x i8] c"wb\00"
@.str.6 = [28 x i8] c"Saved encrypted file as %s\0A\00"
@EOF = global i8 0
@str = [40 x i8] c"\0A\0A ======== Unducked Contents ========\0A\00"
@str.10 = [47 x i8] c"Unable to write file. Check folder permission.\00"
@str.11 = [41 x i8] c"Unable to read file. File may not exist.\00"
@str.12 = [13 x i8] c"Bad argument\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %6
4: ; preds = %2
%5 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
br label %41
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @OpenFile(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call dereferenceable_or_null(15) i8* @malloc(i32 15)
%11 = load i8*, i8** %7
%12 = tail call i32 @strcpy(i8* %10, i8* %11)
%13 = tail call i32 @strcat(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%14 = icmp eq i32* %9, null
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([41 x i8], [41 x i8]* @str.11, i64 0, i64 0))
br label %41
17: ; preds = %6
%18 = tail call i32* @OpenFile(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%19 = icmp eq i32* %18, null
br i1 %19, label %20, label %22
20: ; preds = %17
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([47 x i8], [47 x i8]* @str.10, i64 0, i64 0))
br label %41
22: ; preds = %17
%23 = tail call i32 @Duckfile(i32* %9, i32* %18)
%24 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @.str.6, i64 0, i64 0), i8* %10)
%25 = tail call i32 @fclose(i32* %9)
%26 = tail call i32 @fclose(i32* %18)
%27 = icmp eq i32 %23, 0
br i1 %27, label %28, label %39
28: ; preds = %22
%29 = tail call i32* @OpenFile(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%30 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str, i64 0, i64 0))
br label %31
31: ; preds = %31, %28
%32 = tail call signext i8 @fgetc(i32* %29)
%33 = sext i8 %32 to i32
%34 = tail call i32 @putchar(i32 %33)
%35 = load i8, i8* @EOF
%36 = icmp eq i8 %32, %35
br i1 %36, label %37, label %31
37: ; preds = %31
%38 = tail call i32 @fclose(i32* %29)
br label %39
39: ; preds = %37, %22
%40 = tail call i32 @putchar(i32 10)
br label %41
41: ; preds = %15, %39, %20, %4
ret i32 0
}