#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 */
typedef char uint8_t;

/* Variables and functions */
int /*<<< orphan*/ _write(int, char *, int);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
void _oled_puts(int fd, char *s) {
  int len = strlen(s) + 1;
  uint8_t *buf = malloc(len + 2);
  if (!buf) {
    fprintf(stderr, "out of memory\n");
    exit(1);
  }
  buf[0] = 'T';
  buf[1] = 'T';
  memcpy(&buf[2], s, len);
  _write(fd, buf, len + 2);
  free(buf);
}


x86 assembly (clang, -O0):
<_oled_puts>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x14(%rbp),%edi
add    $0x2,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c7 <_oled_puts+0x57>
mov    0x2e31(%rip),%rax
mov    (%rax),%edi
lea    0xe48(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    -0x20(%rbp),%rax
movb   $0x54,(%rax)
mov    -0x20(%rbp),%rax
movb   $0x54,0x1(%rax)
mov    -0x20(%rbp),%rdi
add    $0x2,%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <memcpy@plt>
mov    -0x4(%rbp),%edi
mov    -0x20(%rbp),%rsi
mov    -0x14(%rbp),%edx
add    $0x2,%edx
call   1080 <_write@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_oled_puts>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rsi,%r15
mov    %edi,%r14d
mov    %rsi,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
lea    0x3(%rbp),%r12d
mov    %r12d,%edi
call   1070 <malloc@plt>
test   %rax,%rax
je     11d3 <_oled_puts+0x63>
mov    %rax,%rbx
add    $0x1,%ebp
movw   $0x5454,(%rax)
mov    %rax,%rdi
add    $0x2,%rdi
mov    %r15,%rsi
mov    %ebp,%edx
call   1060 <memcpy@plt>
mov    %r14d,%edi
mov    %rbx,%rsi
mov    %r12d,%edx
call   1080 <_write@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <free@plt>
mov    0x2e06(%rip),%rax
mov    (%rax),%edi
lea    0xe1d(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
define void @_oled_puts(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i32 %0, i32* %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i32 @strlen(i8* %7)
%9 = add nsw i32 %8, 1
store i32 %9, i32* %5
%10 = load i32, i32* %5
%11 = add nsw i32 %10, 2
%12 = call i8* @malloc(i32 %11)
store i8* %12, i8** %6
%13 = load i8*, i8** %6
%14 = icmp ne i8* %13, null
br i1 %14, label %19, label %15
15: ; preds = %2
%16 = load i32, i32* @stderr
%17 = call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %2
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i64 0
store i8 84, i8* %21
%22 = load i8*, i8** %6
%23 = getelementptr inbounds i8, i8* %22, i64 1
store i8 84, i8* %23
%24 = load i8*, i8** %6
%25 = getelementptr inbounds i8, i8* %24, i64 2
%26 = load i8*, i8** %4
%27 = load i32, i32* %5
%28 = call i32 @memcpy(i8* %25, i8* %26, i32 %27)
%29 = load i32, i32* %3
%30 = load i8*, i8** %6
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 2
%33 = call i32 @_write(i32 %29, i8* %30, i32 %32)
%34 = load i8*, i8** %6
%35 = call i32 @free(i8* %34)
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [15 x i8] c"out of memory\0A\00"
define void @_oled_puts(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = add nsw i32 %3, 3
%5 = tail call i8* @malloc(i32 %4)
%6 = icmp eq i8* %5, null
br i1 %6, label %7, label %11
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0))
%10 = tail call i32 @exit(i32 1)
unreachable
11: ; preds = %2
%12 = add nsw i32 %3, 1
store i8 84, i8* %5
%13 = getelementptr inbounds i8, i8* %5, i64 1
store i8 84, i8* %13
%14 = getelementptr inbounds i8, i8* %5, i64 2
%15 = tail call i32 @memcpy(i8* %14, i8* %1, i32 %12)
%16 = tail call i32 @_write(i32 %0, i8* %5, i32 %4)
%17 = tail call i32 @free(i8* %5)
ret void
}