#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 */
char *DuplicateString(char *);
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ exit_wrapper(int);
int /*<<< orphan*/ puts(char *);
scalar_t__ strlen(char *);
char *ReadUStarTag(char *str) {
  char *temp;
  unsigned long length = 0;
  (assert(str != NULL));
  temp = DuplicateString(str);
  while (1) {
    length = (unsigned long)strlen(temp);
    if (length == 0) {
      (void)puts("Error processing UltraStar tag\nAborting");
      exit_wrapper(1);
    }
    if ((temp[length - 1] == '\r') || (temp[length - 1] == '\n'))
      temp[length - 1] = '\0';
    else
      return temp;
  }
}


x86 assembly (clang, -O0):
<ReadUStarTag>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1040 <DuplicateString@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11b1 <ReadUStarTag+0x61>
lea    0xe5e(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit_wrapper@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
je     11e3 <ReadUStarTag+0x93>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11f8 <ReadUStarTag+0xa8>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1202 <ReadUStarTag+0xb2>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret
jmp    1183 <ReadUStarTag+0x33>

x86 assembly (clang, -O2):
<ReadUStarTag>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%rbx
xor    %edi,%edi
test   %rbx,%rbx
setne  %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1040 <DuplicateString@plt>
mov    %rax,%r15
lea    0xe88(%rip),%r14
jmp    1186 <ReadUStarTag+0x36>
nopw   0x0(%rax,%rax,1)
movb   $0x0,-0x1(%r15,%rbx,1)
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11a8 <ReadUStarTag+0x58>
mov    %r14,%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit_wrapper@plt>
movzbl -0x1(%rbx,%r15,1),%eax
cmp    $0xd,%al
je     1180 <ReadUStarTag+0x30>
cmp    $0xa,%al
je     1180 <ReadUStarTag+0x30>
mov    %r15,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Error processing UltraStar tag\0AAborting\00"
define i8* @ReadUStarTag(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %4
%5 = load i8*, i8** %2
%6 = icmp ne i8* %5, null
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i8*, i8** %2
%10 = call i8* @DuplicateString(i8* %9)
store i8* %10, i8** %3
br label %11
11: ; preds = %1, %42
%12 = load i8*, i8** %3
%13 = call i64 @strlen(i8* %12)
store i64 %13, i64* %4
%14 = load i64, i64* %4
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %11
%17 = call i32 @puts(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit_wrapper(i32 1)
br label %19
19: ; preds = %16, %11
%20 = load i8*, i8** %3
%21 = load i64, i64* %4
%22 = sub i64 %21, 1
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 13
br i1 %26, label %35, label %27
27: ; preds = %19
%28 = load i8*, i8** %3
%29 = load i64, i64* %4
%30 = sub i64 %29, 1
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = icmp eq i32 %33, 10
br i1 %34, label %35, label %40
35: ; preds = %27, %19
%36 = load i8*, i8** %3
%37 = load i64, i64* %4
%38 = sub i64 %37, 1
%39 = getelementptr inbounds i8, i8* %36, i64 %38
store i8 0, i8* %39
br label %42
40: ; preds = %27
%41 = load i8*, i8** %3
ret i8* %41
42: ; preds = %35
br label %11
}

LLVM IR (-O2):
@.str = [40 x i8] c"Error processing UltraStar tag\0AAborting\00"
define i8* @ReadUStarTag(i8* %0) {
%2 = icmp ne i8* %0, null
%3 = zext i1 %2 to i32
%4 = tail call i32 @assert(i32 %3)
%5 = tail call i8* @DuplicateString(i8* %0)
br label %6
6: ; preds = %16, %1
%7 = tail call i64 @strlen(i8* dereferenceable(1) %5)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %6
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
%11 = tail call i32 @exit_wrapper(i32 1)
br label %12
12: ; preds = %9, %6
%13 = add i64 %7, -1
%14 = getelementptr inbounds i8, i8* %5, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %17 [
i8 13, label %16
i8 10, label %16
]
16: ; preds = %12, %12
store i8 0, i8* %14
br label %6
17: ; preds = %12
ret i8* %5
}