#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*/ lcdputchar(int, char);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int strlen(char *);
int lcdputstring(int fd, char *string) {
  int i;
  if (strlen(string) == 0)
    return -1;
  if (strlen(string) > 16) {
    sprintf(string, "%16s", string);
  }
  for (i = 0; i < strlen(string); i++) {
    lcdputchar(fd, string[i]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<lcdputstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
jne    115d <lcdputstring+0x2d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11cf <lcdputstring+0x9f>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x10,%eax
jle    1183 <lcdputstring+0x53>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe82(%rip),%rsi
call   1050 <sprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11c8 <lcdputstring+0x98>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%esi
call   1040 <lcdputchar@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    118a <lcdputstring+0x5a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<lcdputstring>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%r15d
mov    %rsi,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     11a1 <lcdputstring+0x71>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cmp    $0x11,%eax
jl     1168 <lcdputstring+0x38>
lea    0xea3(%rip),%rsi
mov    %rbx,%rdi
mov    %rbx,%rdx
call   1050 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
xor    %r14d,%r14d
test   %eax,%eax
jle    11a7 <lcdputstring+0x77>
xor    %ebp,%ebp
nopl   0x0(%rax)
movsbl (%rbx,%rbp,1),%esi
mov    %r15d,%edi
call   1040 <lcdputchar@plt>
add    $0x1,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jl     1180 <lcdputstring+0x50>
jmp    11a7 <lcdputstring+0x77>
mov    $0xffffffff,%r14d
mov    %r14d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%16s\00"
define i32 @lcdputstring(i32 %0, i8* %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
%7 = load i8*, i8** %5
%8 = call i32 @strlen(i8* %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %2
store i32 -1, i32* %3
br label %37
11: ; preds = %2
%12 = load i8*, i8** %5
%13 = call i32 @strlen(i8* %12)
%14 = icmp sgt i32 %13, 16
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = load i8*, i8** %5
%17 = load i8*, i8** %5
%18 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %15, %11
store i32 0, i32* %6
br label %20
20: ; preds = %33, %19
%21 = load i32, i32* %6
%22 = load i8*, i8** %5
%23 = call i32 @strlen(i8* %22)
%24 = icmp slt i32 %21, %23
br i1 %24, label %25, label %36
25: ; preds = %20
%26 = load i32, i32* %4
%27 = load i8*, i8** %5
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8, i8* %30
%32 = call i32 @lcdputchar(i32 %26, i8 signext %31)
br label %33
33: ; preds = %25
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %20
36: ; preds = %20
store i32 0, i32* %3
br label %37
37: ; preds = %36, %10
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [5 x i8] c"%16s\00"
define i32 @lcdputstring(i32 %0, i8* %1) {
%3 = tail call i32 @strlen(i8* %1)
%4 = icmp eq i32 %3, 0
br i1 %4, label %22, label %5
5: ; preds = %2
%6 = tail call i32 @strlen(i8* %1)
%7 = icmp sgt i32 %6, 16
br i1 %7, label %8, label %10
8: ; preds = %5
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %1, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %1)
br label %10
10: ; preds = %8, %5
%11 = tail call i32 @strlen(i8* %1)
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %22
13: ; preds = %10, %13
%14 = phi i64 [ %18, %13 ], [ 0, %10 ]
%15 = getelementptr inbounds i8, i8* %1, i64 %14
%16 = load i8, i8* %15
%17 = tail call i32 @lcdputchar(i32 %0, i8 signext %16)
%18 = add nuw nsw i64 %14, 1
%19 = tail call i32 @strlen(i8* %1)
%20 = sext i32 %19 to i64
%21 = icmp slt i64 %18, %20
br i1 %21, label %13, label %22
22: ; preds = %13, %10, %2
%23 = phi i32 [ -1, %2 ], [ 0, %10 ], [ 0, %13 ]
ret i32 %23
}