#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 *);
int /*<<< orphan*/ getchar();
char *malloc(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
char *realloc(char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
void test2() {
  char *x, *y;
  printf("newlib malloc test\n");
  x = malloc(0x5000);
  memset(x, 1, 0x5000);
  printf("x: %p\n", x);
  y = malloc(0x100000);
  memset(y, 1, 0x10000);
  printf("y: %p\n", y);
  x = realloc(x, 0x100000);
  printf("x: %p\n", x);
  strcpy(x, "asd");
  free(x);
  free(y);
  y = malloc(0x1000000);
  memset(y, 1, 0x1000000);
  printf("y: %p\n", y);
  printf("devam etmek icin bir tusa basin\n");
  getchar();
  free(y);
  printf("devam etmek icin bir tusa basin\n");
  getchar();
  printf("newlib malloc test OK\n");
}


x86 assembly (clang, -O0):
<test2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xe81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x5000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x1,%esi
mov    $0x5000,%edx
call   1060 <memset@plt>
mov    -0x8(%rbp),%rsi
lea    0xe62(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x100000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rsi
lea    0xe36(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
mov    $0x100000,%esi
call   1090 <realloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rsi
lea    0xe0b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe07(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1000000,%edi
call   1080 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x1,%esi
mov    $0x1000000,%edx
call   1060 <memset@plt>
mov    -0x10(%rbp),%rsi
lea    0xdbd(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xdba(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
lea    0xd9c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    $0x0,%al
call   1070 <getchar@plt>
lea    0xda8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe83(%rip),%rdi
call   1050 <puts@plt>
mov    $0x5000,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x5000,%edx
call   1070 <memset@plt>
lea    0xe46(%rip),%r12
mov    %r12,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0x100000,%edi
call   1090 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x10000,%edx
call   1070 <memset@plt>
lea    0xe1a(%rip),%r14
mov    %r14,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %rbx,%rdi
mov    $0x100000,%esi
call   10a0 <realloc@plt>
mov    %rax,%rbx
mov    %r12,%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdf0(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r15,%rdi
call   1030 <free@plt>
mov    $0x1000000,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    $0x1000000,%edx
call   1070 <memset@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xdbc(%rip),%r14
mov    %r14,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r14,%rdi
call   1050 <puts@plt>
xor    %eax,%eax
call   1080 <getchar@plt>
lea    0xdaf(%rip),%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <puts@plt>

LLVM IR (-O0):
@.str = [20 x i8] c"newlib malloc test\0A\00"
@.str.1 = [7 x i8] c"x: %p\0A\00"
@.str.2 = [7 x i8] c"y: %p\0A\00"
@.str.3 = [4 x i8] c"asd\00"
@.str.4 = [33 x i8] c"devam etmek icin bir tusa basin\0A\00"
@.str.5 = [23 x i8] c"newlib malloc test OK\0A\00"
define void @test2() {
%1 = alloca i8*
%2 = alloca i8*
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%4 = call i8* @malloc(i32 20480)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @memset(i8* %5, i32 1, i32 20480)
%7 = load i8*, i8** %1
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%9 = call i8* @malloc(i32 1048576)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = call i32 @memset(i8* %10, i32 1, i32 65536)
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %1
%15 = call i8* @realloc(i8* %14, i32 1048576)
store i8* %15, i8** %1
%16 = load i8*, i8** %1
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %16)
%18 = load i8*, i8** %1
%19 = call i32 @strcpy(i8* %18, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%20 = load i8*, i8** %1
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** %2
%23 = call i32 @free(i8* %22)
%24 = call i8* @malloc(i32 16777216)
store i8* %24, i8** %2
%25 = load i8*, i8** %2
%26 = call i32 @memset(i8* %25, i32 1, i32 16777216)
%27 = load i8*, i8** %2
%28 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %27)
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%30 = call i32 (...) @getchar()
%31 = load i8*, i8** %2
%32 = call i32 @free(i8* %31)
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%34 = call i32 (...) @getchar()
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"x: %p\0A\00"
@.str.2 = [7 x i8] c"y: %p\0A\00"
@.str.3 = [4 x i8] c"asd\00"
@str = [19 x i8] c"newlib malloc test\00"
@str.7 = [32 x i8] c"devam etmek icin bir tusa basin\00"
@str.8 = [22 x i8] c"newlib malloc test OK\00"
define void @test2() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @str, i64 0, i64 0))
%2 = tail call dereferenceable_or_null(20480) i8* @malloc(i32 20480)
%3 = tail call i32 @memset(i8* %2, i32 1, i32 20480)
%4 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %2)
%5 = tail call dereferenceable_or_null(1048576) i8* @malloc(i32 1048576)
%6 = tail call i32 @memset(i8* %5, i32 1, i32 65536)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%8 = tail call i8* @realloc(i8* %2, i32 1048576)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8* %8)
%10 = tail call i32 @strcpy(i8* %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0))
%11 = tail call i32 @free(i8* %8)
%12 = tail call i32 @free(i8* %5)
%13 = tail call dereferenceable_or_null(16777216) i8* @malloc(i32 16777216)
%14 = tail call i32 @memset(i8* %13, i32 1, i32 16777216)
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i8* %13)
%16 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
%17 = tail call i32 (...) @getchar()
%18 = tail call i32 @free(i8* %13)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.7, i64 0, i64 0))
%20 = tail call i32 (...) @getchar()
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.8, i64 0, i64 0))
ret void
}