#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ nomem();
char *remove_word(char *, char *);
int strlen(char const *);
scalar_t__ strncmp(char *, char *, int);
char tolower(char const);
char *get_card_name(const char *line) {
  char *result, *tmp = malloc(strlen(line) + 16);
  int i;
  if (tmp == NULL)
    nomem();
  for (i = 0; i < strlen(line); i++) {
    if (line[i] == '_')
      tmp[i] = '-';
    else
      tmp[i] = tolower(line[i]);
  }
  tmp[i] = '\0';
  if (strncmp(tmp, "snd-", 4))
    return NULL;
  result = remove_word("snd-", tmp);
  free(tmp);
  return result;
}


x86 assembly (clang, -O0):
<get_card_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%edi
add    $0x10,%edi
call   1090 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11a5 <get_card_name+0x35>
mov    $0x0,%al
call   1070 <nomem@plt>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%eax
cmp    %ecx,%eax
jge    121f <get_card_name+0xaf>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x5f,%eax
jne    11ee <get_card_name+0x7e>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x2d,(%rax,%rcx,1)
jmp    120c <get_card_name+0x9c>
mov    -0x10(%rbp),%rax
movslq -0x24(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1080 <tolower@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1211 <get_card_name+0xa1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11ac <get_card_name+0x3c>
mov    -0x20(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
lea    0xdca(%rip),%rsi
mov    $0x4,%edx
call   1040 <strncmp@plt>
cmp    $0x0,%rax
je     1257 <get_card_name+0xe7>
movq   $0x0,-0x8(%rbp)
jmp    127c <get_card_name+0x10c>
mov    -0x20(%rbp),%rsi
lea    0xd9e(%rip),%rdi
call   1050 <remove_word@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_card_name>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1060 <strlen@plt>
lea    0x10(%rax),%edi
call   1090 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
jne    1194 <get_card_name+0x24>
xor    %eax,%eax
call   1070 <nomem@plt>
mov    %r15,%rdi
call   1060 <strlen@plt>
xor    %ebx,%ebx
test   %eax,%eax
jg     11e7 <get_card_name+0x77>
movb   $0x0,(%r14,%rbx,1)
lea    0xe52(%rip),%rsi
mov    %r14,%rdi
mov    $0x4,%edx
call   1040 <strncmp@plt>
test   %rax,%rax
je     11fd <get_card_name+0x8d>
xor    %eax,%eax
jmp    121a <get_card_name+0xaa>
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r15,%rdi
call   1060 <strlen@plt>
cltq
cmp    %rax,%rbx
jge    11a2 <get_card_name+0x32>
movzbl (%r15,%rbx,1),%ecx
mov    $0x2d,%al
cmp    $0x5f,%cl
je     11d0 <get_card_name+0x60>
movsbl %cl,%edi
call   1080 <tolower@plt>
jmp    11d0 <get_card_name+0x60>
lea    0xdfc(%rip),%rdi
mov    %r14,%rsi
call   1050 <remove_word@plt>
mov    %rax,%rbx
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [5 x i8] c"snd-\00"
define i8* @get_card_name(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 16
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %15
13: ; preds = %1
%14 = call i32 (...) @nomem()
br label %15
15: ; preds = %13, %1
store i32 0, i32* %6
br label %16
16: ; preds = %46, %15
%17 = load i32, i32* %6
%18 = load i8*, i8** %3
%19 = call i32 @strlen(i8* %18)
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %49
21: ; preds = %16
%22 = load i8*, i8** %3
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp eq i32 %27, 95
br i1 %28, label %29, label %34
29: ; preds = %21
%30 = load i8*, i8** %5
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8, i8* %30, i64 %32
store i8 45, i8* %33
br label %45
34: ; preds = %21
%35 = load i8*, i8** %3
%36 = load i32, i32* %6
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
%39 = load i8, i8* %38
%40 = call signext i8 @tolower(i8 signext %39)
%41 = load i8*, i8** %5
%42 = load i32, i32* %6
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
store i8 %40, i8* %44
br label %45
45: ; preds = %34, %29
br label %46
46: ; preds = %45
%47 = load i32, i32* %6
%48 = add nsw i32 %47, 1
store i32 %48, i32* %6
br label %16
49: ; preds = %16
%50 = load i8*, i8** %5
%51 = load i32, i32* %6
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %50, i64 %52
store i8 0, i8* %53
%54 = load i8*, i8** %5
%55 = call i64 @strncmp(i8* %54, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %58
57: ; preds = %49
store i8* null, i8** %2
br label %64
58: ; preds = %49
%59 = load i8*, i8** %5
%60 = call i8* @remove_word(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %59)
store i8* %60, i8** %4
%61 = load i8*, i8** %5
%62 = call i32 @free(i8* %61)
%63 = load i8*, i8** %4
store i8* %63, i8** %2
br label %64
64: ; preds = %58, %57
%65 = load i8*, i8** %2
ret i8* %65
}

LLVM IR (-O2):
@.str = [5 x i8] c"snd-\00"
define i8* @get_card_name(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = add nsw i32 %2, 16
%4 = tail call i8* @malloc(i32 %3)
%5 = icmp eq i8* %4, null
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 (...) @nomem()
br label %8
8: ; preds = %6, %1
%9 = tail call i32 @strlen(i8* %0)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %27
11: ; preds = %8, %18
%12 = phi i64 [ %21, %18 ], [ 0, %8 ]
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 95
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = tail call signext i8 @tolower(i8 signext %14)
br label %18
18: ; preds = %11, %16
%19 = phi i8 [ %17, %16 ], [ 45, %11 ]
%20 = getelementptr inbounds i8, i8* %4, i64 %12
store i8 %19, i8* %20
%21 = add nuw nsw i64 %12, 1
%22 = tail call i32 @strlen(i8* %0)
%23 = sext i32 %22 to i64
%24 = icmp slt i64 %21, %23
br i1 %24, label %11, label %25
25: ; preds = %18
%26 = and i64 %21, 4294967295
br label %27
27: ; preds = %25, %8
%28 = phi i64 [ 0, %8 ], [ %26, %25 ]
%29 = getelementptr inbounds i8, i8* %4, i64 %28
store i8 0, i8* %29
%30 = tail call i64 @strncmp(i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32 4)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = tail call i8* @remove_word(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %4)
%34 = tail call i32 @free(i8* %4)
br label %35
35: ; preds = %27, %32
%36 = phi i8* [ %33, %32 ], [ null, %27 ]
ret i8* %36
}