#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*/ snprintf(char *, int, char *, char *, ...);
int strlen(char *);
void dbgsysBuildLibName(char *holder, int holderlen, char *pname, char *fname) {
  const int pnamelen = pname ? strlen(pname) : 0;
  if (pnamelen + (int)strlen(fname) + 10 > holderlen) {
    *holder = '\0';
    return;
  }
  if (pnamelen == 0) {
    (void)snprintf(holder, holderlen, "lib%s.so", fname);
  } else {
    (void)snprintf(holder, holderlen, "%s/lib%s.so", pname, fname);
  }
}


x86 assembly (clang, -O0):
<dbgsysBuildLibName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1153 <dbgsysBuildLibName+0x33>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x28(%rbp)
jmp    115d <dbgsysBuildLibName+0x3d>
xor    %eax,%eax
mov    %eax,-0x28(%rbp)
jmp    115d <dbgsysBuildLibName+0x3d>
mov    -0x28(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
add    %ecx,%eax
add    $0xa,%eax
cmp    -0xc(%rbp),%eax
jle    1191 <dbgsysBuildLibName+0x71>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
jmp    11d6 <dbgsysBuildLibName+0xb6>
cmpl   $0x0,-0x24(%rbp)
jne    11b9 <dbgsysBuildLibName+0x99>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
lea    0xe56(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
jmp    11d6 <dbgsysBuildLibName+0xb6>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    0xe31(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dbgsysBuildLibName>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%rbx
mov    %esi,%r12d
mov    %rdi,%r14
test   %rdx,%rdx
je     1145 <dbgsysBuildLibName+0x25>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
jmp    1147 <dbgsysBuildLibName+0x27>
xor    %ebp,%ebp
mov    %r15,%rdi
call   1030 <strlen@plt>
add    %ebp,%eax
add    $0xa,%eax
cmp    %r12d,%eax
jle    1166 <dbgsysBuildLibName+0x46>
movb   $0x0,(%r14)
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
test   %ebp,%ebp
je     118c <dbgsysBuildLibName+0x6c>
lea    0xe8f(%rip),%rdx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %rbx,%rcx
mov    %r15,%r8
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <snprintf@plt>
lea    0xe70(%rip),%rdx
mov    %r14,%rdi
mov    %r12d,%esi
mov    %r15,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <snprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"lib%s.so\00"
@.str.1 = [12 x i8] c"%s/lib%s.so\00"
define void @dbgsysBuildLibName(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32
store i8* %0, i8** %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%10 = load i8*, i8** %7
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %15
12: ; preds = %4
%13 = load i8*, i8** %7
%14 = call i32 @strlen(i8* %13)
br label %16
15: ; preds = %4
br label %16
16: ; preds = %15, %12
%17 = phi i32 [ %14, %12 ], [ 0, %15 ]
store i32 %17, i32* %9
%18 = load i32, i32* %9
%19 = load i8*, i8** %8
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %18, %20
%22 = add nsw i32 %21, 10
%23 = load i32, i32* %6
%24 = icmp sgt i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %16
%26 = load i8*, i8** %5
store i8 0, i8* %26
br label %41
27: ; preds = %16
%28 = load i32, i32* %9
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %35
30: ; preds = %27
%31 = load i8*, i8** %5
%32 = load i32, i32* %6
%33 = load i8*, i8** %8
%34 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %31, i32 %32, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %33)
br label %41
35: ; preds = %27
%36 = load i8*, i8** %5
%37 = load i32, i32* %6
%38 = load i8*, i8** %7
%39 = load i8*, i8** %8
%40 = call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %36, i32 %37, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %38, i8* %39)
br label %41
41: ; preds = %25, %35, %30
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"lib%s.so\00"
@.str.1 = [12 x i8] c"%s/lib%s.so\00"
define void @dbgsysBuildLibName(i8* %0, i32 %1, i8* %2, i8* %3) {
%5 = icmp eq i8* %2, null
br i1 %5, label %8, label %6
6: ; preds = %4
%7 = tail call i32 @strlen(i8* %2)
br label %8
8: ; preds = %4, %6
%9 = phi i32 [ %7, %6 ], [ 0, %4 ]
%10 = tail call i32 @strlen(i8* %3)
%11 = add i32 %9, 10
%12 = add i32 %11, %10
%13 = icmp sgt i32 %12, %1
br i1 %13, label %14, label %15
14: ; preds = %8
store i8 0, i8* %0
br label %21
15: ; preds = %8
%16 = icmp eq i32 %9, 0
br i1 %16, label %17, label %19
17: ; preds = %15
%18 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %3)
br label %21
19: ; preds = %15
%20 = tail call i32 (i8*, i32, i8*, i8*, ...) @snprintf(i8* %0, i32 %1, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %3)
br label %21
21: ; preds = %17, %19, %14
ret void
}