#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 */
typedef int /*<<< orphan*/ uint8_t;

/* Variables and functions */
int /*<<< orphan*/ ece391_fdputs(int, int /*<<< orphan*/ *);
int ece391_vidmap(int /*<<< orphan*/ **);
int err_vidmap(void) {
  int fail = 0;
  if (-1 != ece391_vidmap((uint8_t **)0x0)) {
    ece391_fdputs(1, (uint8_t *)"Null pointer fail\n");
    fail = 2;
  }
  if (-1 != ece391_vidmap((uint8_t **)0x400000)) {
    ece391_fdputs(1, (uint8_t *)"Kernel pointer fail fail\n");
    fail = 2;
  }
  if (fail) {
    ece391_fdputs(1, (uint8_t *)"err_vidmap: FAIL\n");
  } else {
    ece391_fdputs(1, (uint8_t *)"err_vidmap: PASS\n");
  }
  return fail;
}


x86 assembly (clang, -O0):
<err_vidmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1030 <ece391_vidmap@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     115f <err_vidmap+0x3f>
mov    $0x1,%edi
lea    0xead(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
mov    $0x400000,%edi
call   1030 <ece391_vidmap@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     1190 <err_vidmap+0x70>
mov    $0x1,%edi
lea    0xe8f(%rip),%rsi
call   1040 <ece391_fdputs@plt>
movl   $0x2,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11b0 <err_vidmap+0x90>
mov    $0x1,%edi
lea    0xe87(%rip),%rsi
call   1040 <ece391_fdputs@plt>
jmp    11c1 <err_vidmap+0xa1>
mov    $0x1,%edi
lea    0xe83(%rip),%rsi
call   1040 <ece391_fdputs@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<err_vidmap>:
push   %rbx
xor    %ebx,%ebx
xor    %edi,%edi
call   1030 <ece391_vidmap@plt>
cmp    $0xffffffff,%eax
je     1151 <err_vidmap+0x31>
lea    0xeca(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    $0x400000,%edi
call   1030 <ece391_vidmap@plt>
cmp    $0xffffffff,%eax
jne    1160 <err_vidmap+0x40>
jmp    1171 <err_vidmap+0x51>
mov    $0x400000,%edi
call   1030 <ece391_vidmap@plt>
cmp    $0xffffffff,%eax
je     118b <err_vidmap+0x6b>
lea    0xeac(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    $0x2,%ebx
lea    0xeb0(%rip),%rsi
mov    $0x1,%edi
call   1040 <ece391_fdputs@plt>
mov    %ebx,%eax
pop    %rbx
ret
lea    0xead(%rip),%rsi
jmp    117d <err_vidmap+0x5d>

LLVM IR (-O0):
@.str = [19 x i8] c"Null pointer fail\0A\00"
@.str.1 = [26 x i8] c"Kernel pointer fail fail\0A\00"
@.str.2 = [18 x i8] c"err_vidmap: FAIL\0A\00"
@.str.3 = [18 x i8] c"err_vidmap: PASS\0A\00"
define i32 @err_vidmap() {
%1 = alloca i32
store i32 0, i32* %1
%2 = call i32 @ece391_vidmap(i32** null)
%3 = icmp ne i32 -1, %2
br i1 %3, label %4, label %6
4: ; preds = %0
%5 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([19 x i8]* @.str to i32*))
store i32 2, i32* %1
br label %6
6: ; preds = %4, %0
%7 = call i32 @ece391_vidmap(i32** inttoptr (i64 4194304 to i32**))
%8 = icmp ne i32 -1, %7
br i1 %8, label %9, label %11
9: ; preds = %6
%10 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([26 x i8]* @.str.1 to i32*))
store i32 2, i32* %1
br label %11
11: ; preds = %9, %6
%12 = load i32, i32* %1
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([18 x i8]* @.str.2 to i32*))
br label %18
16: ; preds = %11
%17 = call i32 @ece391_fdputs(i32 1, i32* bitcast ([18 x i8]* @.str.3 to i32*))
br label %18
18: ; preds = %16, %14
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [19 x i8] c"Null pointer fail\0A\00"
@.str.1 = [26 x i8] c"Kernel pointer fail fail\0A\00"
@.str.2 = [18 x i8] c"err_vidmap: FAIL\0A\00"
@.str.3 = [18 x i8] c"err_vidmap: PASS\0A\00"
define i32 @err_vidmap() {
%1 = tail call i32 @ece391_vidmap(i32** null)
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %6
3: ; preds = %0
%4 = tail call i32 @ece391_vidmap(i32** inttoptr (i64 4194304 to i32**))
%5 = icmp eq i32 %4, -1
br i1 %5, label %12, label %10
6: ; preds = %0
%7 = tail call i32 @ece391_fdputs(i32 1, i32* bitcast ([19 x i8]* @.str to i32*))
%8 = tail call i32 @ece391_vidmap(i32** inttoptr (i64 4194304 to i32**))
%9 = icmp eq i32 %8, -1
br i1 %9, label %12, label %10
10: ; preds = %6, %3
%11 = tail call i32 @ece391_fdputs(i32 1, i32* bitcast ([26 x i8]* @.str.1 to i32*))
br label %12
12: ; preds = %3, %10, %6
%13 = phi i32* [ bitcast ([18 x i8]* @.str.2 to i32*), %6 ], [ bitcast ([18 x i8]* @.str.2 to i32*), %10 ], [ bitcast ([18 x i8]* @.str.3 to i32*), %3 ]
%14 = phi i32 [ 2, %6 ], [ 2, %10 ], [ 0, %3 ]
%15 = tail call i32 @ece391_fdputs(i32 1, i32* %13)
ret i32 %14
}