#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(void *);
void *malloc(int);
int /*<<< orphan*/ strcpy(void *, char *);
int /*<<< orphan*/ unit_test_int(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ unit_test_str(char *, char *, void *);
void test_malloc() {
  void *a = malloc(100);
  unit_test_int("malloc(100) doit retourner un pointeur non null.", 1,
                a != NULL);
  free(a);
  void *b = malloc(sizeof(char) * 101);
  strcpy(b, "123456789012345678901234567890123456789012345678901234567890123456"
            "7890123456789012345678901234567890");
  unit_test_str("strcpy dans un buffer alloué avec malloc",
                "12345678901234567890123456789012345678901234567890123456789012"
                "34567890123456789012345678901234567890",
                b);
  free(b);
  void *c = malloc(sizeof(char) * 1000000);
  strcpy(c, "Test");
  unit_test_str("strcpy dans un buffer de 1mo", "Test", c);
  free(c);
}


x86 assembly (clang, -O0):
<test_malloc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edx
lea    0xe86(%rip),%rdi
mov    $0x1,%esi
call   1050 <unit_test_int@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
mov    $0x65,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x10(%rbp),%rdx
lea    0xee0(%rip),%rdi
lea    0xe74(%rip),%rsi
call   1070 <unit_test_str@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    $0xf4240,%edi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xedc(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rdx
lea    0xed1(%rip),%rdi
lea    0xec5(%rip),%rsi
call   1070 <unit_test_str@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_malloc>:
push   %r14
push   %rbx
push   %rax
mov    $0x64,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
xor    %edx,%edx
test   %rax,%rax
setne  %dl
lea    0xe90(%rip),%rdi
mov    $0x1,%esi
call   1050 <unit_test_int@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x65,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xe9b(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xeee(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <unit_test_str@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0xf4240,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xef1(%rip),%r14
mov    %rax,%rdi
mov    %r14,%rsi
call   1040 <strcpy@plt>
lea    0xee4(%rip),%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
call   1070 <unit_test_str@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <free@plt>

LLVM IR (-O0):
@.str = [49 x i8] c"malloc(100) doit retourner un pointeur non null.\00"
@.str.1 = [101 x i8] c"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\00"
@.str.2 = [42 x i8] c"strcpy dans un buffer allou\C3\A9 avec malloc\00"
@.str.3 = [5 x i8] c"Test\00"
@.str.4 = [29 x i8] c"strcpy dans un buffer de 1mo\00"
define void @test_malloc() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca i8*
%4 = call i8* @malloc(i32 100)
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @unit_test_int(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 1, i32 %7)
%9 = load i8*, i8** %1
%10 = call i32 @free(i8* %9)
%11 = call i8* @malloc(i32 101)
store i8* %11, i8** %2
%12 = load i8*, i8** %2
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.1, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @unit_test_str(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = load i8*, i8** %2
%17 = call i32 @free(i8* %16)
%18 = call i8* @malloc(i32 1000000)
store i8* %18, i8** %3
%19 = load i8*, i8** %3
%20 = call i32 @strcpy(i8* %19, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%21 = load i8*, i8** %3
%22 = call i32 @unit_test_str(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %21)
%23 = load i8*, i8** %3
%24 = call i32 @free(i8* %23)
ret void
}

LLVM IR (-O2):
@.str = [49 x i8] c"malloc(100) doit retourner un pointeur non null.\00"
@.str.1 = [101 x i8] c"1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\00"
@.str.2 = [42 x i8] c"strcpy dans un buffer allou\C3\A9 avec malloc\00"
@.str.3 = [5 x i8] c"Test\00"
@.str.4 = [29 x i8] c"strcpy dans un buffer de 1mo\00"
define void @test_malloc() {
%1 = tail call dereferenceable_or_null(100) i8* @malloc(i32 100)
%2 = icmp ne i8* %1, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @unit_test_int(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str, i64 0, i64 0), i32 1, i32 %3)
%5 = tail call i32 @free(i8* %1)
%6 = tail call dereferenceable_or_null(101) i8* @malloc(i32 101)
%7 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @unit_test_str(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([101 x i8], [101 x i8]* @.str.1, i64 0, i64 0), i8* %6)
%9 = tail call i32 @free(i8* %6)
%10 = tail call dereferenceable_or_null(1000000) i8* @malloc(i32 1000000)
%11 = tail call i32 @strcpy(i8* %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%12 = tail call i32 @unit_test_str(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %10)
%13 = tail call i32 @free(i8* %10)
ret void
}