#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*/ fprintf(int /*<<< orphan*/, char *, char, int);
int ndb_getDebugLevel();
int /*<<< orphan*/ stdout;
char ndb_readbuf_char(char *buf, int *nr) {
  char value = 0;
  value = (buf[(*nr)++] & 0xff);
  if (ndb_getDebugLevel() >= 8)
    fprintf(stdout, "reading char 0x%X from buffer pos 0x%x\n", value & 0xff,
            (*nr) - 1);
  return (value & 0xff);
}


x86 assembly (clang, -O0):
<ndb_readbuf_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movb   $0x0,-0x11(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rdx
mov    (%rdx),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,(%rdx)
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
and    $0xff,%eax
mov    %al,-0x11(%rbp)
mov    $0x0,%al
call   1030 <ndb_getDebugLevel@plt>
cmp    $0x8,%eax
jl     118e <ndb_readbuf_char+0x6e>
mov    0x2e75(%rip),%rax
mov    (%rax),%edi
movsbl -0x11(%rbp),%eax
and    $0xff,%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
lea    0xe7a(%rip),%rsi
movsbl %al,%edx
call   1040 <fprintf@plt>
movsbl -0x11(%rbp),%eax
and    $0xff,%eax
movsbl %al,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndb_readbuf_char>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
movslq (%rsi),%rax
lea    0x1(%rax),%ecx
mov    %ecx,(%rsi)
mov    (%rdi,%rax,1),%bpl
xor    %eax,%eax
call   1030 <ndb_getDebugLevel@plt>
cmp    $0x8,%eax
jl     115c <ndb_readbuf_char+0x3c>
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
add    $0xffffffff,%ecx
movsbl %bpl,%edx
lea    0xea9(%rip),%rsi
call   1040 <fprintf@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [40 x i8] c"reading char 0x%X from buffer pos 0x%x\0A\00"
define signext i8 @ndb_readbuf_char(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8 0, i8* %5
%6 = load i8*, i8** %3
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = add nsw i32 %8, 1
store i32 %9, i32* %7
%10 = sext i32 %8 to i64
%11 = getelementptr inbounds i8, i8* %6, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = and i32 %13, 255
%15 = trunc i32 %14 to i8
store i8 %15, i8* %5
%16 = call i32 (...) @ndb_getDebugLevel()
%17 = icmp sge i32 %16, 8
br i1 %17, label %18, label %28
18: ; preds = %2
%19 = load i32, i32* @stdout
%20 = load i8, i8* %5
%21 = sext i8 %20 to i32
%22 = and i32 %21, 255
%23 = trunc i32 %22 to i8
%24 = load i32*, i32** %4
%25 = load i32, i32* %24
%26 = sub nsw i32 %25, 1
%27 = call i32 @fprintf(i32 %19, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8 signext %23, i32 %26)
br label %28
28: ; preds = %18, %2
%29 = load i8, i8* %5
%30 = sext i8 %29 to i32
%31 = and i32 %30, 255
%32 = trunc i32 %31 to i8
ret i8 %32
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [40 x i8] c"reading char 0x%X from buffer pos 0x%x\0A\00"
define signext i8 @ndb_readbuf_char(i8* nocapture %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = add nsw i32 %3, 1
store i32 %4, i32* %1
%5 = sext i32 %3 to i64
%6 = getelementptr inbounds i8, i8* %0, i64 %5
%7 = load i8, i8* %6
%8 = tail call i32 (...) @ndb_getDebugLevel()
%9 = icmp sgt i32 %8, 7
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stdout
%12 = load i32, i32* %1
%13 = add nsw i32 %12, -1
%14 = tail call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i8 signext %7, i32 %13)
br label %15
15: ; preds = %10, %2
ret i8 %7
}