#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 */
char const *jlibtool_basename(char const *);
scalar_t__ malloc(scalar_t__);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char const *);
scalar_t__ strncmp(char const *, char *, int);
char *strrchr(char *, char);
char *gen_library_name(const char *name, int genlib) {
  char *newarg, *newext;
  newarg = (char *)malloc(strlen(name) + 11);
  strcpy(newarg, ".libs/");
  if (genlib == 2 && strncmp(name, "lib", 3) == 0) {
    name += 3;
  }
  if (genlib == 2) {
    strcat(newarg, jlibtool_basename(name));
  } else {
    strcat(newarg, name);
  }
  newext = strrchr(newarg, '.') + 1;
  switch (genlib) {
  case 0:
    strcpy(newext, "a");
    break;
  case 1:
    strcpy(newext, "so");
    break;
  case 2:
    strcpy(newext, "so");
    break;
  }
  return newarg;
}


x86 assembly (clang, -O0):
<gen_library_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rdi
add    $0xb,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe5d(%rip),%rsi
call   1040 <strcpy@plt>
cmpl   $0x2,-0xc(%rbp)
jne    11dd <gen_library_name+0x6d>
mov    -0x8(%rbp),%rdi
lea    0xe4a(%rip),%rsi
mov    $0x3,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11dd <gen_library_name+0x6d>
mov    -0x8(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x8(%rbp)
cmpl   $0x2,-0xc(%rbp)
jne    1209 <gen_library_name+0x99>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
call   1080 <jlibtool_basename@plt>
mov    -0x28(%rbp),%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
jmp    1216 <gen_library_name+0xa6>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1090 <strcat@plt>
mov    -0x18(%rbp),%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,-0x2c(%rbp)
test   %eax,%eax
je     1261 <gen_library_name+0xf1>
jmp    123f <gen_library_name+0xcf>
mov    -0x2c(%rbp),%eax
sub    $0x1,%eax
je     1276 <gen_library_name+0x106>
jmp    1250 <gen_library_name+0xe0>
mov    -0x2c(%rbp),%eax
sub    $0x2,%eax
je     128b <gen_library_name+0x11b>
jmp    129b <gen_library_name+0x12b>
mov    -0x20(%rbp),%rdi
lea    0xd9f(%rip),%rsi
call   1040 <strcpy@plt>
jmp    129b <gen_library_name+0x12b>
mov    -0x20(%rbp),%rdi
lea    0xd8c(%rip),%rsi
call   1040 <strcpy@plt>
jmp    129b <gen_library_name+0x12b>
mov    -0x20(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gen_library_name>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%rbx
call   1050 <strlen@plt>
lea    0xb(%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe6f(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
cmp    $0x2,%ebp
jne    11eb <gen_library_name+0x7b>
lea    0xe62(%rip),%rsi
mov    %rbx,%rdi
mov    $0x3,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
lea    (%rcx,%rcx,2),%rdi
add    %rbx,%rdi
call   1080 <jlibtool_basename@plt>
mov    %r14,%rdi
mov    %rax,%rsi
call   1090 <strcat@plt>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
lea    0x1(%rax),%rdi
lea    0xe24(%rip),%rsi
jmp    1223 <gen_library_name+0xb3>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1090 <strcat@plt>
mov    %r14,%rdi
mov    $0x2e,%esi
call   1060 <strrchr@plt>
add    $0x1,%rax
cmp    $0x1,%ebp
je     1219 <gen_library_name+0xa9>
test   %ebp,%ebp
jne    1228 <gen_library_name+0xb8>
lea    0xdf4(%rip),%rsi
jmp    1220 <gen_library_name+0xb0>
lea    0xded(%rip),%rsi
mov    %rax,%rdi
call   1040 <strcpy@plt>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c".libs/\00"
@.str.1 = [4 x i8] c"lib\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [3 x i8] c"so\00"
define i8* @gen_library_name(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i64 @strlen(i8* %7)
%9 = add nsw i64 %8, 11
%10 = call i64 @malloc(i64 %9)
%11 = inttoptr i64 %10 to i8*
store i8* %11, i8** %5
%12 = load i8*, i8** %5
%13 = call i32 @strcpy(i8* %12, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%14 = load i32, i32* %4
%15 = icmp eq i32 %14, 2
br i1 %15, label %16, label %23
16: ; preds = %2
%17 = load i8*, i8** %3
%18 = call i64 @strncmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i64 3
store i8* %22, i8** %3
br label %23
23: ; preds = %20, %16, %2
%24 = load i32, i32* %4
%25 = icmp eq i32 %24, 2
br i1 %25, label %26, label %31
26: ; preds = %23
%27 = load i8*, i8** %5
%28 = load i8*, i8** %3
%29 = call i8* @jlibtool_basename(i8* %28)
%30 = call i32 @strcat(i8* %27, i8* %29)
br label %35
31: ; preds = %23
%32 = load i8*, i8** %5
%33 = load i8*, i8** %3
%34 = call i32 @strcat(i8* %32, i8* %33)
br label %35
35: ; preds = %31, %26
%36 = load i8*, i8** %5
%37 = call i8* @strrchr(i8* %36, i8 signext 46)
%38 = getelementptr inbounds i8, i8* %37, i64 1
store i8* %38, i8** %6
%39 = load i32, i32* %4
switch i32 %39, label %49 [
i32 0, label %40
i32 1, label %43
i32 2, label %46
]
40: ; preds = %35
%41 = load i8*, i8** %6
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %49
43: ; preds = %35
%44 = load i8*, i8** %6
%45 = call i32 @strcpy(i8* %44, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %49
46: ; preds = %35
%47 = load i8*, i8** %6
%48 = call i32 @strcpy(i8* %47, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %49
49: ; preds = %35, %46, %43, %40
%50 = load i8*, i8** %5
ret i8* %50
}

LLVM IR (-O2):
@.str = [7 x i8] c".libs/\00"
@.str.1 = [4 x i8] c"lib\00"
@.str.2 = [2 x i8] c"a\00"
@.str.3 = [3 x i8] c"so\00"
define i8* @gen_library_name(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = add nsw i64 %3, 11
%5 = tail call i64 @malloc(i64 %4)
%6 = inttoptr i64 %5 to i8*
%7 = tail call i32 @strcpy(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32 %1, 2
br i1 %8, label %9, label %19
9: ; preds = %2
%10 = tail call i64 @strncmp(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 3)
%11 = icmp eq i64 %10, 0
%12 = select i1 %11, i64 3, i64 0
%13 = getelementptr i8, i8* %0, i64 %12
%14 = tail call i8* @jlibtool_basename(i8* %13)
%15 = tail call i32 @strcat(i8* %6, i8* %14)
%16 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext 46)
%17 = getelementptr inbounds i8, i8* %16, i64 1
%18 = tail call i32 @strcpy(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %27
19: ; preds = %2
%20 = tail call i32 @strcat(i8* %6, i8* %0)
%21 = tail call i8* @strrchr(i8* dereferenceable(1) %6, i8 signext 46)
%22 = getelementptr inbounds i8, i8* %21, i64 1
switch i32 %1, label %27 [
i32 0, label %23
i32 1, label %25
]
23: ; preds = %19
%24 = tail call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %27
25: ; preds = %19
%26 = tail call i32 @strcpy(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
br label %27
27: ; preds = %19, %9, %25, %23
ret i8* %6
}