#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__ isspace(int);
int /*<<< orphan*/ sprintf(char *, char *, char const *, char const, char const,
                           char const);
int strlen(char const *);
scalar_t__ strncasecmp(char const *, char *, int);
scalar_t__ xmalloc(int);
char *auto_artist_sort_name(const char *name) {
  const char *name_orig = name;
  char *buf;
  if (strncasecmp(name, "the ", 4) != 0)
    return NULL;
  name += 4;
  while (isspace((int)*name))
    ++name;
  if (*name == '\0')
    return NULL;
  buf = (char *)xmalloc(sizeof(char) * (strlen(name_orig) + 2));
  sprintf(buf, "%s, %c%c%c", name, name_orig[0], name_orig[1], name_orig[2]);
  return buf;
}


x86 assembly (clang, -O0):
<auto_artist_sort_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe91(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
cmp    $0x0,%rax
je     1190 <auto_artist_sort_name+0x40>
movq   $0x0,-0x8(%rbp)
jmp    1237 <auto_artist_sort_name+0xe7>
mov    -0x10(%rbp),%rax
add    $0x4,%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%edi
call   1050 <isspace@plt>
cmp    $0x0,%rax
je     11c3 <auto_artist_sort_name+0x73>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    119c <auto_artist_sort_name+0x4c>
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    11e0 <auto_artist_sort_name+0x90>
movq   $0x0,-0x8(%rbp)
jmp    1237 <auto_artist_sort_name+0xe7>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x2,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x18(%rbp),%rax
mov    (%rax),%cl
mov    -0x18(%rbp),%rax
mov    0x1(%rax),%r8b
mov    -0x18(%rbp),%rax
lea    0xde7(%rip),%rsi
movsbl %cl,%ecx
movsbl %r8b,%r8d
movsbl 0x2(%rax),%r9d
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<auto_artist_sort_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
lea    0xea1(%rip),%rsi
mov    $0x4,%edx
call   1060 <strncasecmp@plt>
test   %rax,%rax
je     1173 <auto_artist_sort_name+0x23>
xor    %r15d,%r15d
jmp    11ca <auto_artist_sort_name+0x7a>
lea    0x3(%r14),%rbx
nopw   0x0(%rax,%rax,1)
movsbl 0x1(%rbx),%edi
add    $0x1,%rbx
call   1050 <isspace@plt>
test   %rax,%rax
jne    1180 <auto_artist_sort_name+0x30>
cmpb   $0x0,(%rbx)
je     116e <auto_artist_sort_name+0x1e>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0x2(%rax),%edi
call   1040 <xmalloc@plt>
mov    %rax,%r15
movsbl (%r14),%ecx
movsbl 0x1(%r14),%r8d
movsbl 0x2(%r14),%r9d
lea    0xe46(%rip),%rsi
mov    %rax,%rdi
mov    %rbx,%rdx
call   1070 <sprintf@plt>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"the \00"
@.str.1 = [11 x i8] c"%s, %c%c%c\00"
define i8* @auto_artist_sort_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
store i8* %6, i8** %4
%7 = load i8*, i8** %3
%8 = call i64 @strncasecmp(i8* %7, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %51
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = getelementptr inbounds i8, i8* %12, i64 4
store i8* %13, i8** %3
br label %14
14: ; preds = %20, %11
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = call i64 @isspace(i32 %17)
%19 = icmp ne i64 %18, 0
br i1 %19, label %20, label %23
20: ; preds = %14
%21 = load i8*, i8** %3
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %3
br label %14
23: ; preds = %14
%24 = load i8*, i8** %3
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
store i8* null, i8** %2
br label %51
29: ; preds = %23
%30 = load i8*, i8** %4
%31 = call i32 @strlen(i8* %30)
%32 = add nsw i32 %31, 2
%33 = sext i32 %32 to i64
%34 = mul i64 1, %33
%35 = trunc i64 %34 to i32
%36 = call i64 @xmalloc(i32 %35)
%37 = inttoptr i64 %36 to i8*
store i8* %37, i8** %5
%38 = load i8*, i8** %5
%39 = load i8*, i8** %3
%40 = load i8*, i8** %4
%41 = getelementptr inbounds i8, i8* %40, i64 0
%42 = load i8, i8* %41
%43 = load i8*, i8** %4
%44 = getelementptr inbounds i8, i8* %43, i64 1
%45 = load i8, i8* %44
%46 = load i8*, i8** %4
%47 = getelementptr inbounds i8, i8* %46, i64 2
%48 = load i8, i8* %47
%49 = call i32 @sprintf(i8* %38, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %39, i8 signext %42, i8 signext %45, i8 signext %48)
%50 = load i8*, i8** %5
store i8* %50, i8** %2
br label %51
51: ; preds = %29, %28, %10
%52 = load i8*, i8** %2
ret i8* %52
}

LLVM IR (-O2):
@.str = [5 x i8] c"the \00"
@.str.1 = [11 x i8] c"%s, %c%c%c\00"
define i8* @auto_artist_sort_name(i8* %0) {
%2 = tail call i64 @strncasecmp(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%3 = icmp eq i64 %2, 0
br i1 %3, label %4, label %27
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %0, i64 4
br label %6
6: ; preds = %6, %4
%7 = phi i8* [ %5, %4 ], [ %12, %6 ]
%8 = load i8, i8* %7
%9 = sext i8 %8 to i32
%10 = tail call i64 @isspace(i32 %9)
%11 = icmp eq i64 %10, 0
%12 = getelementptr inbounds i8, i8* %7, i64 1
br i1 %11, label %13, label %6
13: ; preds = %6
%14 = load i8, i8* %7
%15 = icmp eq i8 %14, 0
br i1 %15, label %27, label %16
16: ; preds = %13
%17 = tail call i32 @strlen(i8* %0)
%18 = add nsw i32 %17, 2
%19 = tail call i64 @xmalloc(i32 %18)
%20 = inttoptr i64 %19 to i8*
%21 = load i8, i8* %0
%22 = getelementptr inbounds i8, i8* %0, i64 1
%23 = load i8, i8* %22
%24 = getelementptr inbounds i8, i8* %0, i64 2
%25 = load i8, i8* %24
%26 = tail call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8 signext %21, i8 signext %23, i8 signext %25)
br label %27
27: ; preds = %13, %1, %16
%28 = phi i8* [ %20, %16 ], [ null, %1 ], [ null, %13 ]
ret i8* %28
}