#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*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
char *index(char *, char);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strncmp(char *, char *, int);
char tolower(char);
char toupper(char);
void mangle(char *from, char *to) {
  char pattern[4096];
  char cased[4096];
  char *format = 0;
  char *p = 0;
  char *bar = 0;
  bar = index("_", '|');
  if (!bar) {
    fprintf(stderr, "Configuration problem\n");
    exit(1);
  }
  if (index(from, '_')) {
    strcpy(pattern, bar + 1);
  } else {
    strcpy(pattern, "_");
    *bar = 0;
  }
  format = pattern + 5;
  strcpy(cased, from);
  if (strncmp(pattern, "lower", 5) == 0) {
    for (p = cased; *p; ++p)
      *p = tolower(*p);
  } else {
    for (p = cased; *p; ++p)
      *p = toupper(*p);
  }
  sprintf(to, format, cased);
}


x86 assembly (clang, -O0):
<mangle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2030,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x2018(%rbp)
movq   $0x0,-0x2020(%rbp)
movq   $0x0,-0x2028(%rbp)
lea    0xe45(%rip),%rdi
mov    $0x7c,%esi
call   1060 <index@plt>
mov    %rax,-0x2028(%rbp)
cmpq   $0x0,-0x2028(%rbp)
jne    11f9 <mangle+0x79>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe18(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x8(%rbp),%rdi
mov    $0x5f,%esi
call   1060 <index@plt>
cmp    $0x0,%rax
je     122d <mangle+0xad>
lea    -0x1010(%rbp),%rdi
mov    -0x2028(%rbp),%rsi
add    $0x1,%rsi
call   1040 <strcpy@plt>
jmp    124a <mangle+0xca>
lea    -0x1010(%rbp),%rdi
lea    0xdc5(%rip),%rsi
call   1040 <strcpy@plt>
mov    -0x2028(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x1010(%rbp),%rax
add    $0x5,%rax
mov    %rax,-0x2018(%rbp)
lea    -0x2010(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x1010(%rbp),%rdi
lea    0xd9f(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    12e2 <mangle+0x162>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2020(%rbp)
mov    -0x2020(%rbp),%rax
cmpb   $0x0,(%rax)
je     12dd <mangle+0x15d>
mov    -0x2020(%rbp),%rax
movsbl (%rax),%edi
call   1080 <tolower@plt>
mov    %al,%cl
mov    -0x2020(%rbp),%rax
mov    %cl,(%rax)
mov    -0x2020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2020(%rbp)
jmp    129c <mangle+0x11c>
jmp    1336 <mangle+0x1b6>
lea    -0x2010(%rbp),%rax
mov    %rax,-0x2020(%rbp)
mov    -0x2020(%rbp),%rax
cmpb   $0x0,(%rax)
je     1331 <mangle+0x1b1>
mov    -0x2020(%rbp),%rax
movsbl (%rax),%edi
call   1050 <toupper@plt>
mov    %al,%cl
mov    -0x2020(%rbp),%rax
mov    %cl,(%rax)
mov    -0x2020(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x2020(%rbp)
jmp    12f0 <mangle+0x170>
jmp    1336 <mangle+0x1b6>
mov    -0x10(%rbp),%rdi
mov    -0x2018(%rbp),%rsi
lea    -0x2010(%rbp),%rdx
call   1090 <sprintf@plt>
add    $0x2030,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mangle>:
push   %r15
push   %r14
push   %rbx
sub    $0x2000,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe67(%rip),%rdi
mov    $0x7c,%esi
call   1060 <index@plt>
test   %rax,%rax
je     1296 <mangle+0x116>
mov    %rax,%rbx
mov    %r15,%rdi
mov    $0x5f,%esi
call   1060 <index@plt>
test   %rax,%rax
je     11d7 <mangle+0x57>
add    $0x1,%rbx
lea    0x1000(%rsp),%rdi
mov    %rbx,%rsi
call   1040 <strcpy@plt>
jmp    11ee <mangle+0x6e>
lea    0xe22(%rip),%rsi
lea    0x1000(%rsp),%rdi
call   1040 <strcpy@plt>
movb   $0x0,(%rbx)
mov    %rsp,%rdi
mov    %r15,%rsi
call   1040 <strcpy@plt>
lea    0xe19(%rip),%rsi
lea    0x1000(%rsp),%rdi
mov    $0x5,%edx
call   1030 <strncmp@plt>
mov    (%rsp),%cl
test   %rax,%rax
je     1248 <mangle+0xc8>
test   %cl,%cl
je     1276 <mangle+0xf6>
lea    0x1(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %cl,%edi
call   1050 <toupper@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1230 <mangle+0xb0>
jmp    1276 <mangle+0xf6>
test   %cl,%cl
je     1276 <mangle+0xf6>
lea    0x1(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
movsbl %cl,%edi
call   1080 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%ecx
add    $0x1,%rbx
test   %cl,%cl
jne    1260 <mangle+0xe0>
lea    0x1005(%rsp),%rsi
mov    %rsp,%rdx
mov    %r14,%rdi
call   1090 <sprintf@plt>
add    $0x2000,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    0x2d43(%rip),%rax
mov    (%rax),%edi
lea    0xd5c(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"_\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Configuration problem\0A\00"
@.str.2 = [6 x i8] c"lower\00"
define void @mangle(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca [4096 x i8]
%6 = alloca [4096 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i8* null, i8** %7
store i8* null, i8** %8
store i8* null, i8** %9
%10 = call i8* @index(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext 124)
store i8* %10, i8** %9
%11 = load i8*, i8** %9
%12 = icmp ne i8* %11, null
br i1 %12, label %17, label %13
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %2
%18 = load i8*, i8** %3
%19 = call i8* @index(i8* %18, i8 signext 95)
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %26
21: ; preds = %17
%22 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%23 = load i8*, i8** %9
%24 = getelementptr inbounds i8, i8* %23, i64 1
%25 = call i32 @strcpy(i8* %22, i8* %24)
br label %30
26: ; preds = %17
%27 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%29 = load i8*, i8** %9
store i8 0, i8* %29
br label %30
30: ; preds = %26, %21
%31 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%32 = getelementptr inbounds i8, i8* %31, i64 5
store i8* %32, i8** %7
%33 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%34 = load i8*, i8** %3
%35 = call i32 @strcpy(i8* %33, i8* %34)
%36 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%37 = call i64 @strncmp(i8* %36, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%38 = icmp eq i64 %37, 0
br i1 %38, label %39, label %54
39: ; preds = %30
%40 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8* %40, i8** %8
br label %41
41: ; preds = %50, %39
%42 = load i8*, i8** %8
%43 = load i8, i8* %42
%44 = icmp ne i8 %43, 0
br i1 %44, label %45, label %53
45: ; preds = %41
%46 = load i8*, i8** %8
%47 = load i8, i8* %46
%48 = call signext i8 @tolower(i8 signext %47)
%49 = load i8*, i8** %8
store i8 %48, i8* %49
br label %50
50: ; preds = %45
%51 = load i8*, i8** %8
%52 = getelementptr inbounds i8, i8* %51, i32 1
store i8* %52, i8** %8
br label %41
53: ; preds = %41
br label %69
54: ; preds = %30
%55 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
store i8* %55, i8** %8
br label %56
56: ; preds = %65, %54
%57 = load i8*, i8** %8
%58 = load i8, i8* %57
%59 = icmp ne i8 %58, 0
br i1 %59, label %60, label %68
60: ; preds = %56
%61 = load i8*, i8** %8
%62 = load i8, i8* %61
%63 = call signext i8 @toupper(i8 signext %62)
%64 = load i8*, i8** %8
store i8 %63, i8* %64
br label %65
65: ; preds = %60
%66 = load i8*, i8** %8
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %8
br label %56
68: ; preds = %56
br label %69
69: ; preds = %68, %53
%70 = load i8*, i8** %4
%71 = load i8*, i8** %7
%72 = getelementptr inbounds [4096 x i8], [4096 x i8]* %6, i64 0, i64 0
%73 = call i32 @sprintf(i8* %70, i8* %71, i8* %72)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"_\00"
@stderr = global i32 0
@.str.1 = [23 x i8] c"Configuration problem\0A\00"
@.str.2 = [6 x i8] c"lower\00"
define void @mangle(i8* %0, i8* nocapture writeonly %1) {
%3 = alloca [4096 x i8]
%4 = alloca [4096 x i8]
%5 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %4, i64 0, i64 0
%7 = tail call i8* @index(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8 signext 124)
%8 = icmp eq i8* %7, null
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = tail call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0))
%12 = tail call i32 @exit(i32 1)
unreachable
13: ; preds = %2
%14 = tail call i8* @index(i8* %0, i8 signext 95)
%15 = icmp eq i8* %14, null
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = getelementptr inbounds i8, i8* %7, i64 1
%18 = call i32 @strcpy(i8* %5, i8* %17)
br label %21
19: ; preds = %13
%20 = call i32 @strcpy(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8 0, i8* %7
br label %21
21: ; preds = %19, %16
%22 = call i32 @strcpy(i8* %6, i8* %0)
%23 = call i64 @strncmp(i8* %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5)
%24 = icmp eq i64 %23, 0
%25 = load i8, i8* %6
%26 = icmp eq i8 %25, 0
br i1 %24, label %28, label %27
27: ; preds = %21
br i1 %26, label %43, label %36
28: ; preds = %21
br i1 %26, label %43, label %29
29: ; preds = %28, %29
%30 = phi i8 [ %34, %29 ], [ %25, %28 ]
%31 = phi i8* [ %33, %29 ], [ %6, %28 ]
%32 = call signext i8 @tolower(i8 signext %30)
store i8 %32, i8* %31
%33 = getelementptr inbounds i8, i8* %31, i64 1
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %43, label %29
36: ; preds = %27, %36
%37 = phi i8 [ %41, %36 ], [ %25, %27 ]
%38 = phi i8* [ %40, %36 ], [ %6, %27 ]
%39 = call signext i8 @toupper(i8 signext %37)
store i8 %39, i8* %38
%40 = getelementptr inbounds i8, i8* %38, i64 1
%41 = load i8, i8* %40
%42 = icmp eq i8 %41, 0
br i1 %42, label %43, label %36
43: ; preds = %36, %29, %27, %28
%44 = getelementptr inbounds [4096 x i8], [4096 x i8]* %3, i64 0, i64 5
%45 = call i32 @sprintf(i8* dereferenceable(1) %1, i8* %44, i8* %6)
ret void
}