#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 *, int);
int /*<<< orphan*/ sqlite3_snprintf(int, char *, char *, int);
void multiplexFilename(const char *zBase, int nBase, int flags, int iChunk,
                       char *zOut) {
  int n = nBase;
  memcpy(zOut, zBase, n + 1);
  if (iChunk != 0 && iChunk <= 299) {
    sqlite3_snprintf(4, &zOut[n], "%03d", iChunk);
    n += 3;
  }
  assert(zOut[n] == '\0');
  zOut[n + 1] = '\0';
}


x86 assembly (clang, -O0):
<multiplexFilename>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x24(%rbp),%edx
add    $0x1,%edx
call   1040 <memcpy@plt>
cmpl   $0x0,-0x14(%rbp)
je     11a1 <multiplexFilename+0x71>
cmpl   $0x12b,-0x14(%rbp)
jg     11a1 <multiplexFilename+0x71>
mov    -0x20(%rbp),%rsi
movslq -0x24(%rbp),%rax
add    %rax,%rsi
mov    -0x14(%rbp),%ecx
mov    $0x4,%edi
lea    0xe6d(%rip),%rdx
call   1050 <sqlite3_snprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x3,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1030 <assert@plt>
mov    -0x20(%rbp),%rax
mov    -0x24(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<multiplexFilename>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %r8,%r14
mov    %ecx,%ebp
mov    %esi,%ebx
mov    %rdi,%rsi
lea    0x1(%rbx),%r15d
mov    %r8,%rdi
mov    %r15d,%edx
call   1040 <memcpy@plt>
test   %ebp,%ebp
je     1180 <multiplexFilename+0x50>
cmp    $0x12b,%ebp
jg     1180 <multiplexFilename+0x50>
movslq %ebx,%rsi
add    %r14,%rsi
lea    0xe97(%rip),%rdx
mov    $0x4,%edi
mov    %ebp,%ecx
call   1050 <sqlite3_snprintf@plt>
lea    0x3(%rbx),%eax
add    $0x4,%ebx
mov    %ebx,%r15d
mov    %eax,%ebx
movslq %ebx,%rax
xor    %edi,%edi
cmpb   $0x0,(%r14,%rax,1)
sete   %dil
call   1030 <assert@plt>
movslq %r15d,%rax
movb   $0x0,(%r14,%rax,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%03d\00"
define void @multiplexFilename(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i32 %1, i32* %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i8* %4, i8** %10
%12 = load i32, i32* %7
store i32 %12, i32* %11
%13 = load i8*, i8** %10
%14 = load i8*, i8** %6
%15 = load i32, i32* %11
%16 = add nsw i32 %15, 1
%17 = call i32 @memcpy(i8* %13, i8* %14, i32 %16)
%18 = load i32, i32* %9
%19 = icmp ne i32 %18, 0
br i1 %19, label %20, label %32
20: ; preds = %5
%21 = load i32, i32* %9
%22 = icmp sle i32 %21, 299
br i1 %22, label %23, label %32
23: ; preds = %20
%24 = load i8*, i8** %10
%25 = load i32, i32* %11
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8, i8* %24, i64 %26
%28 = load i32, i32* %9
%29 = call i32 @sqlite3_snprintf(i32 4, i8* %27, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %28)
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 3
store i32 %31, i32* %11
br label %32
32: ; preds = %23, %20, %5
%33 = load i8*, i8** %10
%34 = load i32, i32* %11
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = icmp eq i32 %38, 0
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i8*, i8** %10
%43 = load i32, i32* %11
%44 = add nsw i32 %43, 1
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %42, i64 %45
store i8 0, i8* %46
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%03d\00"
define void @multiplexFilename(i8* %0, i32 %1, i32 %2, i32 %3, i8* %4) {
%6 = add nsw i32 %1, 1
%7 = tail call i32 @memcpy(i8* %4, i8* %0, i32 %6)
%8 = icmp ne i32 %3, 0
%9 = icmp slt i32 %3, 300
%10 = and i1 %8, %9
br i1 %10, label %11, label %17
11: ; preds = %5
%12 = sext i32 %1 to i64
%13 = getelementptr inbounds i8, i8* %4, i64 %12
%14 = tail call i32 @sqlite3_snprintf(i32 4, i8* %13, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 %3)
%15 = add nsw i32 %1, 3
%16 = add nsw i32 %1, 4
br label %17
17: ; preds = %11, %5
%18 = phi i32 [ %16, %11 ], [ %6, %5 ]
%19 = phi i32 [ %15, %11 ], [ %1, %5 ]
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %4, i64 %20
%22 = load i8, i8* %21
%23 = icmp eq i8 %22, 0
%24 = zext i1 %23 to i32
%25 = tail call i32 @assert(i32 %24)
%26 = sext i32 %18 to i64
%27 = getelementptr inbounds i8, i8* %4, i64 %26
store i8 0, i8* %27
ret void
}