#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__ my_malloc(int);
char nuc_id_to_char(unsigned char const);
char *nuc_ids_to_str(char *buf, const unsigned char *ids, const long len) {
  long i;
  if (buf == NULL) {
    buf = ((char *)my_malloc(sizeof(char) * len + 1));
  }
  for (i = 0; i < len; i++) {
    buf[i] = nuc_id_to_char(ids[i]);
  }
  buf[len] = '\0';
  return buf;
}


x86 assembly (clang, -O0):
<nuc_ids_to_str>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
cmpq   $0x0,-0x8(%rbp)
jne    1156 <nuc_ids_to_str+0x36>
mov    -0x18(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1030 <my_malloc@plt>
mov    %rax,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
jge    119b <nuc_ids_to_str+0x7b>
mov    -0x10(%rbp),%rax
mov    -0x20(%rbp),%rcx
movzbl (%rax,%rcx,1),%edi
call   1040 <nuc_id_to_char@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    115e <nuc_ids_to_str+0x3e>
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nuc_ids_to_str>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
test   %rdi,%rdi
je     113d <nuc_ids_to_str+0x1d>
test   %r15,%r15
jg     114e <nuc_ids_to_str+0x2e>
jmp    1167 <nuc_ids_to_str+0x47>
lea    0x1(%r15),%edi
call   1030 <my_malloc@plt>
mov    %rax,%r12
test   %r15,%r15
jle    1167 <nuc_ids_to_str+0x47>
xor    %ebx,%ebx
movzbl (%r14,%rbx,1),%edi
call   1040 <nuc_id_to_char@plt>
mov    %al,(%r12,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <nuc_ids_to_str+0x30>
movb   $0x0,(%r12,%r15,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @nuc_ids_to_str(i8* %0, i8* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store i64 %2, i64* %6
%8 = load i8*, i8** %4
%9 = icmp eq i8* %8, null
br i1 %9, label %10, label %17
10: ; preds = %3
%11 = load i64, i64* %6
%12 = mul i64 1, %11
%13 = add i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i64 @my_malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %4
br label %17
17: ; preds = %10, %3
store i64 0, i64* %7
br label %18
18: ; preds = %31, %17
%19 = load i64, i64* %7
%20 = load i64, i64* %6
%21 = icmp slt i64 %19, %20
br i1 %21, label %22, label %34
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = load i64, i64* %7
%25 = getelementptr inbounds i8, i8* %23, i64 %24
%26 = load i8, i8* %25
%27 = call signext i8 @nuc_id_to_char(i8 zeroext %26)
%28 = load i8*, i8** %4
%29 = load i64, i64* %7
%30 = getelementptr inbounds i8, i8* %28, i64 %29
store i8 %27, i8* %30
br label %31
31: ; preds = %22
%32 = load i64, i64* %7
%33 = add nsw i64 %32, 1
store i64 %33, i64* %7
br label %18
34: ; preds = %18
%35 = load i8*, i8** %4
%36 = load i64, i64* %6
%37 = getelementptr inbounds i8, i8* %35, i64 %36
store i8 0, i8* %37
%38 = load i8*, i8** %4
ret i8* %38
}

LLVM IR (-O2):
define i8* @nuc_ids_to_str(i8* writeonly %0, i8* nocapture %1, i64 %2) {
%4 = icmp eq i8* %0, null
br i1 %4, label %5, label %10
5: ; preds = %3
%6 = trunc i64 %2 to i32
%7 = add i32 %6, 1
%8 = tail call i64 @my_malloc(i32 %7)
%9 = inttoptr i64 %8 to i8*
br label %10
10: ; preds = %5, %3
%11 = phi i8* [ %9, %5 ], [ %0, %3 ]
%12 = icmp sgt i64 %2, 0
br i1 %12, label %13, label %21
13: ; preds = %10, %13
%14 = phi i64 [ %19, %13 ], [ 0, %10 ]
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15
%17 = tail call signext i8 @nuc_id_to_char(i8 zeroext %16)
%18 = getelementptr inbounds i8, i8* %11, i64 %14
store i8 %17, i8* %18
%19 = add nuw nsw i64 %14, 1
%20 = icmp eq i64 %19, %2
br i1 %20, label %21, label %13
21: ; preds = %13, %10
%22 = getelementptr inbounds i8, i8* %11, i64 %2
store i8 0, i8* %22
ret i8* %11
}