#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 */
char *malloc(int);
int /*<<< orphan*/ parse(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
char *countAndSay(int n) {
  if (n < 1) {
    return NULL;
  }
  char *result;
  char *prev = malloc(10000);
  char *next = malloc(10000);
  strcpy(prev, "1");
  if (n == 1) {
    return prev;
  }
  int i;
  for (i = 2; i <= n; i++) {
    if (i & 0x1) {
      parse(next, prev);
      result = prev;
    } else {
      parse(prev, next);
      result = next;
    }
  }
  return result;
}


x86 assembly (clang, -O0):
<countAndSay>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
cmpl   $0x1,-0xc(%rbp)
jge    1152 <countAndSay+0x22>
movq   $0x0,-0x8(%rbp)
jmp    1201 <countAndSay+0xd1>
mov    $0x2710,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    $0x2710,%edi
call   1040 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
lea    0xe87(%rip),%rsi
call   1030 <strcpy@plt>
cmpl   $0x1,-0xc(%rbp)
jne    1195 <countAndSay+0x65>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1201 <countAndSay+0xd1>
movl   $0x2,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0xc(%rbp),%eax
jg     11f9 <countAndSay+0xc9>
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     11d1 <countAndSay+0xa1>
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1050 <parse@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11e6 <countAndSay+0xb6>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1050 <parse@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    11eb <countAndSay+0xbb>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    119c <countAndSay+0x6c>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<countAndSay>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
jle    1173 <countAndSay+0x43>
mov    %edi,%r14d
mov    $0x2710,%edi
call   1040 <malloc@plt>
mov    %rax,%r15
mov    $0x2710,%edi
call   1040 <malloc@plt>
mov    %rax,%r12
lea    0xea0(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
cmp    $0x1,%r14d
jne    1181 <countAndSay+0x51>
mov    %r15,%rax
jmp    1175 <countAndSay+0x45>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
neg    %r14d
mov    $0x2,%ebx
jmp    11b1 <countAndSay+0x81>
nopl   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    %r12,%rsi
call   1050 <parse@plt>
mov    %r12,%rax
lea    (%r14,%rbx,1),%ecx
add    $0x1,%ecx
mov    %ebx,%edx
add    $0x1,%edx
mov    %edx,%ebx
cmp    $0x1,%ecx
je     1175 <countAndSay+0x45>
test   $0x1,%bl
je     1190 <countAndSay+0x60>
mov    %r12,%rdi
mov    %r15,%rsi
call   1050 <parse@plt>
mov    %r15,%rax
jmp    119e <countAndSay+0x6e>

LLVM IR (-O0):
@.str = [2 x i8] c"1\00"
define i8* @countAndSay(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
store i32 %0, i32* %3
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 1
br i1 %9, label %10, label %11
10: ; preds = %1
store i8* null, i8** %2
br label %45
11: ; preds = %1
%12 = call i8* @malloc(i32 10000)
store i8* %12, i8** %5
%13 = call i8* @malloc(i32 10000)
store i8* %13, i8** %6
%14 = load i8*, i8** %5
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* %3
%17 = icmp eq i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %11
%19 = load i8*, i8** %5
store i8* %19, i8** %2
br label %45
20: ; preds = %11
store i32 2, i32* %7
br label %21
21: ; preds = %40, %20
%22 = load i32, i32* %7
%23 = load i32, i32* %3
%24 = icmp sle i32 %22, %23
br i1 %24, label %25, label %43
25: ; preds = %21
%26 = load i32, i32* %7
%27 = and i32 %26, 1
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %34
29: ; preds = %25
%30 = load i8*, i8** %6
%31 = load i8*, i8** %5
%32 = call i32 @parse(i8* %30, i8* %31)
%33 = load i8*, i8** %5
store i8* %33, i8** %4
br label %39
34: ; preds = %25
%35 = load i8*, i8** %5
%36 = load i8*, i8** %6
%37 = call i32 @parse(i8* %35, i8* %36)
%38 = load i8*, i8** %6
store i8* %38, i8** %4
br label %39
39: ; preds = %34, %29
br label %40
40: ; preds = %39
%41 = load i32, i32* %7
%42 = add nsw i32 %41, 1
store i32 %42, i32* %7
br label %21
43: ; preds = %21
%44 = load i8*, i8** %4
store i8* %44, i8** %2
br label %45
45: ; preds = %43, %18, %10
%46 = load i8*, i8** %2
ret i8* %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"1\00"
define i8* @countAndSay(i32 %0) {
%2 = icmp slt i32 %0, 1
br i1 %2, label %20, label %3
3: ; preds = %1
%4 = tail call dereferenceable_or_null(10000) i8* @malloc(i32 10000)
%5 = tail call dereferenceable_or_null(10000) i8* @malloc(i32 10000)
%6 = tail call i32 @strcpy(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%7 = icmp eq i32 %0, 1
br i1 %7, label %20, label %8
8: ; preds = %3, %16
%9 = phi i32 [ %18, %16 ], [ 2, %3 ]
%10 = and i32 %9, 1
%11 = icmp eq i32 %10, 0
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @parse(i8* %5, i8* %4)
br label %16
14: ; preds = %8
%15 = tail call i32 @parse(i8* %4, i8* %5)
br label %16
16: ; preds = %12, %14
%17 = phi i8* [ %4, %12 ], [ %5, %14 ]
%18 = add nuw i32 %9, 1
%19 = icmp eq i32 %9, %0
br i1 %19, label %20, label %8
20: ; preds = %16, %3, %1
%21 = phi i8* [ null, %1 ], [ %4, %3 ], [ %17, %16 ]
ret i8* %21
}