#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 get_mem(int);
int /*<<< orphan*/ printf(char *, ...);
int sscanf(char *, char *, int *);
int /*<<< orphan*/ strncmp(char *, char *, int);
int check_show_mem(char *buf) {
  if (1024 > 8 && !strncmp(buf, "showmem", 7)) {
    int mem;
    if (sscanf(buf + 8, "%x", &mem) == 1 && mem >= 0 && mem <= 0xFFFF) {
      printf("0x%X\n", get_mem(mem));
      return 1;
    } else {
      printf("usage: showmem [address]"
             "(where address is between 0x0000 and 0xFFFF inclusive)\n");
      return 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<check_show_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    11e0 <check_show_mem+0xa0>
mov    -0x10(%rbp),%rdi
add    $0x8,%rdi
lea    0xe8f(%rip),%rsi
lea    -0x14(%rbp),%rdx
call   1060 <sscanf@plt>
cmp    $0x1,%eax
jne    11c6 <check_show_mem+0x86>
cmpl   $0x0,-0x14(%rbp)
jl     11c6 <check_show_mem+0x86>
cmpl   $0xffff,-0x14(%rbp)
jg     11c6 <check_show_mem+0x86>
mov    -0x14(%rbp),%edi
call   1050 <get_mem@plt>
mov    %eax,%esi
lea    0xe58(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e7 <check_show_mem+0xa7>
lea    0xe44(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11e7 <check_show_mem+0xa7>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_show_mem>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
lea    0xea1(%rip),%rsi
mov    $0x7,%edx
call   1030 <strncmp@plt>
mov    %eax,%ecx
xor    %eax,%eax
test   %ecx,%ecx
jne    11c8 <check_show_mem+0x78>
add    $0x8,%rbx
lea    0xe8c(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rbx,%rdi
call   1070 <sscanf@plt>
cmp    $0x1,%eax
jne    11ba <check_show_mem+0x6a>
mov    0xc(%rsp),%edi
test   %edi,%edi
js     11ba <check_show_mem+0x6a>
cmp    $0xffff,%edi
jg     11ba <check_show_mem+0x6a>
call   1060 <get_mem@plt>
lea    0xe61(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%eax
jmp    11c8 <check_show_mem+0x78>
lea    0xe50(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [8 x i8] c"showmem\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [6 x i8] c"0x%X\0A\00"
@.str.3 = [80 x i8] c"usage: showmem [address](where address is between 0x0000 and 0xFFFF inclusive)\0A\00"
define i32 @check_show_mem(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32
store i8* %0, i8** %3
%5 = load i8*, i8** %3
%6 = call i32 @strncmp(i8* %5, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%7 = icmp ne i32 %6, 0
br i1 %7, label %25, label %8
8: ; preds = %1
%9 = load i8*, i8** %3
%10 = getelementptr inbounds i8, i8* %9, i64 8
%11 = call i32 @sscanf(i8* %10, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %4)
%12 = icmp eq i32 %11, 1
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i32, i32* %4
%15 = icmp sge i32 %14, 0
br i1 %15, label %16, label %23
16: ; preds = %13
%17 = load i32, i32* %4
%18 = icmp sle i32 %17, 65535
br i1 %18, label %19, label %23
19: ; preds = %16
%20 = load i32, i32* %4
%21 = call i32 @get_mem(i32 %20)
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %21)
store i32 1, i32* %2
br label %26
23: ; preds = %16, %13, %8
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([80 x i8], [80 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %2
br label %26
25: ; preds = %1
store i32 0, i32* %2
br label %26
26: ; preds = %25, %23, %19
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@.str = [8 x i8] c"showmem\00"
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [6 x i8] c"0x%X\0A\00"
@str = [79 x i8] c"usage: showmem [address](where address is between 0x0000 and 0xFFFF inclusive)\00"
define i32 @check_show_mem(i8* %0) {
%2 = alloca i32
%3 = tail call i32 @strncmp(i8* %0, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 7)
%4 = icmp eq i32 %3, 0
br i1 %4, label %5, label %22
5: ; preds = %1
%6 = bitcast i32* %2 to i8*
%7 = getelementptr inbounds i8, i8* %0, i64 8
%8 = call i32 @sscanf(i8* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32* %2)
%9 = icmp eq i32 %8, 1
%10 = load i32, i32* %2
%11 = icmp sgt i32 %10, -1
%12 = select i1 %9, i1 %11, i1 false
%13 = icmp slt i32 %10, 65536
%14 = select i1 %12, i1 %13, i1 false
br i1 %14, label %15, label %18
15: ; preds = %5
%16 = call i32 @get_mem(i32 %10)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %20
18: ; preds = %5
%19 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([79 x i8], [79 x i8]* @str, i64 0, i64 0))
br label %20
20: ; preds = %18, %15
%21 = phi i32 [ 1, %15 ], [ 0, %18 ]
br label %22
22: ; preds = %1, %20
%23 = phi i32 [ %21, %20 ], [ 0, %1 ]
ret i32 %23
}