#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ free(int *);
scalar_t__ malloc(unsigned int);
int /*<<< orphan*/ memcpy(int *, int *, unsigned int);
int /*<<< orphan*/ sleep(int);
unsigned int strtoul(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  if (argc != 2) {
    exit(0);
  }
  unsigned int use_memory;
  unsigned int max_memory;
  use_memory = strtoul(argv[1], NULL, 10);
  max_memory = use_memory * 1024 * 1024 / 2;
  int *a;
  a = (int *)malloc(max_memory);
  int *c;
  c = (int *)malloc(max_memory);
  while (1) {
    memcpy(c, a, max_memory);
    memcpy(a, c, max_memory);
    sleep(2);
    free(a);
    free(c);
    a = (int *)malloc(max_memory);
    c = (int *)malloc(max_memory);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1187 <main+0x27>
xor    %edi,%edi
call   1070 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%eax
shl    $0xa,%eax
shl    $0xa,%eax
shr    $0x1,%eax
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x18(%rbp),%edx
call   1040 <memcpy@plt>
mov    $0x2,%edi
call   1080 <sleep@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x28(%rbp)
jmp    11c7 <main+0x67>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11fe <main+0x9e>
mov    0x8(%rsi),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtoul@plt>
mov    %eax,%r14d
shl    $0x13,%r14d
and    $0x7ff80000,%r14d
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
mov    %r14d,%edx
call   1040 <memcpy@plt>
mov    $0x2,%edi
call   1080 <sleep@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbx
mov    %r14d,%edi
call   1050 <malloc@plt>
mov    %rax,%rbp
jmp    11b0 <main+0x50>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
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*
%9 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 2
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i32 @strtoul(i8* %17, i32* null, i32 10)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = mul i32 %19, 1024
%21 = mul i32 %20, 1024
%22 = udiv i32 %21, 2
store i32 %22, i32* %7
%23 = load i32, i32* %7
%24 = call i64 @malloc(i32 %23)
%25 = inttoptr i64 %24 to i32*
store i32* %25, i32** %8
%26 = load i32, i32* %7
%27 = call i64 @malloc(i32 %26)
%28 = inttoptr i64 %27 to i32*
store i32* %28, i32** %9
br label %29
29: ; preds = %14, %29
%30 = load i32*, i32** %9
%31 = load i32*, i32** %8
%32 = load i32, i32* %7
%33 = call i32 @memcpy(i32* %30, i32* %31, i32 %32)
%34 = load i32*, i32** %8
%35 = load i32*, i32** %9
%36 = load i32, i32* %7
%37 = call i32 @memcpy(i32* %34, i32* %35, i32 %36)
%38 = call i32 @sleep(i32 2)
%39 = load i32*, i32** %8
%40 = call i32 @free(i32* %39)
%41 = load i32*, i32** %9
%42 = call i32 @free(i32* %41)
%43 = load i32, i32* %7
%44 = call i64 @malloc(i32 %43)
%45 = inttoptr i64 %44 to i32*
store i32* %45, i32** %8
%46 = load i32, i32* %7
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i32*
store i32* %48, i32** %9
br label %29
}

LLVM IR (-O2):
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %6, label %4
4: ; preds = %2
%5 = tail call i32 @exit(i32 0)
unreachable
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32 @strtoul(i8* nocapture %8, i32* null, i32 10)
%10 = shl i32 %9, 19
%11 = and i32 %10, 2146959360
%12 = tail call i64 @malloc(i32 %11)
%13 = tail call i64 @malloc(i32 %11)
br label %14
14: ; preds = %14, %6
%15 = phi i64 [ %12, %6 ], [ %24, %14 ]
%16 = phi i64 [ %13, %6 ], [ %25, %14 ]
%17 = inttoptr i64 %16 to i32*
%18 = inttoptr i64 %15 to i32*
%19 = tail call i32 @memcpy(i32* %17, i32* %18, i32 %11)
%20 = tail call i32 @memcpy(i32* %18, i32* %17, i32 %11)
%21 = tail call i32 @sleep(i32 2)
%22 = tail call i32 @free(i32* %18)
%23 = tail call i32 @free(i32* %17)
%24 = tail call i64 @malloc(i32 %11)
%25 = tail call i64 @malloc(i32 %11)
br label %14
}