#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 dread(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fwrite(char *, int, int, int /*<<< orphan*/ *);
int getLocationOfCurrent();
void copymem(char *filename) {
  int size = getLocationOfCurrent() + 16;
  char buffer[size];
  FILE *opfile = fopen(filename, "wb");
  int read = dread(buffer, 0, size);
  fwrite(buffer, read, 1, opfile);
  fclose(opfile);
}


x86 assembly (clang, -O0):
<copymem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
xor    %eax,%eax
call   1050 <getLocationOfCurrent@plt>
add    $0x10,%eax
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x38(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe66(%rip),%rsi
call   1060 <fopen@plt>
mov    -0x38(%rbp),%rdi
mov    %rax,-0x28(%rbp)
mov    -0xc(%rbp),%edx
xor    %esi,%esi
call   1040 <dread@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%esi
mov    -0x28(%rbp),%rcx
mov    $0x1,%edx
call   1070 <fwrite@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<copymem>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1050 <getLocationOfCurrent@plt>
lea    0x10(%rax),%r15d
mov    %rsp,%rbx
lea    0xf(%r15),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xe80(%rip),%rsi
mov    %r14,%rdi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    %rbx,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1040 <dread@plt>
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1070 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"wb\00"
define void @copymem(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32*
%7 = alloca i32
store i8* %0, i8** %2
%8 = call i32 (...) @getLocationOfCurrent()
%9 = add nsw i32 %8, 16
store i32 %9, i32* %3
%10 = load i32, i32* %3
%11 = zext i32 %10 to i64
%12 = call i8* @llvm.stacksave()
store i8* %12, i8** %4
%13 = alloca i8, i64 %11
store i64 %11, i64* %5
%14 = load i8*, i8** %2
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %6
%16 = load i32, i32* %3
%17 = call i32 @dread(i8* %13, i32 0, i32 %16)
store i32 %17, i32* %7
%18 = load i32, i32* %7
%19 = load i32*, i32** %6
%20 = call i32 @fwrite(i8* %13, i32 %18, i32 1, i32* %19)
%21 = load i32*, i32** %6
%22 = call i32 @fclose(i32* %21)
%23 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"wb\00"
define void @copymem(i8* nocapture %0) {
%2 = tail call i32 (...) @getLocationOfCurrent()
%3 = add nsw i32 %2, 16
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%7 = call i32 @dread(i8* %5, i32 0, i32 %3)
%8 = call i32 @fwrite(i8* %5, i32 %7, i32 1, i32* %6)
%9 = call i32 @fclose(i32* %6)
ret void
}