#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*/ strcpy(char *, char const *);
char toupper(char);
void create_new_name_ptr(const char *fpath, size_t index, char *localbuf) {
  int counter = 0;
  strcpy(localbuf, fpath);
  char *ptr = localbuf + index;
  *ptr = toupper(*ptr);
  ptr++;
  for (; *ptr != '\0' && counter < 2; ptr++) {
    if (*(ptr - 1) == '_') {
      *ptr = toupper(*ptr);
      counter++;
    }
  }
}


x86 assembly (clang, -O0):
<create_new_name_ptr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rax
add    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x29(%rbp)
je     1193 <create_new_name_ptr+0x73>
cmpl   $0x2,-0x1c(%rbp)
setl   %al
mov    %al,-0x29(%rbp)
mov    -0x29(%rbp),%al
test   $0x1,%al
jne    11a3 <create_new_name_ptr+0x83>
jmp    11e7 <create_new_name_ptr+0xc7>
mov    -0x28(%rbp),%rax
movsbl -0x1(%rax),%eax
cmp    $0x5f,%eax
jne    11d1 <create_new_name_ptr+0xb1>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1040 <toupper@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11d6 <create_new_name_ptr+0xb6>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1174 <create_new_name_ptr+0x54>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<create_new_name_ptr>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%rsi
mov    %rdx,%rdi
call   1030 <strcpy@plt>
movsbl (%rbx,%r14,1),%edi
call   1040 <toupper@plt>
mov    %al,(%rbx,%r14,1)
mov    0x1(%rbx,%r14,1),%cl
test   %cl,%cl
je     1188 <create_new_name_ptr+0x68>
add    %r14,%rbx
add    $0x2,%rbx
xor    %ebp,%ebp
cmp    $0x5f,%al
jne    116e <create_new_name_ptr+0x4e>
nopl   0x0(%rax)
movsbl %cl,%edi
call   1040 <toupper@plt>
mov    %al,-0x1(%rbx)
add    $0x1,%ebp
movzbl (%rbx),%ecx
test   %cl,%cl
je     1188 <create_new_name_ptr+0x68>
cmp    $0x1,%ebp
jg     1188 <create_new_name_ptr+0x68>
movzbl -0x1(%rbx),%eax
add    $0x1,%rbx
cmp    $0x5f,%al
je     1160 <create_new_name_ptr+0x40>
jmp    116e <create_new_name_ptr+0x4e>
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define void @create_new_name_ptr(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
store i32 0, i32* %7
%9 = load i8*, i8** %6
%10 = load i8*, i8** %4
%11 = call i32 @strcpy(i8* %9, i8* %10)
%12 = load i8*, i8** %6
%13 = load i64, i64* %5
%14 = getelementptr inbounds i8, i8* %12, i64 %13
store i8* %14, i8** %8
%15 = load i8*, i8** %8
%16 = load i8, i8* %15
%17 = call signext i8 @toupper(i8 signext %16)
%18 = load i8*, i8** %8
store i8 %17, i8* %18
%19 = load i8*, i8** %8
%20 = getelementptr inbounds i8, i8* %19, i32 1
store i8* %20, i8** %8
br label %21
21: ; preds = %45, %3
%22 = load i8*, i8** %8
%23 = load i8, i8* %22
%24 = sext i8 %23 to i32
%25 = icmp ne i32 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32, i32* %7
%28 = icmp slt i32 %27, 2
br label %29
29: ; preds = %26, %21
%30 = phi i1 [ false, %21 ], [ %28, %26 ]
br i1 %30, label %31, label %48
31: ; preds = %29
%32 = load i8*, i8** %8
%33 = getelementptr inbounds i8, i8* %32, i64 -1
%34 = load i8, i8* %33
%35 = sext i8 %34 to i32
%36 = icmp eq i32 %35, 95
br i1 %36, label %37, label %44
37: ; preds = %31
%38 = load i8*, i8** %8
%39 = load i8, i8* %38
%40 = call signext i8 @toupper(i8 signext %39)
%41 = load i8*, i8** %8
store i8 %40, i8* %41
%42 = load i32, i32* %7
%43 = add nsw i32 %42, 1
store i32 %43, i32* %7
br label %44
44: ; preds = %37, %31
br label %45
45: ; preds = %44
%46 = load i8*, i8** %8
%47 = getelementptr inbounds i8, i8* %46, i32 1
store i8* %47, i8** %8
br label %21
48: ; preds = %29
ret void
}

LLVM IR (-O2):
define void @create_new_name_ptr(i8* %0, i64 %1, i8* %2) {
%4 = tail call i32 @strcpy(i8* %2, i8* %0)
%5 = getelementptr inbounds i8, i8* %2, i64 %1
%6 = load i8, i8* %5
%7 = tail call signext i8 @toupper(i8 signext %6)
store i8 %7, i8* %5
%8 = getelementptr inbounds i8, i8* %5, i64 1
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 0
br i1 %10, label %29, label %11
11: ; preds = %3, %27
%12 = phi i8 [ %28, %27 ], [ %7, %3 ]
%13 = phi i8 [ %23, %27 ], [ %9, %3 ]
%14 = phi i8* [ %22, %27 ], [ %8, %3 ]
%15 = phi i32 [ %21, %27 ], [ 0, %3 ]
%16 = icmp eq i8 %12, 95
br i1 %16, label %17, label %20
17: ; preds = %11
%18 = tail call signext i8 @toupper(i8 signext %13)
store i8 %18, i8* %14
%19 = add nsw i32 %15, 1
br label %20
20: ; preds = %11, %17
%21 = phi i32 [ %19, %17 ], [ %15, %11 ]
%22 = getelementptr inbounds i8, i8* %14, i64 1
%23 = load i8, i8* %22
%24 = icmp ne i8 %23, 0
%25 = icmp slt i32 %21, 2
%26 = select i1 %24, i1 %25, i1 false
br i1 %26, label %27, label %29
27: ; preds = %20
%28 = load i8, i8* %14
br label %11
29: ; preds = %20, %3
ret void
}