#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*/ newpath;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int PATH_MAX;
int /*<<< orphan*/ chdir(char *);
char *dirname(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ find_yourself(char *, int);
int /*<<< orphan*/ findyourself_init(char *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(int /*<<< orphan*/, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *);
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int main(int argc, char **argv) {
  findyourself_init(argv[0]);
  char newpath[PATH_MAX];
  find_yourself(newpath, sizeof(newpath));
  if (1 || strcmp(argv[0], newpath)) {
  }
  char *dummy = strdup(newpath);
  char *dname = dirname(dummy);
  printf("Extracting...\n");
  extern char _binary__bin_bash_start;
  extern char _binary__bin_bash_size;
  extern char _binary__bin_bash_end;
  char *p = &_binary__bin_bash_start;
  FILE *fp;
  chdir(dname);
  fp = fopen("bash", ("w+"));
  while (p != &_binary__bin_bash_end)
    fputc(*p++, fp);
  fclose(fp);
  free(dummy);
  printf("Extracted\n");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   10a0 <findyourself_init@plt>
mov    0x2e27(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x48(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%esi
call   1070 <find_yourself@plt>
mov    -0x48(%rbp),%rdi
call   10c0 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1080 <dirname@plt>
mov    %rax,-0x30(%rbp)
lea    0xdea(%rip),%rdi
call   1060 <printf@plt>
mov    0x2dbe(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <chdir@plt>
lea    0xdd9(%rip),%rdi
lea    0xdd7(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    0x2d83(%rip),%rax
cmp    %rax,-0x38(%rbp)
je     1277 <main+0xd7>
mov    -0x38(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x38(%rbp)
movsbl (%rax),%edi
mov    -0x40(%rbp),%rsi
call   1090 <fputc@plt>
jmp    1246 <main+0xa6>
mov    -0x40(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
lea    0xd87(%rip),%rdi
call   1060 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x18(%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
mov    (%rsi),%rdi
call   10a0 <findyourself_init@plt>
mov    0x2e36(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
mov    %rbx,%rdi
call   1070 <find_yourself@plt>
mov    %rbx,%rdi
call   10c0 <strdup@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1080 <dirname@plt>
mov    %rax,%rbx
lea    0xe13(%rip),%rdi
call   1040 <puts@plt>
mov    %rbx,%rdi
call   1060 <chdir@plt>
lea    0xdf7(%rip),%rdi
lea    0xdf5(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,%r15
mov    0x2dc1(%rip),%rbx
mov    0x2daa(%rip),%r12
cs nopw 0x0(%rax,%rax,1)
movsbl (%rbx),%edi
add    $0x1,%rbx
mov    %r15,%rsi
call   1090 <fputc@plt>
cmp    %r12,%rbx
jne    1230 <main+0x90>
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r14,%rdi
call   1030 <free@plt>
lea    0xdbb(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
lea    -0x20(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@PATH_MAX = global i32 0
@.str = [15 x i8] c"Extracting...\0A\00"
@_binary__bin_bash_start = external global i8
@.str.1 = [5 x i8] c"bash\00"
@.str.2 = [3 x i8] c"w+\00"
@_binary__bin_bash_end = external global i8
@.str.3 = [11 x i8] c"Extracted\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @findyourself_init(i8* %14)
%16 = load i32, i32* @PATH_MAX
%17 = zext i32 %16 to i64
%18 = call i8* @llvm.stacksave()
store i8* %18, i8** %6
%19 = alloca i8, i64 %17
store i64 %17, i64* %7
%20 = trunc i64 %17 to i32
%21 = call i32 @find_yourself(i8* %19, i32 %20)
%22 = call i8* @strdup(i8* %19)
store i8* %22, i8** %8
%23 = load i8*, i8** %8
%24 = call i8* @dirname(i8* %23)
store i8* %24, i8** %9
%25 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
store i8* @_binary__bin_bash_start, i8** %10
%26 = load i8*, i8** %9
%27 = call i32 @chdir(i8* %26)
%28 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
store i32* %28, i32** %11
br label %29
29: ; preds = %32, %2
%30 = load i8*, i8** %10
%31 = icmp ne i8* %30, @_binary__bin_bash_end
br i1 %31, label %32, label %39
32: ; preds = %29
%33 = load i8*, i8** %10
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %10
%35 = load i8, i8* %33
%36 = sext i8 %35 to i32
%37 = load i32*, i32** %11
%38 = call i32 @fputc(i32 %36, i32* %37)
br label %29
39: ; preds = %29
%40 = load i32*, i32** %11
%41 = call i32 @fclose(i32* %40)
%42 = load i8*, i8** %8
%43 = call i32 @free(i8* %42)
%44 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %3
%45 = load i8*, i8** %6
%46 = load i32, i32* %3
ret i32 %46
}

LLVM IR (-O2):
@PATH_MAX = global i32 0
@_binary__bin_bash_start = external global i8
@.str.1 = [5 x i8] c"bash\00"
@.str.2 = [3 x i8] c"w+\00"
@_binary__bin_bash_end = external global i8
@str = [14 x i8] c"Extracting...\00"
@str.4 = [10 x i8] c"Extracted\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = load i8*, i8** %1
%4 = tail call i32 @findyourself_init(i8* %3)
%5 = load i32, i32* @PATH_MAX
%6 = zext i32 %5 to i64
%7 = alloca i8, i64 %6
%8 = call i32 @find_yourself(i8* %7, i32 %5)
%9 = call i8* @strdup(i8* %7)
%10 = call i8* @dirname(i8* %9)
%11 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str, i64 0, i64 0))
%12 = call i32 @chdir(i8* %10)
%13 = call i32* @fopen(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
br label %14
14: ; preds = %2, %14
%15 = phi i8* [ @_binary__bin_bash_start, %2 ], [ %16, %14 ]
%16 = getelementptr inbounds i8, i8* %15, i64 1
%17 = load i8, i8* %15
%18 = sext i8 %17 to i32
%19 = call i32 @fputc(i32 %18, i32* %13)
%20 = icmp eq i8* %16, @_binary__bin_bash_end
br i1 %20, label %21, label %14
21: ; preds = %14
%22 = call i32 @fclose(i32* %13)
%23 = call i32 @free(i8* %9)
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @str.4, i64 0, i64 0))
ret i32 0
}