#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__ malloc(int);
int /*<<< orphan*/ perror(char *);
int *count_bases(char *dna) {
  int *counts = (int *)malloc(4 * sizeof(int));
  if (counts == NULL) {
    perror("Memory allocation failed!");
  }
  for (int i = 0; i < 4; i++) {
    counts[i] = 0;
  }
  for (int i = 0; i < 1000; i++) {
    switch (dna[i]) {
    case 'A':
      counts[0] += 1;
      break;
    case 'C':
      counts[1] += 1;
      break;
    case 'G':
      counts[2] += 1;
      break;
    case 'T':
      counts[3] += 1;
      break;
    default:
      break;
    }
  }
  return counts;
}


x86 assembly (clang, -O0):
<count_bases>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1151 <count_bases+0x31>
lea    0xf04(%rip),%rdi
call   1040 <perror@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0x4,-0x14(%rbp)
jge    117f <count_bases+0x5f>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movl   $0x0,(%rax,%rcx,4)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1158 <count_bases+0x38>
movl   $0x0,-0x18(%rbp)
cmpl   $0x3e8,-0x18(%rbp)
jge    1223 <count_bases+0x103>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
add    $0xffffffbf,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x13,%eax
ja     120b <count_bases+0xeb>
mov    -0x20(%rbp),%rax
lea    0xe44(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    1210 <count_bases+0xf0>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x4(%rax)
jmp    1210 <count_bases+0xf0>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0x8(%rax)
jmp    1210 <count_bases+0xf0>
mov    -0x10(%rbp),%rax
mov    0xc(%rax),%ecx
add    $0x1,%ecx
mov    %ecx,0xc(%rax)
jmp    1210 <count_bases+0xf0>
jmp    1210 <count_bases+0xf0>
jmp    1215 <count_bases+0xf5>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1186 <count_bases+0x66>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<count_bases>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%rbx
mov    $0x10,%edi
call   1030 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     11c4 <count_bases+0xa4>
xorps  %xmm0,%xmm0
movups %xmm0,(%r14)
xor    %r8d,%r8d
lea    0xeb2(%rip),%rcx
xor    %r9d,%r9d
xor    %esi,%esi
xor    %edi,%edi
xor    %eax,%eax
jmp    117c <count_bases+0x5c>
nopl   0x0(%rax)
add    $0x1,%edi
mov    %edi,0xc(%r14)
nopw   0x0(%rax,%rax,1)
add    $0x1,%rax
cmp    $0x3e8,%rax
je     11b9 <count_bases+0x99>
movsbl (%rbx,%rax,1),%edx
add    $0xffffffbf,%edx
cmp    $0x13,%edx
ja     1170 <count_bases+0x50>
movslq (%rcx,%rdx,4),%rdx
add    %rcx,%rdx
jmp    *%rdx
add    $0x1,%r8d
mov    %r8d,(%r14)
jmp    1170 <count_bases+0x50>
nopw   0x0(%rax,%rax,1)
add    $0x1,%r9d
mov    %r9d,0x4(%r14)
jmp    1170 <count_bases+0x50>
nopw   0x0(%rax,%rax,1)
add    $0x1,%esi
mov    %esi,0x8(%r14)
jmp    1170 <count_bases+0x50>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe85(%rip),%rdi
call   1040 <perror@plt>
jmp    113d <count_bases+0x1d>

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

LLVM IR (-O2):
@.str = [26 x i8] c"Memory allocation failed!\00"
define i32* @count_bases(i8* nocapture %0) {
%2 = tail call i64 @malloc(i32 16)
%3 = inttoptr i64 %2 to i32*
%4 = inttoptr i64 %2 to i8*
%5 = icmp eq i64 %2, 0
br i1 %5, label %6, label %8
6: ; preds = %1
%7 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %1
%9 = getelementptr inbounds i32, i32* %3, i64 3
%10 = getelementptr inbounds i32, i32* %3, i64 2
%11 = getelementptr inbounds i32, i32* %3, i64 1
br label %13
12: ; preds = %30
ret i32* %3
13: ; preds = %8, %30
%14 = phi i32 [ 0, %8 ], [ %31, %30 ]
%15 = phi i32 [ 0, %8 ], [ %32, %30 ]
%16 = phi i32 [ 0, %8 ], [ %33, %30 ]
%17 = phi i32 [ 0, %8 ], [ %34, %30 ]
%18 = phi i64 [ 0, %8 ], [ %35, %30 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %18
%20 = load i8, i8* %19
%21 = sext i8 %20 to i32
switch i32 %21, label %30 [
i32 65, label %22
i32 67, label %24
i32 71, label %26
i32 84, label %28
]
22: ; preds = %13
%23 = add nsw i32 %14, 1
store i32 %23, i32* %3
br label %30
24: ; preds = %13
%25 = add nsw i32 %15, 1
store i32 %25, i32* %11
br label %30
26: ; preds = %13
%27 = add nsw i32 %16, 1
store i32 %27, i32* %10
br label %30
28: ; preds = %13
%29 = add nsw i32 %17, 1
store i32 %29, i32* %9
br label %30
30: ; preds = %22, %24, %26, %28, %13
%31 = phi i32 [ %23, %22 ], [ %14, %24 ], [ %14, %26 ], [ %14, %28 ], [ %14, %13 ]
%32 = phi i32 [ %15, %22 ], [ %25, %24 ], [ %15, %26 ], [ %15, %28 ], [ %15, %13 ]
%33 = phi i32 [ %16, %22 ], [ %16, %24 ], [ %27, %26 ], [ %16, %28 ], [ %16, %13 ]
%34 = phi i32 [ %17, %22 ], [ %17, %24 ], [ %17, %26 ], [ %29, %28 ], [ %17, %13 ]
%35 = add nuw nsw i64 %18, 1
%36 = icmp eq i64 %35, 1000
br i1 %36, label %12, label %13
}