#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 */
scalar_t__ checkblock(unsigned int volatile *, int, int /*<<< orphan*/,
                      int /*<<< orphan*/);
int /*<<< orphan*/ free(void *);
unsigned int *malloc(int);
int /*<<< orphan*/ markblock(unsigned int volatile *, int, int /*<<< orphan*/,
                             int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
void test1(void) {
  volatile unsigned *x;
  printf("*** Malloc test 1 ***\n");
  printf("Allocating %u bytes\n", 16384);
  x = malloc(16384);
  if (x == NULL) {
    printf("FAILED: malloc failed\n");
    return;
  }
  markblock(x, 16384, 0, 0);
  if (checkblock(x, 16384, 0, 0)) {
    printf("FAILED: data corrupt\n");
    return;
  }
  free((void *)x);
  printf("Passed malloc test 1.\n");
}


x86 assembly (clang, -O0):
<test1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xea1(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xeaa(%rip),%rdi
mov    $0x4000,%esi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x4000,%edi
call   1050 <malloc@plt>
mov    %rax,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    11a5 <test1+0x55>
lea    0xe93(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fd <test1+0xad>
mov    -0x8(%rbp),%rdi
mov    $0x4000,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1060 <markblock@plt>
mov    -0x8(%rbp),%rdi
mov    $0x4000,%esi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1070 <checkblock@plt>
cmp    $0x0,%rax
je     11e6 <test1+0x96>
lea    0xe69(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11fd <test1+0xad>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
lea    0xe63(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test1>:
push   %rbx
lea    0xead(%rip),%rdi
call   1040 <puts@plt>
lea    0xe8c(%rip),%rdi
mov    $0x4000,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x4000,%edi
call   1060 <malloc@plt>
test   %rax,%rax
je     11c6 <test1+0x66>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x4000,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <markblock@plt>
mov    %rbx,%rdi
mov    $0x4000,%esi
xor    %edx,%edx
xor    %ecx,%ecx
call   1080 <checkblock@plt>
test   %rax,%rax
je     11d3 <test1+0x73>
lea    0xe81(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>
lea    0xe89(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xe49(%rip),%rdi
pop    %rbx
jmp    1040 <puts@plt>

LLVM IR (-O0):
@.str = [23 x i8] c"*** Malloc test 1 ***\0A\00"
@.str.1 = [21 x i8] c"Allocating %u bytes\0A\00"
@.str.2 = [23 x i8] c"FAILED: malloc failed\0A\00"
@.str.3 = [22 x i8] c"FAILED: data corrupt\0A\00"
@.str.4 = [23 x i8] c"Passed malloc test 1.\0A\00"
define void @test1() {
%1 = alloca i32*
%2 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
%3 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 16384)
%4 = call i32* @malloc(i32 16384)
store i32* %4, i32** %1
%5 = load i32*, i32** %1
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
br label %22
9: ; preds = %0
%10 = load i32*, i32** %1
%11 = call i32 @markblock(i32* %10, i32 16384, i32 0, i32 0)
%12 = load i32*, i32** %1
%13 = call i64 @checkblock(i32* %12, i32 16384, i32 0, i32 0)
%14 = icmp ne i64 %13, 0
br i1 %14, label %15, label %17
15: ; preds = %9
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.3, i64 0, i64 0))
br label %22
17: ; preds = %9
%18 = load i32*, i32** %1
%19 = bitcast i32* %18 to i8*
%20 = call i32 @free(i8* %19)
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %17, %15, %7
ret void
}

LLVM IR (-O2):
@.str.1 = [21 x i8] c"Allocating %u bytes\0A\00"
@str = [22 x i8] c"*** Malloc test 1 ***\00"
@str.5 = [22 x i8] c"Passed malloc test 1.\00"
@str.6 = [21 x i8] c"FAILED: data corrupt\00"
@str.7 = [22 x i8] c"FAILED: malloc failed\00"
define void @test1() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0), i32 16384)
%3 = tail call i32* @malloc(i32 16384)
%4 = icmp eq i32* %3, null
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = tail call i32 @markblock(i32* %3, i32 16384, i32 0, i32 0)
%7 = tail call i64 @checkblock(i32* %3, i32 16384, i32 0, i32 0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %5
%10 = bitcast i32* %3 to i8*
%11 = tail call i32 @free(i8* %10)
br label %12
12: ; preds = %5, %0, %9
%13 = phi i8* [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.5, i64 0, i64 0), %9 ], [ getelementptr inbounds ([22 x i8], [22 x i8]* @str.7, i64 0, i64 0), %0 ], [ getelementptr inbounds ([21 x i8], [21 x i8]* @str.6, i64 0, i64 0), %5 ]
%14 = tail call i32 @puts(i8* dereferenceable(1) %13)
ret void
}