#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 */
unsigned long file_write(unsigned long, unsigned long);
int /*<<< orphan*/ intern(char *);
char string_c_last_char(unsigned long);
unsigned long string_new(char *);
unsigned long toi_funcall(unsigned long, int /*<<< orphan*/, int, ...);
unsigned long int file_puts(unsigned long int recv, unsigned long int arg) {
  unsigned long int bytes;
  unsigned long int strobj;
  strobj = toi_funcall(arg, intern("to_s"), 0);
  bytes = file_write(recv, strobj);
  if (string_c_last_char(strobj) != '\n')
    bytes =
        toi_funcall(bytes, intern("+"), 1, file_write(recv, string_new("\n")));
  return bytes;
}


x86 assembly (clang, -O0):
<file_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    0xe91(%rip),%rdi
call   1060 <intern@plt>
mov    -0x28(%rbp),%rdi
mov    %eax,%esi
xor    %edx,%edx
mov    $0x0,%al
call   1050 <toi_funcall@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1070 <file_write@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <string_c_last_char@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     11fe <file_puts+0xae>
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
lea    0xe49(%rip),%rdi
call   1060 <intern@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x40(%rbp)
lea    0xe34(%rip),%rdi
call   1030 <string_new@plt>
mov    -0x40(%rbp),%rdi
mov    %rax,%rsi
call   1070 <file_write@plt>
mov    -0x38(%rbp),%rdi
mov    -0x2c(%rbp),%esi
mov    %rax,%rcx
mov    $0x1,%edx
mov    $0x0,%al
call   1050 <toi_funcall@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<file_puts>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
lea    0xe9e(%rip),%rdi
call   1060 <intern@plt>
mov    %rbx,%rdi
mov    %eax,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1050 <toi_funcall@plt>
mov    %rax,%rbx
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <file_write@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1040 <string_c_last_char@plt>
cmp    $0xa,%al
jne    119b <file_puts+0x4b>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe63(%rip),%rdi
call   1060 <intern@plt>
mov    %eax,%ebx
lea    0xe57(%rip),%rdi
call   1030 <string_new@plt>
mov    %r15,%rdi
mov    %rax,%rsi
call   1070 <file_write@plt>
mov    %r14,%rdi
mov    %ebx,%esi
mov    $0x1,%edx
mov    %rax,%rcx
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
jmp    1050 <toi_funcall@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"to_s\00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [2 x i8] c"\0A\00"
define i64 @file_puts(i64 %0, i64 %1) {
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i64 %0, i64* %3
store i64 %1, i64* %4
%7 = load i64, i64* %4
%8 = call i32 @intern(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%9 = call i64 (i64, i32, i32, ...) @toi_funcall(i64 %7, i32 %8, i32 0)
store i64 %9, i64* %6
%10 = load i64, i64* %3
%11 = load i64, i64* %6
%12 = call i64 @file_write(i64 %10, i64 %11)
store i64 %12, i64* %5
%13 = load i64, i64* %6
%14 = call signext i8 @string_c_last_char(i64 %13)
%15 = sext i8 %14 to i32
%16 = icmp ne i32 %15, 10
br i1 %16, label %17, label %24
17: ; preds = %2
%18 = load i64, i64* %5
%19 = call i32 @intern(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = load i64, i64* %3
%21 = call i64 @string_new(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = call i64 @file_write(i64 %20, i64 %21)
%23 = call i64 (i64, i32, i32, ...) @toi_funcall(i64 %18, i32 %19, i32 1, i64 %22)
store i64 %23, i64* %5
br label %24
24: ; preds = %17, %2
%25 = load i64, i64* %5
ret i64 %25
}

LLVM IR (-O2):
@.str = [5 x i8] c"to_s\00"
@.str.1 = [2 x i8] c"+\00"
@.str.2 = [2 x i8] c"\0A\00"
define i64 @file_puts(i64 %0, i64 %1) {
%3 = tail call i32 @intern(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 (i64, i32, i32, ...) @toi_funcall(i64 %1, i32 %3, i32 0)
%5 = tail call i64 @file_write(i64 %0, i64 %4)
%6 = tail call signext i8 @string_c_last_char(i64 %4)
%7 = icmp eq i8 %6, 10
br i1 %7, label %13, label %8
8: ; preds = %2
%9 = tail call i32 @intern(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i64 @string_new(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%11 = tail call i64 @file_write(i64 %0, i64 %10)
%12 = tail call i64 (i64, i32, i32, ...) @toi_funcall(i64 %5, i32 %9, i32 1, i64 %11)
br label %13
13: ; preds = %8, %2
%14 = phi i64 [ %12, %8 ], [ %5, %2 ]
ret i64 %14
}