#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 */
scalar_t__ strlen(char const *);
scalar_t__ toupper(char const);
void genCSName(char *out, const char *name) {
  bool upperCaseNext = false;
  int len = (int)strlen(name);
  *out++ = (char)toupper(name[0]);
  for (int i = 1; i < len; ++i) {
    char c = name[i];
    if (upperCaseNext) {
      *out++ = (char)toupper(c);
      upperCaseNext = false;
    } else {
      if (c == '_')
        upperCaseNext = true;
      else
        *out++ = c;
    }
  }
  *out = 0;
}


x86 assembly (clang, -O0):
<genCSName>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
jge    11fa <genCSName+0xda>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
cmpl   $0x0,-0x14(%rbp)
je     11b5 <genCSName+0x95>
movsbl -0x1d(%rbp),%edi
call   1030 <toupper@plt>
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
movl   $0x0,-0x14(%rbp)
jmp    11e7 <genCSName+0xc7>
movsbl -0x1d(%rbp),%eax
cmp    $0x5f,%eax
jne    11ce <genCSName+0xae>
movl   $0x1,-0x14(%rbp)
jmp    11e2 <genCSName+0xc2>
mov    -0x1d(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    11e7 <genCSName+0xc7>
jmp    11ec <genCSName+0xcc>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1169 <genCSName+0x49>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<genCSName>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %rax,%r15
movsbl (%r14),%edi
call   1030 <toupper@plt>
mov    %al,(%r12)
add    $0x1,%r12
cmp    $0x2,%r15d
jl     118f <genCSName+0x6f>
mov    %r15d,%r15d
xor    %ecx,%ecx
mov    $0x1,%ebx
jmp    117b <genCSName+0x5b>
nopl   0x0(%rax)
movsbl %al,%edi
call   1030 <toupper@plt>
mov    %al,(%r12)
add    $0x1,%r12
xor    %ecx,%ecx
add    $0x1,%rbx
cmp    %rbx,%r15
je     118f <genCSName+0x6f>
movzbl (%r14,%rbx,1),%eax
test   %ecx,%ecx
jne    1160 <genCSName+0x40>
mov    $0x1,%ecx
cmp    $0x5f,%al
jne    1168 <genCSName+0x48>
jmp    1172 <genCSName+0x52>
movb   $0x0,(%r12)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
define void @genCSName(i8* nocapture writeonly %0, i8* nocapture %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %1)
%4 = trunc i64 %3 to i32
%5 = load i8, i8* %1
%6 = tail call i64 @toupper(i8 signext %5)
%7 = trunc i64 %6 to i8
%8 = getelementptr inbounds i8, i8* %0, i64 1
store i8 %7, i8* %0
%9 = icmp sgt i32 %4, 1
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = and i64 %3, 4294967295
br label %14
12: ; preds = %29, %2
%13 = phi i8* [ %8, %2 ], [ %31, %29 ]
store i8 0, i8* %13
ret void
14: ; preds = %10, %29
%15 = phi i64 [ 1, %10 ], [ %32, %29 ]
%16 = phi i8* [ %8, %10 ], [ %31, %29 ]
%17 = phi i32 [ 0, %10 ], [ %30, %29 ]
%18 = getelementptr inbounds i8, i8* %1, i64 %15
%19 = load i8, i8* %18
%20 = icmp eq i32 %17, 0
br i1 %20, label %24, label %21
21: ; preds = %14
%22 = tail call i64 @toupper(i8 signext %19)
%23 = trunc i64 %22 to i8
br label %26
24: ; preds = %14
%25 = icmp eq i8 %19, 95
br i1 %25, label %29, label %26
26: ; preds = %24, %21
%27 = phi i8 [ %23, %21 ], [ %19, %24 ]
%28 = getelementptr inbounds i8, i8* %16, i64 1
store i8 %27, i8* %16
br label %29
29: ; preds = %26, %24
%30 = phi i32 [ 1, %24 ], [ 0, %26 ]
%31 = phi i8* [ %16, %24 ], [ %28, %26 ]
%32 = add nuw nsw i64 %15, 1
%33 = icmp eq i64 %32, %11
br i1 %33, label %12, label %14
}