#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 size_t uint8_t;
struct mcp23017 {
  int dummy;
};
struct hd44780 {
  int dummy;
};
typedef int /*<<< orphan*/ int8_t;

/* Variables and functions */
int /*<<< orphan*/ hd44780WriteByte(struct mcp23017 *, struct hd44780 *, char,
                                    int);
size_t strlen(char *);
int8_t hd44780WriteString(struct mcp23017 *mcp23017, struct hd44780 *hd44780,
                          char *string) {
  uint8_t i;
  for (i = 0; i < strlen(string); i++)
    hd44780WriteByte(mcp23017, hd44780, string[i], 1);
  return 0;
}


x86 assembly (clang, -O0):
<hd44780WriteString>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
jae    118c <hd44780WriteString+0x6c>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rax
mov    -0x20(%rbp),%rdx
mov    $0x1,%ecx
movsbl (%rax,%rdx,1),%edx
call   1030 <hd44780WriteByte@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    113c <hd44780WriteString+0x1c>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<hd44780WriteString>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    (%rdx),%al
test   %al,%al
je     1186 <hd44780WriteString+0x66>
mov    %rdx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
movsbl %al,%edx
mov    $0x1,%ecx
call   1030 <hd44780WriteByte@plt>
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    $0x2,%rax
jb     1186 <hd44780WriteString+0x66>
mov    $0x1,%ebx
nopw   0x0(%rax,%rax,1)
movsbl (%r12,%rbx,1),%edx
mov    %r15,%rdi
mov    %r14,%rsi
mov    $0x1,%ecx
call   1030 <hd44780WriteByte@plt>
add    $0x1,%rbx
mov    %r12,%rdi
call   1040 <strlen@plt>
cmp    %rax,%rbx
jb     1160 <hd44780WriteString+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.mcp23017 = type { i32 }
%struct.hd44780 = type { i32 }
define i32 @hd44780WriteString(%struct.mcp23017* %0, %struct.hd44780* %1, i8* %2) {
%4 = alloca %struct.mcp23017*
%5 = alloca %struct.hd44780*
%6 = alloca i8*
%7 = alloca i64
store %struct.mcp23017* %0, %struct.mcp23017** %4
store %struct.hd44780* %1, %struct.hd44780** %5
store i8* %2, i8** %6
store i64 0, i64* %7
br label %8
8: ; preds = %21, %3
%9 = load i64, i64* %7
%10 = load i8*, i8** %6
%11 = call i64 @strlen(i8* %10)
%12 = icmp ult i64 %9, %11
br i1 %12, label %13, label %24
13: ; preds = %8
%14 = load %struct.mcp23017*, %struct.mcp23017** %4
%15 = load %struct.hd44780*, %struct.hd44780** %5
%16 = load i8*, i8** %6
%17 = load i64, i64* %7
%18 = getelementptr inbounds i8, i8* %16, i64 %17
%19 = load i8, i8* %18
%20 = call i32 @hd44780WriteByte(%struct.mcp23017* %14, %struct.hd44780* %15, i8 signext %19, i32 1)
br label %21
21: ; preds = %13
%22 = load i64, i64* %7
%23 = add i64 %22, 1
store i64 %23, i64* %7
br label %8
24: ; preds = %8
ret i32 0
}

LLVM IR (-O2):
%struct.mcp23017 = type { i32 }
%struct.hd44780 = type { i32 }
define i32 @hd44780WriteString(%struct.mcp23017* %0, %struct.hd44780* %1, i8* nocapture %2) {
%4 = load i8, i8* %2
%5 = icmp eq i8 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %3
%7 = tail call i32 @hd44780WriteByte(%struct.mcp23017* %0, %struct.hd44780* %1, i8 signext %4, i32 1)
%8 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%9 = icmp ugt i64 %8, 1
br i1 %9, label %10, label %18
10: ; preds = %6, %10
%11 = phi i64 [ %15, %10 ], [ 1, %6 ]
%12 = getelementptr inbounds i8, i8* %2, i64 %11
%13 = load i8, i8* %12
%14 = tail call i32 @hd44780WriteByte(%struct.mcp23017* %0, %struct.hd44780* %1, i8 signext %13, i32 1)
%15 = add nuw i64 %11, 1
%16 = tail call i64 @strlen(i8* dereferenceable(1) %2)
%17 = icmp ult i64 %15, %16
br i1 %17, label %10, label %18
18: ; preds = %10, %6, %3
ret i32 0
}