#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*/ fprintf(int /*<<< orphan*/, char *, int);
scalar_t__ malloc(int);
int randomish();
int /*<<< orphan*/ stderr;
char *generate_random_dna(int len) {
  char *bases = "AGTC";
  char *dna, *dnaptr;
  int i;
  if ((dnaptr = dna = (char *)malloc(len)) == NULL)
    fprintf(stderr, "Error: failed to allocate random DNA of size %d!\n", len);
  else
    for (i = 0; i < len; i++)
      *dnaptr++ = bases[(randomish() % 4)];
  return dna;
}


x86 assembly (clang, -O0):
<generate_random_dna>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
lea    0xebe(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x4(%rbp),%edi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117d <generate_random_dna+0x4d>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%edx
lea    0xe92(%rip),%rsi
call   1030 <fprintf@plt>
jmp    11d5 <generate_random_dna+0xa5>
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x4(%rbp),%eax
jge    11d0 <generate_random_dna+0xa0>
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1040 <randomish@plt>
mov    $0x4,%ecx
cltd
idiv   %ecx
mov    -0x30(%rbp),%rax
movslq %edx,%rcx
mov    (%rax,%rcx,1),%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <generate_random_dna+0x54>
jmp    11d5 <generate_random_dna+0xa5>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generate_random_dna>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %edi,%ebp
call   1050 <malloc@plt>
mov    %rax,%r15
test   %rax,%rax
je     1189 <generate_random_dna+0x59>
test   %ebp,%ebp
jle    11a0 <generate_random_dna+0x70>
mov    %ebp,%ebp
lea    0xead(%rip),%r14
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <randomish@plt>
lea    0x3(%rax),%ecx
test   %eax,%eax
cmovns %eax,%ecx
and    $0xfffffffc,%ecx
sub    %ecx,%eax
cltq
movzbl (%rax,%r14,1),%eax
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
cmp    %ebx,%ebp
jne    1160 <generate_random_dna+0x30>
jmp    11a0 <generate_random_dna+0x70>
mov    0x2e50(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
mov    %ebp,%edx
call   1030 <fprintf@plt>
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"AGTC\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"Error: failed to allocate random DNA of size %d!\0A\00"
define i8* @generate_random_dna(i32 %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %2
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8** %3
%7 = load i32, i32* %2
%8 = call i64 @malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %4
store i8* %9, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %11, label %15
11: ; preds = %1
%12 = load i32, i32* @stderr
%13 = load i32, i32* %2
%14 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %13)
br label %33
15: ; preds = %1
store i32 0, i32* %6
br label %16
16: ; preds = %29, %15
%17 = load i32, i32* %6
%18 = load i32, i32* %2
%19 = icmp slt i32 %17, %18
br i1 %19, label %20, label %32
20: ; preds = %16
%21 = load i8*, i8** %3
%22 = call i32 (...) @randomish()
%23 = srem i32 %22, 4
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
%26 = load i8, i8* %25
%27 = load i8*, i8** %5
%28 = getelementptr inbounds i8, i8* %27, i32 1
store i8* %28, i8** %5
store i8 %26, i8* %27
br label %29
29: ; preds = %20
%30 = load i32, i32* %6
%31 = add nsw i32 %30, 1
store i32 %31, i32* %6
br label %16
32: ; preds = %16
br label %33
33: ; preds = %32, %11
%34 = load i8*, i8** %4
ret i8* %34
}

LLVM IR (-O2):
@.str = [5 x i8] c"AGTC\00"
@stderr = global i32 0
@.str.1 = [50 x i8] c"Error: failed to allocate random DNA of size %d!\0A\00"
define i8* @generate_random_dna(i32 %0) {
%2 = tail call i64 @malloc(i32 %0)
%3 = inttoptr i64 %2 to i8*
%4 = icmp eq i64 %2, 0
br i1 %4, label %7, label %5
5: ; preds = %1
%6 = icmp sgt i32 %0, 0
br i1 %6, label %10, label %21
7: ; preds = %1
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.1, i64 0, i64 0), i32 %0)
br label %21
10: ; preds = %5, %10
%11 = phi i32 [ %19, %10 ], [ 0, %5 ]
%12 = phi i8* [ %18, %10 ], [ %3, %5 ]
%13 = tail call i32 (...) @randomish()
%14 = srem i32 %13, 4
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [5 x i8], [5 x i8]* @.str, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = getelementptr inbounds i8, i8* %12, i64 1
store i8 %17, i8* %12
%19 = add nuw nsw i32 %11, 1
%20 = icmp eq i32 %19, %0
br i1 %20, label %21, label %10
21: ; preds = %10, %5, %7
ret i8* %3
}