#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 basm_coff_idxstr(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int basm_elf_idxstr2(char *strs, char *str) {
  char buf[256];
  int i;
  if (!str)
    return (4);
  if (!*str)
    return (4);
  sprintf(buf, "_%s", str);
  i = basm_coff_idxstr(strs, buf);
  return (i);
}


x86 assembly (clang, -O0):
<basm_elf_idxstr2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    114a <basm_elf_idxstr2+0x2a>
movl   $0x4,-0x4(%rbp)
jmp    1199 <basm_elf_idxstr2+0x79>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1163 <basm_elf_idxstr2+0x43>
movl   $0x4,-0x4(%rbp)
jmp    1199 <basm_elf_idxstr2+0x79>
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    0xe8b(%rip),%rsi
call   1040 <sprintf@plt>
mov    -0x10(%rbp),%rdi
lea    -0x120(%rbp),%rsi
call   1030 <basm_coff_idxstr@plt>
mov    %eax,-0x124(%rbp)
mov    -0x124(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<basm_elf_idxstr2>:
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    $0x4,%eax
test   %rsi,%rsi
je     115c <basm_elf_idxstr2+0x3c>
mov    %rsi,%rdx
cmpb   $0x0,(%rsi)
je     115c <basm_elf_idxstr2+0x3c>
mov    %rdi,%rbx
lea    0xeba(%rip),%rsi
mov    %rsp,%r14
mov    %r14,%rdi
call   1040 <sprintf@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <basm_coff_idxstr@plt>
add    $0x108,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [4 x i8] c"_%s\00"
define i32 @basm_elf_idxstr2(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [256 x i8]
%7 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%9 = icmp ne i8* %8, null
br i1 %9, label %11, label %10
10: ; preds = %2
store i32 4, i32* %3
br label %24
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = load i8, i8* %12
%14 = icmp ne i8 %13, 0
br i1 %14, label %16, label %15
15: ; preds = %11
store i32 4, i32* %3
br label %24
16: ; preds = %11
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%18 = load i8*, i8** %5
%19 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %18)
%20 = load i8*, i8** %4
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%22 = call i32 @basm_coff_idxstr(i8* %20, i8* %21)
store i32 %22, i32* %7
%23 = load i32, i32* %7
store i32 %23, i32* %3
br label %24
24: ; preds = %16, %15, %10
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"_%s\00"
define i32 @basm_elf_idxstr2(i8* %0, i8* %1) {
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%5 = icmp eq i8* %1, null
br i1 %5, label %12, label %6
6: ; preds = %2
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 0
br i1 %8, label %12, label %9
9: ; preds = %6
%10 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %1)
%11 = call i32 @basm_coff_idxstr(i8* %0, i8* %4)
br label %12
12: ; preds = %6, %2, %9
%13 = phi i32 [ %11, %9 ], [ 4, %2 ], [ 4, %6 ]
ret i32 %13
}