#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*/ console_print(char *);
char *mm_alloc(int);
int /*<<< orphan*/ mm_free(char *);
scalar_t__ mm_init();
int systemcheck() {
  if (mm_init()) {
    return 0;
  }
  console_print("initializing system check...\n");
  console_print("    memory... ");
  char *mem = mm_alloc(128);
  if (mem) {
    console_print("OK\n");
    mm_free(mem);
  } else {
    console_print("BAD\n");
    return 0;
  }
  console_print("completed system check\n");
  return 1;
}


x86 assembly (clang, -O0):
<systemcheck>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1040 <mm_init@plt>
cmp    $0x0,%rax
je     1165 <systemcheck+0x25>
movl   $0x0,-0x4(%rbp)
jmp    11db <systemcheck+0x9b>
lea    0xe94(%rip),%rdi
call   1030 <console_print@plt>
lea    0xea6(%rip),%rdi
call   1030 <console_print@plt>
mov    $0x80,%edi
call   1050 <mm_alloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11b0 <systemcheck+0x70>
lea    0xe90(%rip),%rdi
call   1030 <console_print@plt>
mov    -0x10(%rbp),%rdi
call   1060 <mm_free@plt>
jmp    11c8 <systemcheck+0x88>
lea    0xe7a(%rip),%rdi
call   1030 <console_print@plt>
movl   $0x0,-0x4(%rbp)
jmp    11db <systemcheck+0x9b>
lea    0xe67(%rip),%rdi
call   1030 <console_print@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<systemcheck>:
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <mm_init@plt>
test   %rax,%rax
jne    11a9 <systemcheck+0x69>
lea    0xeaa(%rip),%rdi
call   1030 <console_print@plt>
lea    0xebc(%rip),%rdi
call   1030 <console_print@plt>
mov    $0x80,%edi
call   1050 <mm_alloc@plt>
test   %rax,%rax
je     119b <systemcheck+0x5b>
mov    %rax,%rbx
lea    0xead(%rip),%rdi
call   1030 <console_print@plt>
mov    %rbx,%rdi
call   1060 <mm_free@plt>
mov    $0x1,%ebx
lea    0xe9d(%rip),%rdi
jmp    11a4 <systemcheck+0x64>
xor    %ebx,%ebx
lea    0xe8d(%rip),%rdi
call   1030 <console_print@plt>
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [30 x i8] c"initializing system check...\0A\00"
@.str.1 = [15 x i8] c" memory... \00"
@.str.2 = [4 x i8] c"OK\0A\00"
@.str.3 = [5 x i8] c"BAD\0A\00"
@.str.4 = [24 x i8] c"completed system check\0A\00"
define i32 @systemcheck() {
%1 = alloca i32
%2 = alloca i8*
%3 = call i64 (...) @mm_init()
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %6
5: ; preds = %0
store i32 0, i32* %1
br label %20
6: ; preds = %0
%7 = call i32 @console_print(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @console_print(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%9 = call i8* @mm_alloc(i32 128)
store i8* %9, i8** %2
%10 = load i8*, i8** %2
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %6
%13 = call i32 @console_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%14 = load i8*, i8** %2
%15 = call i32 @mm_free(i8* %14)
br label %18
16: ; preds = %6
%17 = call i32 @console_print(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %20
18: ; preds = %12
%19 = call i32 @console_print(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %1
br label %20
20: ; preds = %18, %16, %5
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [30 x i8] c"initializing system check...\0A\00"
@.str.1 = [15 x i8] c" memory... \00"
@.str.2 = [4 x i8] c"OK\0A\00"
@.str.3 = [5 x i8] c"BAD\0A\00"
@.str.4 = [24 x i8] c"completed system check\0A\00"
define i32 @systemcheck() {
%1 = tail call i64 (...) @mm_init()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %15
3: ; preds = %0
%4 = tail call i32 @console_print(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%5 = tail call i32 @console_print(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i8* @mm_alloc(i32 128)
%7 = icmp eq i8* %6, null
br i1 %7, label %11, label %8
8: ; preds = %3
%9 = tail call i32 @console_print(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%10 = tail call i32 @mm_free(i8* %6)
br label %11
11: ; preds = %3, %8
%12 = phi i8* [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.4, i64 0, i64 0), %8 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %3 ]
%13 = phi i32 [ 1, %8 ], [ 0, %3 ]
%14 = tail call i32 @console_print(i8* %12)
br label %15
15: ; preds = %11, %0
%16 = phi i32 [ 0, %0 ], [ %13, %11 ]
ret i32 %16
}