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


x86 assembly (clang, -O0):
<ndb_write2buf_char>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %dl,%al
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %al,-0x11(%rbp)
mov    $0x0,%al
call   1030 <ndb_getDebugLevel@plt>
cmp    $0x8,%eax
jl     116c <ndb_write2buf_char+0x4c>
mov    0x2e94(%rip),%rax
mov    (%rax),%edi
movsbl -0x11(%rbp),%eax
and    $0xff,%eax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
lea    0xe9c(%rip),%rsi
movsbl %al,%edx
call   1040 <fprintf@plt>
movsbl -0x11(%rbp),%eax
and    $0xff,%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rsi
mov    (%rsi),%ecx
mov    %ecx,%edi
add    $0x1,%edi
mov    %edi,(%rsi)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndb_write2buf_char>:
push   %rbp
push   %r14
push   %rbx
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <ndb_getDebugLevel@plt>
cmp    $0x8,%eax
jl     1153 <ndb_write2buf_char+0x33>
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
movsbl %bpl,%edx
lea    0xeb2(%rip),%rsi
call   1040 <fprintf@plt>
movslq (%rbx),%rax
lea    0x1(%rax),%ecx
mov    %ecx,(%rbx)
mov    %bpl,(%r14,%rax,1)
mov    (%rbx),%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

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

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