#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 *, int, int);
int ndb_getDebugLevel();
int /*<<< orphan*/ stdout;
int ndb_write2buf_byte_n(char *buf, int *nr, char *value, int len) {
  int count;
  if (ndb_getDebugLevel() >= 8)
    fprintf(stdout, "saving 0x%x bytes at buffer pos 0x%x\n", len, *nr);
  for (count = 0; count < len; count++) {
    buf[(*nr)++] = value[count];
  }
  return (*nr);
}


x86 assembly (clang, -O0):
<ndb_write2buf_byte_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    $0x0,%al
call   1030 <ndb_getDebugLevel@plt>
cmp    $0x8,%eax
jl     1165 <ndb_write2buf_byte_n+0x45>
mov    0x2e92(%rip),%rax
mov    (%rax),%edi
mov    -0x1c(%rbp),%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
lea    0xea0(%rip),%rsi
call   1040 <fprintf@plt>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11a8 <ndb_write2buf_byte_n+0x88>
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    (%rax,%rcx,1),%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    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    116c <ndb_write2buf_byte_n+0x4c>
mov    -0x10(%rbp),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ndb_write2buf_byte_n>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %ecx,%ebp
mov    %rdx,%r15
mov    %rsi,%rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <ndb_getDebugLevel@plt>
cmp    $0x8,%eax
jl     1157 <ndb_write2buf_byte_n+0x37>
mov    0x2e9b(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%ecx
lea    0xeb0(%rip),%rsi
mov    %ebp,%edx
call   1040 <fprintf@plt>
test   %ebp,%ebp
jle    11b2 <ndb_write2buf_byte_n+0x92>
mov    %ebp,%esi
cmp    $0x1,%ebp
jne    1166 <ndb_write2buf_byte_n+0x46>
xor    %ecx,%ecx
jmp    119c <ndb_write2buf_byte_n+0x7c>
mov    %esi,%edx
and    $0xfffffffe,%edx
xor    %ecx,%ecx
nopl   (%rax)
movzbl (%r15,%rcx,1),%eax
movslq (%rbx),%rdi
lea    0x1(%rdi),%ebp
mov    %ebp,(%rbx)
mov    %al,(%r14,%rdi,1)
movzbl 0x1(%r15,%rcx,1),%eax
movslq (%rbx),%rdi
lea    0x1(%rdi),%ebp
mov    %ebp,(%rbx)
mov    %al,(%r14,%rdi,1)
add    $0x2,%rcx
cmp    %rcx,%rdx
jne    1170 <ndb_write2buf_byte_n+0x50>
test   $0x1,%sil
je     11b2 <ndb_write2buf_byte_n+0x92>
mov    (%r15,%rcx,1),%al
movslq (%rbx),%rcx
lea    0x1(%rcx),%edx
mov    %edx,(%rbx)
mov    %al,(%r14,%rcx,1)
mov    (%rbx),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stdout = global i32 0
@.str = [38 x i8] c"saving 0x%x bytes at buffer pos 0x%x\0A\00"
define i32 @ndb_write2buf_byte_n(i8* nocapture writeonly %0, i32* nocapture %1, i8* nocapture %2, i32 %3) {
%5 = tail call i32 (...) @ndb_getDebugLevel()
%6 = icmp sgt i32 %5, 7
br i1 %6, label %7, label %11
7: ; preds = %4
%8 = load i32, i32* @stdout
%9 = load i32, i32* %1
%10 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %3, i32 %9)
br label %11
11: ; preds = %7, %4
%12 = icmp sgt i32 %3, 0
br i1 %12, label %13, label %48
13: ; preds = %11
%14 = zext i32 %3 to i64
%15 = and i64 %14, 1
%16 = icmp eq i32 %3, 1
br i1 %16, label %38, label %17
17: ; preds = %13
%18 = and i64 %14, 4294967294
br label %19
19: ; preds = %19, %17
%20 = phi i64 [ 0, %17 ], [ %35, %19 ]
%21 = phi i64 [ 0, %17 ], [ %36, %19 ]
%22 = getelementptr inbounds i8, i8* %2, i64 %20
%23 = load i8, i8* %22
%24 = load i32, i32* %1
%25 = add nsw i32 %24, 1
store i32 %25, i32* %1
%26 = sext i32 %24 to i64
%27 = getelementptr inbounds i8, i8* %0, i64 %26
store i8 %23, i8* %27
%28 = or i64 %20, 1
%29 = getelementptr inbounds i8, i8* %2, i64 %28
%30 = load i8, i8* %29
%31 = load i32, i32* %1
%32 = add nsw i32 %31, 1
store i32 %32, i32* %1
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %0, i64 %33
store i8 %30, i8* %34
%35 = add nuw nsw i64 %20, 2
%36 = add i64 %21, 2
%37 = icmp eq i64 %36, %18
br i1 %37, label %38, label %19
38: ; preds = %19, %13
%39 = phi i64 [ 0, %13 ], [ %35, %19 ]
%40 = icmp eq i64 %15, 0
br i1 %40, label %48, label %41
41: ; preds = %38
%42 = getelementptr inbounds i8, i8* %2, i64 %39
%43 = load i8, i8* %42
%44 = load i32, i32* %1
%45 = add nsw i32 %44, 1
store i32 %45, i32* %1
%46 = sext i32 %44 to i64
%47 = getelementptr inbounds i8, i8* %0, i64 %46
store i8 %43, i8* %47
br label %48
48: ; preds = %41, %38, %11
%49 = load i32, i32* %1
ret i32 %49
}