#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*/ assert(char *);
char codon_to_amino(char *);
char *malloc(int);
int strlen(char *);
char *rna_to_protein(char *rna) {
  char *s, *ret;
  ret = malloc(strlen(rna) / 3 + 1);
  assert(ret);
  for (s = ret; *rna != '\0'; rna += 3, s++) {
    *s = codon_to_amino(rna);
    if (*s < 0)
      return NULL;
    if (!*s)
      break;
  }
  *s = '\0';
  return ret;
}


x86 assembly (clang, -O0):
<rna_to_protein>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    $0x3,%ecx
cltd
idiv   %ecx
mov    %eax,%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11ee <rna_to_protein+0xae>
mov    -0x10(%rbp),%rdi
call   1060 <codon_to_amino@plt>
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %cl,(%rax)
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jge    11ba <rna_to_protein+0x7a>
movq   $0x0,-0x8(%rbp)
jmp    11fd <rna_to_protein+0xbd>
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
jne    11cc <rna_to_protein+0x8c>
jmp    11ee <rna_to_protein+0xae>
jmp    11d1 <rna_to_protein+0x91>
mov    -0x10(%rbp),%rax
add    $0x3,%rax
mov    %rax,-0x10(%rbp)
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    117c <rna_to_protein+0x3c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rna_to_protein>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r15
call   1030 <strlen@plt>
cltq
imul   $0x55555556,%rax,%rax
mov    %rax,%rcx
shr    $0x20,%rcx
shr    $0x3f,%rax
lea    (%rcx,%rax,1),%edi
add    $0x1,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
call   1040 <assert@plt>
cmpb   $0x0,(%r15)
mov    %r14,%rbx
je     11af <rna_to_protein+0x6f>
mov    %r14,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1060 <codon_to_amino@plt>
mov    %al,(%rbx)
test   %al,%al
js     11b4 <rna_to_protein+0x74>
je     11af <rna_to_protein+0x6f>
add    $0x1,%rbx
cmpb   $0x0,0x3(%r15)
lea    0x3(%r15),%r15
jne    1190 <rna_to_protein+0x50>
movb   $0x0,(%rbx)
jmp    11b7 <rna_to_protein+0x77>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @rna_to_protein(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %3
%6 = load i8*, i8** %3
%7 = call i32 @strlen(i8* %6)
%8 = sdiv i32 %7, 3
%9 = add nsw i32 %8, 1
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %5
%11 = load i8*, i8** %5
%12 = call i32 @assert(i8* %11)
%13 = load i8*, i8** %5
store i8* %13, i8** %4
br label %14
14: ; preds = %34, %1
%15 = load i8*, i8** %3
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %39
19: ; preds = %14
%20 = load i8*, i8** %3
%21 = call signext i8 @codon_to_amino(i8* %20)
%22 = load i8*, i8** %4
store i8 %21, i8* %22
%23 = load i8*, i8** %4
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp slt i32 %25, 0
br i1 %26, label %27, label %28
27: ; preds = %19
store i8* null, i8** %2
br label %42
28: ; preds = %19
%29 = load i8*, i8** %4
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %33, label %32
32: ; preds = %28
br label %39
33: ; preds = %28
br label %34
34: ; preds = %33
%35 = load i8*, i8** %3
%36 = getelementptr inbounds i8, i8* %35, i64 3
store i8* %36, i8** %3
%37 = load i8*, i8** %4
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %4
br label %14
39: ; preds = %32, %14
%40 = load i8*, i8** %4
store i8 0, i8* %40
%41 = load i8*, i8** %5
store i8* %41, i8** %2
br label %42
42: ; preds = %39, %27
%43 = load i8*, i8** %2
ret i8* %43
}

LLVM IR (-O2):
define i8* @rna_to_protein(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = sdiv i32 %2, 3
%4 = add nsw i32 %3, 1
%5 = tail call i8* @malloc(i32 %4)
%6 = tail call i32 @assert(i8* %5)
%7 = load i8, i8* %0
%8 = icmp eq i8 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %1, %16
%10 = phi i8* [ %18, %16 ], [ %5, %1 ]
%11 = phi i8* [ %17, %16 ], [ %0, %1 ]
%12 = tail call signext i8 @codon_to_amino(i8* %11)
store i8 %12, i8* %10
%13 = icmp slt i8 %12, 0
br i1 %13, label %23, label %14
14: ; preds = %9
%15 = icmp eq i8 %12, 0
br i1 %15, label %21, label %16
16: ; preds = %14
%17 = getelementptr inbounds i8, i8* %11, i64 3
%18 = getelementptr inbounds i8, i8* %10, i64 1
%19 = load i8, i8* %17
%20 = icmp eq i8 %19, 0
br i1 %20, label %21, label %9
21: ; preds = %16, %14, %1
%22 = phi i8* [ %5, %1 ], [ %10, %14 ], [ %18, %16 ]
store i8 0, i8* %22
br label %23
23: ; preds = %9, %21
%24 = phi i8* [ %5, %21 ], [ null, %9 ]
ret i8* %24
}