#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*/ display_text(int, int, char *, int, int);
char *strchr(char *, char);
int /*<<< orphan*/ strncpy(char *, char const *, int);
void display_multiline_text(int x, int y, const char *inbuf, int color) {
  char tmp[4096];
  char *buf = tmp;
  char *next;
  int y_off = 0;
  strncpy(buf, inbuf, 4095);
  buf[4095] = 0;
  while ((*buf != 0) && (next = strchr(buf, '\n'))) {
    *next = 0;
    display_text(x, y + y_off, buf, color, 1);
    buf = next + 1;
    y_off += 11;
  }
}


x86 assembly (clang, -O0):
<display_multiline_text>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1040,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
lea    -0x1020(%rbp),%rax
mov    %rax,-0x1028(%rbp)
movl   $0x0,-0x1034(%rbp)
mov    -0x1028(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    $0xfff,%edx
call   1030 <strncpy@plt>
mov    -0x1028(%rbp),%rax
movb   $0x0,0xfff(%rax)
mov    -0x1028(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x1035(%rbp)
je     11c3 <display_multiline_text+0x93>
mov    -0x1028(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x1030(%rbp)
cmp    $0x0,%rax
setne  %al
mov    %al,-0x1035(%rbp)
mov    -0x1035(%rbp),%al
test   $0x1,%al
jne    11d6 <display_multiline_text+0xa6>
jmp    1227 <display_multiline_text+0xf7>
mov    -0x1030(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%edi
mov    -0x8(%rbp),%esi
add    -0x1034(%rbp),%esi
mov    -0x1028(%rbp),%rdx
mov    -0x14(%rbp),%ecx
mov    $0x1,%r8d
call   1050 <display_text@plt>
mov    -0x1030(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x1028(%rbp)
mov    -0x1034(%rbp),%eax
add    $0xb,%eax
mov    %eax,-0x1034(%rbp)
jmp    1183 <display_multiline_text+0x53>
add    $0x1040,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<display_multiline_text>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x1000,%rsp
mov    %ecx,%r14d
mov    %esi,%r12d
mov    %edi,%r15d
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    %rdx,%rsi
mov    $0xfff,%edx
call   1030 <strncpy@plt>
movb   $0x0,0xfff(%rsp)
cmpb   $0x0,(%rsp)
je     11b0 <display_multiline_text+0x80>
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11b0 <display_multiline_text+0x80>
mov    %rax,%rbp
movb   $0x0,(%rax)
mov    %r15d,%edi
mov    %r12d,%esi
mov    %rbx,%rdx
mov    %r14d,%ecx
mov    $0x1,%r8d
call   1050 <display_text@plt>
mov    %rbp,%rbx
add    $0x1,%rbx
add    $0xb,%r12d
cmpb   $0x0,0x1(%rbp)
jne    1170 <display_multiline_text+0x40>
add    $0x1000,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @display_multiline_text(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [4096 x i8]
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i32
store i32 %0, i32* %5
store i32 %1, i32* %6
store i8* %2, i8** %7
store i32 %3, i32* %8
%13 = getelementptr inbounds [4096 x i8], [4096 x i8]* %9, i64 0, i64 0
store i8* %13, i8** %10
store i32 0, i32* %12
%14 = load i8*, i8** %10
%15 = load i8*, i8** %7
%16 = call i32 @strncpy(i8* %14, i8* %15, i32 4095)
%17 = load i8*, i8** %10
%18 = getelementptr inbounds i8, i8* %17, i64 4095
store i8 0, i8* %18
br label %19
19: ; preds = %30, %4
%20 = load i8*, i8** %10
%21 = load i8, i8* %20
%22 = sext i8 %21 to i32
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %28
24: ; preds = %19
%25 = load i8*, i8** %10
%26 = call i8* @strchr(i8* %25, i8 signext 10)
store i8* %26, i8** %11
%27 = icmp ne i8* %26, null
br label %28
28: ; preds = %24, %19
%29 = phi i1 [ false, %19 ], [ %27, %24 ]
br i1 %29, label %30, label %43
30: ; preds = %28
%31 = load i8*, i8** %11
store i8 0, i8* %31
%32 = load i32, i32* %5
%33 = load i32, i32* %6
%34 = load i32, i32* %12
%35 = add nsw i32 %33, %34
%36 = load i8*, i8** %10
%37 = load i32, i32* %8
%38 = call i32 @display_text(i32 %32, i32 %35, i8* %36, i32 %37, i32 1)
%39 = load i8*, i8** %11
%40 = getelementptr inbounds i8, i8* %39, i64 1
store i8* %40, i8** %10
%41 = load i32, i32* %12
%42 = add nsw i32 %41, 11
store i32 %42, i32* %12
br label %19
43: ; preds = %28
ret void
}

LLVM IR (-O2):
define void @display_multiline_text(i32 %0, i32 %1, i8* %2, i32 %3) {
%5 = alloca [4096 x i8]
%6 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 0
%7 = call i32 @strncpy(i8* %6, i8* %2, i32 4095)
%8 = getelementptr inbounds [4096 x i8], [4096 x i8]* %5, i64 0, i64 4095
store i8 0, i8* %8
%9 = load i8, i8* %6
%10 = icmp eq i8 %9, 0
br i1 %10, label %23, label %11
11: ; preds = %4, %16
%12 = phi i32 [ %20, %16 ], [ 0, %4 ]
%13 = phi i8* [ %19, %16 ], [ %6, %4 ]
%14 = call i8* @strchr(i8* %13, i8 signext 10)
%15 = icmp eq i8* %14, null
br i1 %15, label %23, label %16
16: ; preds = %11
store i8 0, i8* %14
%17 = add nsw i32 %12, %1
%18 = call i32 @display_text(i32 %0, i32 %17, i8* %13, i32 %3, i32 1)
%19 = getelementptr inbounds i8, i8* %14, i64 1
%20 = add nuw nsw i32 %12, 11
%21 = load i8, i8* %19
%22 = icmp eq i8 %21, 0
br i1 %22, label %23, label %11
23: ; preds = %11, %16, %4
ret void
}