#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 CheckSet(char *);
int /*<<< orphan*/ SetStrings(char **, char **);
int /*<<< orphan*/ WrMessage(char *);
int errno;
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int);
void WrMallocErrors(void) {
  int err_no;
  int check;
  char string[20];
  char *null_ptr;
  char *local_ptr;
  SetStrings(&null_ptr, &local_ptr);
  local_ptr = &string[0];
  WrMessage("@MALLOC-ERRORS");
  check = CheckSet("@FREENULL");
  if (check) {
    WrMessage("@MALLOC-FREE-NULL");
    errno = 0;
    free(null_ptr);
    err_no = errno;
    printf("System error: %s\n\n", strerror(err_no));
    WrMessage("@MALLOC-CONTINUE");
  }
  check = CheckSet("@FREELOCAL");
  if (check) {
    WrMessage("@MALLOC-FREE-LOCAL");
    errno = 0;
    free(local_ptr);
    err_no = errno;
    printf("System error: %s\n\n", strerror(err_no));
    WrMessage("@MALLOC-CONTINUE");
  }
  return;
}


x86 assembly (clang, -O0):
<WrMallocErrors>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x28(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <SetStrings@plt>
lea    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe7c(%rip),%rdi
call   1070 <WrMessage@plt>
lea    0xe7f(%rip),%rdi
call   1040 <CheckSet@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     11f3 <WrMallocErrors+0x93>
lea    0xe70(%rip),%rdi
call   1070 <WrMessage@plt>
mov    0x2e2b(%rip),%rax
movl   $0x0,(%rax)
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2e15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xe49(%rip),%rdi
call   1050 <printf@plt>
lea    0xe50(%rip),%rdi
call   1070 <WrMessage@plt>
lea    0xe55(%rip),%rdi
call   1040 <CheckSet@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
je     125d <WrMallocErrors+0xfd>
lea    0xe47(%rip),%rdi
call   1070 <WrMessage@plt>
mov    0x2dc1(%rip),%rax
movl   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%edi
call   1080 <strerror@plt>
mov    %rax,%rsi
lea    0xddf(%rip),%rdi
call   1050 <printf@plt>
lea    0xde6(%rip),%rdi
call   1070 <WrMessage@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<WrMallocErrors>:
push   %rbx
sub    $0x30,%rsp
lea    0x8(%rsp),%rdi
mov    %rsp,%rsi
call   1060 <SetStrings@plt>
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
lea    0xe7e(%rip),%rdi
call   1070 <WrMessage@plt>
lea    0xe81(%rip),%rdi
call   1040 <CheckSet@plt>
test   %eax,%eax
je     11dc <WrMallocErrors+0x7c>
lea    0xe7b(%rip),%rdi
call   1070 <WrMessage@plt>
mov    0x2e36(%rip),%rbx
movl   $0x0,(%rbx)
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    (%rbx),%edi
call   1080 <strerror@plt>
lea    0xe63(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0xe67(%rip),%rdi
call   1070 <WrMessage@plt>
lea    0xe6c(%rip),%rdi
call   1040 <CheckSet@plt>
test   %eax,%eax
je     1230 <WrMallocErrors+0xd0>
lea    0xe67(%rip),%rdi
call   1070 <WrMessage@plt>
mov    0x2de1(%rip),%rbx
movl   $0x0,(%rbx)
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    (%rbx),%edi
call   1080 <strerror@plt>
lea    0xe0f(%rip),%rdi
mov    %rax,%rsi
call   1050 <printf@plt>
lea    0xe13(%rip),%rdi
call   1070 <WrMessage@plt>
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [15 x i8] c"@MALLOC-ERRORS\00"
@.str.1 = [10 x i8] c"@FREENULL\00"
@.str.2 = [18 x i8] c"@MALLOC-FREE-NULL\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"System error: %s\0A\0A\00"
@.str.4 = [17 x i8] c"@MALLOC-CONTINUE\00"
@.str.5 = [11 x i8] c"@FREELOCAL\00"
@.str.6 = [19 x i8] c"@MALLOC-FREE-LOCAL\00"
define void @WrMallocErrors() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [20 x i8]
%4 = alloca i8*
%5 = alloca i8*
%6 = call i32 @SetStrings(i8** %4, i8** %5)
%7 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
store i8* %7, i8** %5
%8 = call i32 @WrMessage(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @CheckSet(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = icmp ne i32 %10, 0
br i1 %11, label %12, label %21
12: ; preds = %0
%13 = call i32 @WrMessage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* @errno
%14 = load i8*, i8** %4
%15 = call i32 @free(i8* %14)
%16 = load i32, i32* @errno
store i32 %16, i32* %1
%17 = load i32, i32* %1
%18 = call i8* @strerror(i32 %17)
%19 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %18)
%20 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %21
21: ; preds = %12, %0
%22 = call i32 @CheckSet(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
store i32 %22, i32* %2
%23 = load i32, i32* %2
%24 = icmp ne i32 %23, 0
br i1 %24, label %25, label %34
25: ; preds = %21
%26 = call i32 @WrMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* @errno
%27 = load i8*, i8** %5
%28 = call i32 @free(i8* %27)
%29 = load i32, i32* @errno
store i32 %29, i32* %1
%30 = load i32, i32* %1
%31 = call i8* @strerror(i32 %30)
%32 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %31)
%33 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %34
34: ; preds = %25, %21
ret void
}

LLVM IR (-O2):
@.str = [15 x i8] c"@MALLOC-ERRORS\00"
@.str.1 = [10 x i8] c"@FREENULL\00"
@.str.2 = [18 x i8] c"@MALLOC-FREE-NULL\00"
@errno = global i32 0
@.str.3 = [19 x i8] c"System error: %s\0A\0A\00"
@.str.4 = [17 x i8] c"@MALLOC-CONTINUE\00"
@.str.5 = [11 x i8] c"@FREELOCAL\00"
@.str.6 = [19 x i8] c"@MALLOC-FREE-LOCAL\00"
define void @WrMallocErrors() {
%1 = alloca [20 x i8]
%2 = alloca i8*
%3 = alloca i8*
%4 = getelementptr inbounds [20 x i8], [20 x i8]* %1, i64 0, i64 0
%5 = bitcast i8** %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = call i32 @SetStrings(i8** %2, i8** %3)
store i8* %4, i8** %3
%8 = call i32 @WrMessage(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%9 = call i32 @CheckSet(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i32 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %0
%12 = call i32 @WrMessage(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* @errno
%13 = load i8*, i8** %2
%14 = call i32 @free(i8* %13)
%15 = load i32, i32* @errno
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %16)
%18 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %19
19: ; preds = %11, %0
%20 = call i32 @CheckSet(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0))
%21 = icmp eq i32 %20, 0
br i1 %21, label %30, label %22
22: ; preds = %19
%23 = call i32 @WrMessage(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.6, i64 0, i64 0))
store i32 0, i32* @errno
%24 = load i8*, i8** %3
%25 = call i32 @free(i8* %24)
%26 = load i32, i32* @errno
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %27)
%29 = call i32 @WrMessage(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.4, i64 0, i64 0))
br label %30
30: ; preds = %22, %19
ret void
}