#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*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ setMessageToDisplay(char *);
int strlen(char *);
int /*<<< orphan*/ usleep(int);
void scrollText(char *text) {
  int i, len = strlen(text);
  char *out = malloc(16);
  for (i = 0; i <= (len - 16); i++) {
    memset(out, ' ', 16);
    memcpy(out, text + i, 16);
    setMessageToDisplay(out);
    usleep(200000);
  }
  for (i = 1; i < 16; i++) {
    memset(out, ' ', 16);
    memcpy(out, text + len + i - 16, 16 - i);
    setMessageToDisplay(out);
    usleep(200000);
  }
  memcpy(out, text, 16);
  setMessageToDisplay(out);
  free(out);
}


x86 assembly (clang, -O0):
<scrollText>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    -0x10(%rbp),%ecx
sub    $0x10,%ecx
cmp    %ecx,%eax
jg     11fb <scrollText+0x8b>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1060 <setMessageToDisplay@plt>
mov    $0x30d40,%edi
call   1090 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    119d <scrollText+0x2d>
movl   $0x1,-0xc(%rbp)
cmpl   $0x10,-0xc(%rbp)
jge    1267 <scrollText+0xf7>
mov    -0x18(%rbp),%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
movslq -0x10(%rbp),%rax
add    %rax,%rsi
movslq -0xc(%rbp),%rax
add    %rax,%rsi
add    $0xfffffffffffffff0,%rsi
mov    $0x10,%edx
sub    -0xc(%rbp),%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1060 <setMessageToDisplay@plt>
mov    $0x30d40,%edi
call   1090 <usleep@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1202 <scrollText+0x92>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    -0x18(%rbp),%rdi
call   1060 <setMessageToDisplay@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scrollText>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
call   1040 <strlen@plt>
mov    %eax,%r15d
mov    $0x10,%edi
call   1080 <malloc@plt>
mov    %rax,%r12
cmp    $0x10,%r15d
jl     11de <scrollText+0x6e>
lea    -0xf(%r15),%r13d
mov    %r14,%rbx
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %rbx,%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    %r12,%rdi
call   1060 <setMessageToDisplay@plt>
mov    $0x30d40,%edi
call   1090 <usleep@plt>
add    $0x1,%rbx
add    $0xffffffffffffffff,%r13
jne    11a0 <scrollText+0x30>
movslq %r15d,%rax
lea    (%rax,%r14,1),%r15
add    $0xfffffffffffffff1,%r15
mov    $0xf,%ebx
xchg   %ax,%ax
mov    %r12,%rdi
mov    $0x20,%esi
mov    $0x10,%edx
call   1050 <memset@plt>
mov    %r12,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1070 <memcpy@plt>
mov    %r12,%rdi
call   1060 <setMessageToDisplay@plt>
mov    $0x30d40,%edi
call   1090 <usleep@plt>
add    $0x1,%r15
add    $0xffffffffffffffff,%rbx
jne    11f0 <scrollText+0x80>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x10,%edx
call   1070 <memcpy@plt>
mov    %r12,%rdi
call   1060 <setMessageToDisplay@plt>
mov    %r12,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1030 <free@plt>

LLVM IR (-O0):
define void @scrollText(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32 @strlen(i8* %6)
store i32 %7, i32* %4
%8 = call i8* @malloc(i32 16)
store i8* %8, i8** %5
store i32 0, i32* %3
br label %9
9: ; preds = %26, %1
%10 = load i32, i32* %3
%11 = load i32, i32* %4
%12 = sub nsw i32 %11, 16
%13 = icmp sle i32 %10, %12
br i1 %13, label %14, label %29
14: ; preds = %9
%15 = load i8*, i8** %5
%16 = call i32 @memset(i8* %15, i8 signext 32, i32 16)
%17 = load i8*, i8** %5
%18 = load i8*, i8** %2
%19 = load i32, i32* %3
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = call i32 @memcpy(i8* %17, i8* %21, i32 16)
%23 = load i8*, i8** %5
%24 = call i32 @setMessageToDisplay(i8* %23)
%25 = call i32 @usleep(i32 200000)
br label %26
26: ; preds = %14
%27 = load i32, i32* %3
%28 = add nsw i32 %27, 1
store i32 %28, i32* %3
br label %9
29: ; preds = %9
store i32 1, i32* %3
br label %30
30: ; preds = %51, %29
%31 = load i32, i32* %3
%32 = icmp slt i32 %31, 16
br i1 %32, label %33, label %54
33: ; preds = %30
%34 = load i8*, i8** %5
%35 = call i32 @memset(i8* %34, i8 signext 32, i32 16)
%36 = load i8*, i8** %5
%37 = load i8*, i8** %2
%38 = load i32, i32* %4
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8, i8* %37, i64 %39
%41 = load i32, i32* %3
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8, i8* %40, i64 %42
%44 = getelementptr inbounds i8, i8* %43, i64 -16
%45 = load i32, i32* %3
%46 = sub nsw i32 16, %45
%47 = call i32 @memcpy(i8* %36, i8* %44, i32 %46)
%48 = load i8*, i8** %5
%49 = call i32 @setMessageToDisplay(i8* %48)
%50 = call i32 @usleep(i32 200000)
br label %51
51: ; preds = %33
%52 = load i32, i32* %3
%53 = add nsw i32 %52, 1
store i32 %53, i32* %3
br label %30
54: ; preds = %30
%55 = load i8*, i8** %5
%56 = load i8*, i8** %2
%57 = call i32 @memcpy(i8* %55, i8* %56, i32 16)
%58 = load i8*, i8** %5
%59 = call i32 @setMessageToDisplay(i8* %58)
%60 = load i8*, i8** %5
%61 = call i32 @free(i8* %60)
ret void
}

LLVM IR (-O2):
define void @scrollText(i8* %0) {
%2 = tail call i32 @strlen(i8* %0)
%3 = tail call dereferenceable_or_null(16) i8* @malloc(i32 16)
%4 = icmp slt i32 %2, 16
br i1 %4, label %8, label %5
5: ; preds = %1
%6 = add nsw i32 %2, -15
%7 = zext i32 %6 to i64
br label %12
8: ; preds = %12, %1
%9 = sext i32 %2 to i64
%10 = getelementptr inbounds i8, i8* %0, i64 %9
%11 = getelementptr inbounds i8, i8* %10, i64 -16
br label %21
12: ; preds = %5, %12
%13 = phi i64 [ 0, %5 ], [ %19, %12 ]
%14 = tail call i32 @memset(i8* %3, i8 signext 32, i32 16)
%15 = getelementptr inbounds i8, i8* %0, i64 %13
%16 = tail call i32 @memcpy(i8* %3, i8* %15, i32 16)
%17 = tail call i32 @setMessageToDisplay(i8* %3)
%18 = tail call i32 @usleep(i32 200000)
%19 = add nuw nsw i64 %13, 1
%20 = icmp eq i64 %19, %7
br i1 %20, label %8, label %12
21: ; preds = %8, %21
%22 = phi i64 [ 1, %8 ], [ %30, %21 ]
%23 = tail call i32 @memset(i8* %3, i8 signext 32, i32 16)
%24 = getelementptr inbounds i8, i8* %11, i64 %22
%25 = trunc i64 %22 to i32
%26 = sub i32 16, %25
%27 = tail call i32 @memcpy(i8* %3, i8* %24, i32 %26)
%28 = tail call i32 @setMessageToDisplay(i8* %3)
%29 = tail call i32 @usleep(i32 200000)
%30 = add nuw nsw i64 %22, 1
%31 = icmp eq i64 %30, 16
br i1 %31, label %32, label %21
32: ; preds = %21
%33 = tail call i32 @memcpy(i8* %3, i8* %0, i32 16)
%34 = tail call i32 @setMessageToDisplay(i8* %3)
%35 = tail call i32 @free(i8* %3)
ret void
}