#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*/ abort();
int /*<<< orphan*/ empty(int);
int eval(int);
int /*<<< orphan*/ first(int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ is_f(int /*<<< orphan*/);
int rest(int);
int /*<<< orphan*/ stderr;
char to_int(int /*<<< orphan*/);
const char *to_buffer(int list, char *buffer, int bufsize) {
  if (bufsize <= 1) {
    fputs("Buffer too small!\n", stderr);
    abort();
  };
  int eval_list = eval(list);
  if (!is_f(empty(eval_list)))
    *buffer = '\0';
  else {
    *buffer = to_int(first(eval_list));
    to_buffer(rest(list), buffer + 1, bufsize - 1);
  };
  return buffer;
}


x86 assembly (clang, -O0):
<to_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
cmpl   $0x1,-0x14(%rbp)
jg     11c8 <to_buffer+0x38>
mov    0x2e2d(%rip),%rax
mov    (%rax),%esi
lea    0xe44(%rip),%rdi
call   1050 <fputs@plt>
mov    $0x0,%al
call   1030 <abort@plt>
mov    -0x4(%rbp),%edi
call   10a0 <eval@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%edi
call   1070 <empty@plt>
mov    %eax,%edi
call   1040 <is_f@plt>
cmp    $0x0,%eax
jne    11f7 <to_buffer+0x67>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    122b <to_buffer+0x9b>
mov    -0x18(%rbp),%edi
call   10b0 <first@plt>
mov    %eax,%edi
call   1080 <to_int@plt>
mov    %al,%cl
mov    -0x10(%rbp),%rax
mov    %cl,(%rax)
mov    -0x4(%rbp),%edi
call   1060 <rest@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
add    $0x1,%rsi
mov    -0x14(%rbp),%edx
sub    $0x1,%edx
call   1090 <to_buffer@plt>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_buffer>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    $0x2,%edx
jl     11e6 <to_buffer+0x66>
mov    %edx,%r12d
mov    %rsi,%r14
mov    %edi,%r15d
add    $0x1,%r12d
mov    %rsi,%rbp
nopl   (%rax)
mov    %r15d,%edi
call   1090 <eval@plt>
mov    %eax,%ebx
mov    %eax,%edi
call   1070 <empty@plt>
mov    %eax,%edi
call   1040 <is_f@plt>
test   %eax,%eax
je     1202 <to_buffer+0x82>
mov    %ebx,%edi
call   10a0 <first@plt>
mov    %eax,%edi
call   1080 <to_int@plt>
mov    %al,0x0(%rbp)
mov    %r15d,%edi
call   1060 <rest@plt>
mov    %eax,%r15d
add    $0x1,%rbp
add    $0xffffffff,%r12d
cmp    $0x3,%r12d
jge    11a0 <to_buffer+0x20>
mov    0x2df3(%rip),%rax
mov    (%rax),%esi
lea    0xe0a(%rip),%rdi
call   1050 <fputs@plt>
xor    %eax,%eax
call   1030 <abort@plt>
movb   $0x0,0x0(%rbp)
mov    %r14,%rax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Buffer too small!\0A\00"
@stderr = global i32 0
define i8* @to_buffer(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%8 = load i32, i32* %6
%9 = icmp sle i32 %8, 1
br i1 %9, label %10, label %14
10: ; preds = %3
%11 = load i32, i32* @stderr
%12 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = call i32 (...) @abort()
unreachable
14: ; preds = %3
%15 = load i32, i32* %4
%16 = call i32 @eval(i32 %15)
store i32 %16, i32* %7
%17 = load i32, i32* %7
%18 = call i32 @empty(i32 %17)
%19 = call i32 @is_f(i32 %18)
%20 = icmp ne i32 %19, 0
br i1 %20, label %23, label %21
21: ; preds = %14
%22 = load i8*, i8** %5
store i8 0, i8* %22
br label %35
23: ; preds = %14
%24 = load i32, i32* %7
%25 = call i32 @first(i32 %24)
%26 = call signext i8 @to_int(i32 %25)
%27 = load i8*, i8** %5
store i8 %26, i8* %27
%28 = load i32, i32* %4
%29 = call i32 @rest(i32 %28)
%30 = load i8*, i8** %5
%31 = getelementptr inbounds i8, i8* %30, i64 1
%32 = load i32, i32* %6
%33 = sub nsw i32 %32, 1
%34 = call i8* @to_buffer(i32 %29, i8* %31, i32 %33)
br label %35
35: ; preds = %23, %21
%36 = load i8*, i8** %5
ret i8* %36
}

LLVM IR (-O2):
@.str = [19 x i8] c"Buffer too small!\0A\00"
@stderr = global i32 0
define i8* @to_buffer(i32 %0, i8* returned %1, i32 %2) {
%4 = icmp slt i32 %2, 2
br i1 %4, label %5, label %9
5: ; preds = %18, %3
%6 = load i32, i32* @stderr
%7 = tail call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 (...) @abort()
unreachable
9: ; preds = %3, %18
%10 = phi i32 [ %23, %18 ], [ %2, %3 ]
%11 = phi i8* [ %22, %18 ], [ %1, %3 ]
%12 = phi i32 [ %21, %18 ], [ %0, %3 ]
%13 = tail call i32 @eval(i32 %12)
%14 = tail call i32 @empty(i32 %13)
%15 = tail call i32 @is_f(i32 %14)
%16 = icmp eq i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %9
store i8 0, i8* %11
ret i8* %1
18: ; preds = %9
%19 = tail call i32 @first(i32 %13)
%20 = tail call signext i8 @to_int(i32 %19)
store i8 %20, i8* %11
%21 = tail call i32 @rest(i32 %12)
%22 = getelementptr inbounds i8, i8* %11, i64 1
%23 = add nsw i32 %10, -1
%24 = icmp slt i32 %10, 3
br i1 %24, label %5, label %9
}