#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*/ Die(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ isalpha(char);
scalar_t__ islower(char);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
char toupper(char);
void PrepareSequence(char *s, char **ret_seq, int *ret_L) {
  int L;
  int pos;
  int badchar = 0;
  char *seq;
  L = strlen(s);
  if ((seq = (char *)malloc(sizeof(char) * (L + 3))) == NULL)
    Die("malloc failed");
  strcpy(seq + 1, s);
  for (pos = 1; pos <= L; pos++) {
    if (islower(seq[pos]))
      seq[pos] = toupper(seq[pos]);
    else if (!isalpha(seq[pos])) {
      seq[pos] = 'X';
      badchar++;
    }
  }
  seq[0] = seq[L + 1] = 'X';
  seq[L + 2] = '\0';
  if (badchar)
    fprintf(stderr, "Warning: converted %d non-alphabetic characters to X\n",
            badchar);
  *ret_seq = seq;
  if (ret_L != NULL)
    *ret_L = L;
}


x86 assembly (clang, -O0):
<PrepareSequence>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <strlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x3,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    11d4 <PrepareSequence+0x54>
lea    0xe31(%rip),%rdi
call   1090 <Die@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
mov    -0x8(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     127d <PrepareSequence+0xfd>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <islower@plt>
cmp    $0x0,%rax
je     1236 <PrepareSequence+0xb6>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1050 <toupper@plt>
mov    %al,%dl
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    126a <PrepareSequence+0xea>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   10a0 <isalpha@plt>
cmp    $0x0,%eax
jne    1265 <PrepareSequence+0xe5>
mov    -0x30(%rbp),%rax
movslq -0x20(%rbp),%rcx
movb   $0x58,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    126a <PrepareSequence+0xea>
jmp    126f <PrepareSequence+0xef>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11ec <PrepareSequence+0x6c>
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x58,(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
movb   $0x58,(%rax)
mov    -0x30(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
cmpl   $0x0,-0x24(%rbp)
je     12c8 <PrepareSequence+0x148>
mov    0x2d29(%rip),%rax
mov    (%rax),%edi
mov    -0x24(%rbp),%edx
lea    0xd4b(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x18(%rbp)
je     12e7 <PrepareSequence+0x167>
mov    -0x1c(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<PrepareSequence>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,0x10(%rsp)
mov    %rsi,0x8(%rsp)
mov    %rdi,%rbp
call   1060 <strlen@plt>
mov    %eax,%r12d
lea    0x3(%r12),%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11c1 <PrepareSequence+0x41>
lea    0xe44(%rip),%rdi
call   1090 <Die@plt>
mov    %rbx,%rdi
add    $0x1,%rdi
mov    %rbp,%rsi
call   1030 <strcpy@plt>
lea    0x1(%r12),%r13d
test   %r12d,%r12d
jle    122c <PrepareSequence+0xac>
mov    %r13d,%r14d
xor    %ebp,%ebp
mov    $0x1,%r15d
jmp    1202 <PrepareSequence+0x82>
nopw   0x0(%rax,%rax,1)
call   1050 <toupper@plt>
mov    %al,(%rbx,%r15,1)
add    $0x1,%r15
cmp    %r15,%r14
je     122e <PrepareSequence+0xae>
movsbl (%rbx,%r15,1),%edi
call   1040 <islower@plt>
movzbl (%rbx,%r15,1),%ecx
movsbl %cl,%edi
test   %rax,%rax
jne    11f0 <PrepareSequence+0x70>
call   10a0 <isalpha@plt>
test   %eax,%eax
jne    11f9 <PrepareSequence+0x79>
movb   $0x58,(%rbx,%r15,1)
add    $0x1,%ebp
jmp    11f9 <PrepareSequence+0x79>
xor    %ebp,%ebp
movslq %r13d,%rax
movb   $0x58,(%rbx,%rax,1)
movb   $0x58,(%rbx)
movslq %r12d,%rax
movb   $0x0,0x2(%rax,%rbx,1)
test   %ebp,%ebp
je     125b <PrepareSequence+0xdb>
mov    0x2d95(%rip),%rax
mov    (%rax),%edi
lea    0xdba(%rip),%rsi
mov    %ebp,%edx
call   1070 <fprintf@plt>
mov    0x8(%rsp),%rax
mov    %rbx,(%rax)
mov    0x10(%rsp),%rax
test   %rax,%rax
je     1270 <PrepareSequence+0xf0>
mov    %r12d,(%rax)
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [14 x i8] c"malloc failed\00"
@stderr = global i32 0
@.str.1 = [54 x i8] c"Warning: converted %d non-alphabetic characters to X\0A\00"
define void @PrepareSequence(i8* %0, i8** %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
store i32 0, i32* %9
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %7
%13 = load i32, i32* %7
%14 = add nsw i32 %13, 3
%15 = sext i32 %14 to i64
%16 = mul i64 1, %15
%17 = trunc i64 %16 to i32
%18 = call i64 @malloc(i32 %17)
%19 = inttoptr i64 %18 to i8*
store i8* %19, i8** %10
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %3
%22 = call i32 @Die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %23
23: ; preds = %21, %3
%24 = load i8*, i8** %10
%25 = getelementptr inbounds i8, i8* %24, i64 1
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %25, i8* %26)
store i32 1, i32* %8
br label %28
28: ; preds = %68, %23
%29 = load i32, i32* %8
%30 = load i32, i32* %7
%31 = icmp sle i32 %29, %30
br i1 %31, label %32, label %71
32: ; preds = %28
%33 = load i8*, i8** %10
%34 = load i32, i32* %8
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8, i8* %33, i64 %35
%37 = load i8, i8* %36
%38 = call i64 @islower(i8 signext %37)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %51
40: ; preds = %32
%41 = load i8*, i8** %10
%42 = load i32, i32* %8
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %41, i64 %43
%45 = load i8, i8* %44
%46 = call signext i8 @toupper(i8 signext %45)
%47 = load i8*, i8** %10
%48 = load i32, i32* %8
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8, i8* %47, i64 %49
store i8 %46, i8* %50
br label %67
51: ; preds = %32
%52 = load i8*, i8** %10
%53 = load i32, i32* %8
%54 = sext i32 %53 to i64
%55 = getelementptr inbounds i8, i8* %52, i64 %54
%56 = load i8, i8* %55
%57 = call i32 @isalpha(i8 signext %56)
%58 = icmp ne i32 %57, 0
br i1 %58, label %66, label %59
59: ; preds = %51
%60 = load i8*, i8** %10
%61 = load i32, i32* %8
%62 = sext i32 %61 to i64
%63 = getelementptr inbounds i8, i8* %60, i64 %62
store i8 88, i8* %63
%64 = load i32, i32* %9
%65 = add nsw i32 %64, 1
store i32 %65, i32* %9
br label %66
66: ; preds = %59, %51
br label %67
67: ; preds = %66, %40
br label %68
68: ; preds = %67
%69 = load i32, i32* %8
%70 = add nsw i32 %69, 1
store i32 %70, i32* %8
br label %28
71: ; preds = %28
%72 = load i8*, i8** %10
%73 = load i32, i32* %7
%74 = add nsw i32 %73, 1
%75 = sext i32 %74 to i64
%76 = getelementptr inbounds i8, i8* %72, i64 %75
store i8 88, i8* %76
%77 = load i8*, i8** %10
%78 = getelementptr inbounds i8, i8* %77, i64 0
store i8 88, i8* %78
%79 = load i8*, i8** %10
%80 = load i32, i32* %7
%81 = add nsw i32 %80, 2
%82 = sext i32 %81 to i64
%83 = getelementptr inbounds i8, i8* %79, i64 %82
store i8 0, i8* %83
%84 = load i32, i32* %9
%85 = icmp ne i32 %84, 0
br i1 %85, label %86, label %90
86: ; preds = %71
%87 = load i32, i32* @stderr
%88 = load i32, i32* %9
%89 = call i32 @fprintf(i32 %87, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %88)
br label %90
90: ; preds = %86, %71
%91 = load i8*, i8** %10
%92 = load i8**, i8*** %5
store i8* %91, i8** %92
%93 = load i32*, i32** %6
%94 = icmp ne i32* %93, null
br i1 %94, label %95, label %98
95: ; preds = %90
%96 = load i32, i32* %7
%97 = load i32*, i32** %6
store i32 %96, i32* %97
br label %98
98: ; preds = %95, %90
ret void
}

LLVM IR (-O2):
@.str = [14 x i8] c"malloc failed\00"
@stderr = global i32 0
@.str.1 = [54 x i8] c"Warning: converted %d non-alphabetic characters to X\0A\00"
define void @PrepareSequence(i8* %0, i8** nocapture writeonly %1, i32* writeonly %2) {
%4 = tail call i32 @strlen(i8* %0)
%5 = add nsw i32 %4, 3
%6 = tail call i64 @malloc(i32 %5)
%7 = inttoptr i64 %6 to i8*
%8 = icmp eq i64 %6, 0
br i1 %8, label %9, label %11
9: ; preds = %3
%10 = tail call i32 @Die(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %3
%12 = getelementptr inbounds i8, i8* %7, i64 1
%13 = tail call i32 @strcpy(i8* %12, i8* %0)
%14 = icmp slt i32 %4, 1
%15 = add i32 %4, 1
br i1 %14, label %37, label %16
16: ; preds = %11
%17 = zext i32 %15 to i64
br label %18
18: ; preds = %16, %33
%19 = phi i64 [ 1, %16 ], [ %35, %33 ]
%20 = phi i32 [ 0, %16 ], [ %34, %33 ]
%21 = getelementptr inbounds i8, i8* %7, i64 %19
%22 = load i8, i8* %21
%23 = tail call i64 @islower(i8 signext %22)
%24 = icmp eq i64 %23, 0
%25 = load i8, i8* %21
br i1 %24, label %28, label %26
26: ; preds = %18
%27 = tail call signext i8 @toupper(i8 signext %25)
store i8 %27, i8* %21
br label %33
28: ; preds = %18
%29 = tail call i32 @isalpha(i8 signext %25)
%30 = icmp eq i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %28
store i8 88, i8* %21
%32 = add nsw i32 %20, 1
br label %33
33: ; preds = %26, %31, %28
%34 = phi i32 [ %20, %26 ], [ %20, %28 ], [ %32, %31 ]
%35 = add nuw nsw i64 %19, 1
%36 = icmp eq i64 %35, %17
br i1 %36, label %37, label %18
37: ; preds = %33, %11
%38 = phi i32 [ 0, %11 ], [ %34, %33 ]
%39 = sext i32 %15 to i64
%40 = getelementptr inbounds i8, i8* %7, i64 %39
store i8 88, i8* %40
store i8 88, i8* %7
%41 = add nsw i32 %4, 2
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %7, i64 %42
store i8 0, i8* %43
%44 = icmp eq i32 %38, 0
br i1 %44, label %48, label %45
45: ; preds = %37
%46 = load i32, i32* @stderr
%47 = tail call i32 @fprintf(i32 %46, i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %48
48: ; preds = %45, %37
store i8* %7, i8** %1
%49 = icmp eq i32* %2, null
br i1 %49, label %51, label %50
50: ; preds = %48
store i32 %4, i32* %2
br label %51
51: ; preds = %50, %48
ret void
}