#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*/ SetBackColor(int, int, int, unsigned char *);
int /*<<< orphan*/ font_blit(unsigned char *, unsigned char *, int, int);
int get_width(short *, char *, int);
int /*<<< orphan*/ picture(short *, char *, unsigned char *, int, int);
int /*<<< orphan*/ zfree(unsigned char *);
scalar_t__ zmalloc(int);
unsigned char *__attribute__((stdcall))
text_out_mem(short *string, char *buffer, int height, int color,
             int back_color) {
  unsigned char *from_zone;
  unsigned char *to_zone;
  int px, py;
  unsigned char app_data[1024];
  int width;
  width = get_width(string, buffer, height);
  from_zone = (char *)zmalloc(3 * height * width + 4);
  to_zone = (char *)zmalloc(height * width);
  *(int *)from_zone = width;
  SetBackColor(back_color, width, height, from_zone + 4);
  picture(string, buffer, to_zone, width, height);
  font_blit(from_zone + 4, to_zone, color, width * height);
  zfree(to_zone);
  return from_zone;
}


x86 assembly (clang, -O0):
<text_out_mem>:
push   %rbp
mov    %rsp,%rbp
sub    $0x450,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1060 <get_width@plt>
mov    %eax,-0x444(%rbp)
imul   $0x3,-0x14(%rbp),%edi
imul   -0x444(%rbp),%edi
add    $0x4,%edi
call   1050 <zmalloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
imul   -0x444(%rbp),%edi
call   1050 <zmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x444(%rbp),%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x1c(%rbp),%edi
mov    -0x444(%rbp),%esi
mov    -0x14(%rbp),%edx
mov    -0x28(%rbp),%rcx
add    $0x4,%rcx
call   1040 <SetBackColor@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x30(%rbp),%rdx
mov    -0x444(%rbp),%ecx
mov    -0x14(%rbp),%r8d
call   1030 <picture@plt>
mov    -0x28(%rbp),%rdi
add    $0x4,%rdi
mov    -0x30(%rbp),%rsi
mov    -0x18(%rbp),%edx
mov    -0x444(%rbp),%ecx
imul   -0x14(%rbp),%ecx
call   1080 <font_blit@plt>
mov    -0x30(%rbp),%rdi
call   1070 <zfree@plt>
mov    -0x28(%rbp),%rax
add    $0x450,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<text_out_mem>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r8d,(%rsp)
mov    %ecx,0x4(%rsp)
mov    %edx,%ebp
mov    %rsi,0x10(%rsp)
mov    %rdi,0x8(%rsp)
call   1060 <get_width@plt>
mov    %eax,%r14d
mov    %eax,%ebx
imul   %ebp,%ebx
lea    (%rbx,%rbx,2),%edi
add    $0x4,%edi
call   1050 <zmalloc@plt>
mov    %rax,%r12
mov    %ebx,%edi
call   1050 <zmalloc@plt>
mov    %rax,%r15
mov    %r14d,(%r12)
lea    0x4(%r12),%r13
mov    (%rsp),%edi
mov    %r14d,%esi
mov    %ebp,%edx
mov    %r13,%rcx
call   1040 <SetBackColor@plt>
mov    0x8(%rsp),%rdi
mov    0x10(%rsp),%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
mov    %ebp,%r8d
call   1030 <picture@plt>
mov    %r13,%rdi
mov    %r15,%rsi
mov    0x4(%rsp),%edx
mov    %ebx,%ecx
call   1080 <font_blit@plt>
mov    %r15,%rdi
call   1070 <zfree@plt>
mov    %r12,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i8* @text_out_mem(i16* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i16*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i32
%14 = alloca i32
%15 = alloca [1024 x i8]
%16 = alloca i32
store i16* %0, i16** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i32 %3, i32* %9
store i32 %4, i32* %10
%17 = load i16*, i16** %6
%18 = load i8*, i8** %7
%19 = load i32, i32* %8
%20 = call i32 @get_width(i16* %17, i8* %18, i32 %19)
store i32 %20, i32* %16
%21 = load i32, i32* %8
%22 = mul nsw i32 3, %21
%23 = load i32, i32* %16
%24 = mul nsw i32 %22, %23
%25 = add nsw i32 %24, 4
%26 = call i64 @zmalloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
store i8* %27, i8** %11
%28 = load i32, i32* %8
%29 = load i32, i32* %16
%30 = mul nsw i32 %28, %29
%31 = call i64 @zmalloc(i32 %30)
%32 = inttoptr i64 %31 to i8*
store i8* %32, i8** %12
%33 = load i32, i32* %16
%34 = load i8*, i8** %11
%35 = bitcast i8* %34 to i32*
store i32 %33, i32* %35
%36 = load i32, i32* %10
%37 = load i32, i32* %16
%38 = load i32, i32* %8
%39 = load i8*, i8** %11
%40 = getelementptr inbounds i8, i8* %39, i64 4
%41 = call i32 @SetBackColor(i32 %36, i32 %37, i32 %38, i8* %40)
%42 = load i16*, i16** %6
%43 = load i8*, i8** %7
%44 = load i8*, i8** %12
%45 = load i32, i32* %16
%46 = load i32, i32* %8
%47 = call i32 @picture(i16* %42, i8* %43, i8* %44, i32 %45, i32 %46)
%48 = load i8*, i8** %11
%49 = getelementptr inbounds i8, i8* %48, i64 4
%50 = load i8*, i8** %12
%51 = load i32, i32* %9
%52 = load i32, i32* %16
%53 = load i32, i32* %8
%54 = mul nsw i32 %52, %53
%55 = call i32 @font_blit(i8* %49, i8* %50, i32 %51, i32 %54)
%56 = load i8*, i8** %12
%57 = call i32 @zfree(i8* %56)
%58 = load i8*, i8** %11
ret i8* %58
}

LLVM IR (-O2):
define i8* @text_out_mem(i16* %0, i8* %1, i32 %2, i32 %3, i32 %4) {
%6 = tail call i32 @get_width(i16* %0, i8* %1, i32 %2)
%7 = mul i32 %6, %2
%8 = mul i32 %7, 3
%9 = add nsw i32 %8, 4
%10 = tail call i64 @zmalloc(i32 %9)
%11 = inttoptr i64 %10 to i8*
%12 = tail call i64 @zmalloc(i32 %7)
%13 = inttoptr i64 %12 to i8*
%14 = inttoptr i64 %10 to i32*
store i32 %6, i32* %14
%15 = getelementptr inbounds i8, i8* %11, i64 4
%16 = tail call i32 @SetBackColor(i32 %4, i32 %6, i32 %2, i8* %15)
%17 = tail call i32 @picture(i16* %0, i8* %1, i8* %13, i32 %6, i32 %2)
%18 = tail call i32 @font_blit(i8* %15, i8* %13, i32 %3, i32 %7)
%19 = tail call i32 @zfree(i8* %13)
ret i8* %11
}