#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*/ assert(int);
int /*<<< orphan*/ memcpy(char *, char const *, size_t);
scalar_t__ sqlite3_malloc64(size_t);
int strlen(char const *);
char *rbuStrndup(const char *zStr, int *pRc) {
  char *zRet = 0;
  assert(*pRc == 0);
  if (zStr) {
    size_t nCopy = strlen(zStr) + 1;
    zRet = (char *)sqlite3_malloc64(nCopy);
    if (zRet) {
      memcpy(zRet, zStr, nCopy);
    } else {
      *pRc = 7;
    }
  }
  return zRet;
}


x86 assembly (clang, -O0):
<rbuStrndup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
cmpq   $0x0,-0x8(%rbp)
je     11c6 <rbuStrndup+0x86>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <sqlite3_malloc64@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b7 <rbuStrndup+0x77>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <memcpy@plt>
jmp    11c1 <rbuStrndup+0x81>
mov    -0x10(%rbp),%rax
movl   $0x7,(%rax)
jmp    11c6 <rbuStrndup+0x86>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rbuStrndup>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
cmpl   $0x0,(%rsi)
sete   %dil
call   1050 <assert@plt>
test   %r15,%r15
je     118f <rbuStrndup+0x4f>
mov    %r15,%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
movslq %eax,%r12
mov    %r12,%rdi
call   1040 <sqlite3_malloc64@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1193 <rbuStrndup+0x53>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1060 <memcpy@plt>
jmp    119a <rbuStrndup+0x5a>
xor    %ebx,%ebx
jmp    119a <rbuStrndup+0x5a>
movl   $0x7,(%r14)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @rbuStrndup(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %3
store i32* %1, i32** %4
store i8* null, i8** %5
%7 = load i32*, i32** %4
%8 = load i32, i32* %7
%9 = icmp eq i32 %8, 0
%10 = zext i1 %9 to i32
%11 = call i32 @assert(i32 %10)
%12 = load i8*, i8** %3
%13 = icmp ne i8* %12, null
br i1 %13, label %14, label %32
14: ; preds = %2
%15 = load i8*, i8** %3
%16 = call i32 @strlen(i8* %15)
%17 = add nsw i32 %16, 1
%18 = sext i32 %17 to i64
store i64 %18, i64* %6
%19 = load i64, i64* %6
%20 = call i64 @sqlite3_malloc64(i64 %19)
%21 = inttoptr i64 %20 to i8*
store i8* %21, i8** %5
%22 = load i8*, i8** %5
%23 = icmp ne i8* %22, null
br i1 %23, label %24, label %29
24: ; preds = %14
%25 = load i8*, i8** %5
%26 = load i8*, i8** %3
%27 = load i64, i64* %6
%28 = call i32 @memcpy(i8* %25, i8* %26, i64 %27)
br label %31
29: ; preds = %14
%30 = load i32*, i32** %4
store i32 7, i32* %30
br label %31
31: ; preds = %29, %24
br label %32
32: ; preds = %31, %2
%33 = load i8*, i8** %5
ret i8* %33
}

LLVM IR (-O2):
define i8* @rbuStrndup(i8* %0, i32* nocapture %1) {
%3 = load i32, i32* %1
%4 = icmp eq i32 %3, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = icmp eq i8* %0, null
br i1 %7, label %18, label %8
8: ; preds = %2
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, 1
%11 = sext i32 %10 to i64
%12 = tail call i64 @sqlite3_malloc64(i64 %11)
%13 = inttoptr i64 %12 to i8*
%14 = icmp eq i64 %12, 0
br i1 %14, label %17, label %15
15: ; preds = %8
%16 = tail call i32 @memcpy(i8* %13, i8* %0, i64 %11)
br label %18
17: ; preds = %8
store i32 7, i32* %1
br label %18
18: ; preds = %15, %17, %2
%19 = phi i8* [ null, %2 ], [ %13, %17 ], [ %13, %15 ]
ret i8* %19
}