#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*/ printf(char *, unsigned long);
int validate_addr(char *ptr, int high_addr) {
  unsigned long addr = (unsigned long)ptr;
  if (high_addr) {
    if (addr < (1UL << 47)) {
      printf("in high Bad address %lx\n", addr);
      return 1;
    }
    return 0;
  }
  if (addr > (1UL << 47)) {
    printf("in low Bad address %lx\n", addr);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<validate_addr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     116d <validate_addr+0x5d>
movabs $0x800000000000,%rax
cmp    %rax,-0x20(%rbp)
jae    1161 <validate_addr+0x51>
mov    -0x20(%rbp),%rsi
lea    0xeb0(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a4 <validate_addr+0x94>
movl   $0x0,-0x4(%rbp)
jmp    11a4 <validate_addr+0x94>
movabs $0x800000000000,%rax
cmp    %rax,-0x20(%rbp)
jbe    119d <validate_addr+0x8d>
mov    -0x20(%rbp),%rsi
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11a4 <validate_addr+0x94>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<validate_addr>:
mov    %rdi,%rcx
movabs $0x800000000000,%rdx
xor    %eax,%eax
test   %esi,%esi
je     1131 <validate_addr+0x21>
cmp    %rdx,%rcx
jae    114f <validate_addr+0x3f>
lea    0xed1(%rip),%rdi
jmp    113d <validate_addr+0x2d>
cmp    %rdx,%rcx
jbe    114f <validate_addr+0x3f>
lea    0xedc(%rip),%rdi
push   %rax
mov    %rcx,%rsi
call   1030 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
ret

LLVM IR (-O0):
@.str = [25 x i8] c"in high Bad address %lx\0A\00"
@.str.1 = [24 x i8] c"in low Bad address %lx\0A\00"
define i32 @validate_addr(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i64
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i8*, i8** %4
%8 = ptrtoint i8* %7 to i64
store i64 %8, i64* %6
%9 = load i32, i32* %5
%10 = icmp ne i32 %9, 0
br i1 %10, label %11, label %18
11: ; preds = %2
%12 = load i64, i64* %6
%13 = icmp ult i64 %12, 140737488355328
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = load i64, i64* %6
%16 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i64 %15)
store i32 1, i32* %3
br label %25
17: ; preds = %11
store i32 0, i32* %3
br label %25
18: ; preds = %2
%19 = load i64, i64* %6
%20 = icmp ugt i64 %19, 140737488355328
br i1 %20, label %21, label %24
21: ; preds = %18
%22 = load i64, i64* %6
%23 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i64 %22)
store i32 1, i32* %3
br label %25
24: ; preds = %18
store i32 0, i32* %3
br label %25
25: ; preds = %24, %21, %17, %14
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [25 x i8] c"in high Bad address %lx\0A\00"
@.str.1 = [24 x i8] c"in low Bad address %lx\0A\00"
define i32 @validate_addr(i8* %0, i32 %1) {
%3 = ptrtoint i8* %0 to i64
%4 = icmp eq i32 %1, 0
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = icmp ult i8* %0, inttoptr (i64 140737488355328 to i8*)
br i1 %6, label %9, label %12
7: ; preds = %2
%8 = icmp ugt i8* %0, inttoptr (i64 140737488355328 to i8*)
br i1 %8, label %9, label %12
9: ; preds = %7, %5
%10 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), %5 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), %7 ]
%11 = tail call i32 @printf(i8* %10, i64 %3)
br label %12
12: ; preds = %9, %7, %5
%13 = phi i32 [ 0, %5 ], [ 0, %7 ], [ 1, %9 ]
ret i32 %13
}