#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 */
struct ht16k33_7Segment {
  int dummy;
};

/* Variables and functions */
int ht16k337Seg_printAscii(struct ht16k33_7Segment *, int, char);
int strnlen(char *, int);
int ht16k337Seg_printStrInternal(struct ht16k33_7Segment *device,
                                 char *string) {
  int len = strnlen(string, 4);
  len = len < 4 ? len : 4;
  for (int i = 0; i < len; i++) {
    int ret = ht16k337Seg_printAscii(device, i, string[i]);
    if (ret < 0) {
      return ret;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<ht16k337Seg_printStrInternal>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    $0x4,%esi
call   1030 <strnlen@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    1156 <ht16k337Seg_printStrInternal+0x36>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x28(%rbp)
jmp    1163 <ht16k337Seg_printStrInternal+0x43>
mov    $0x4,%eax
mov    %eax,-0x28(%rbp)
jmp    1163 <ht16k337Seg_printStrInternal+0x43>
mov    -0x28(%rbp),%eax
mov    %eax,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11bf <ht16k337Seg_printStrInternal+0x9f>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x18(%rbp),%rax
movslq -0x20(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
call   1040 <ht16k337Seg_printAscii@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jge    11ac <ht16k337Seg_printStrInternal+0x8c>
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    11c6 <ht16k337Seg_printStrInternal+0xa6>
jmp    11b1 <ht16k337Seg_printStrInternal+0x91>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    1170 <ht16k337Seg_printStrInternal+0x50>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ht16k337Seg_printStrInternal>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
mov    $0x4,%r12d
mov    %rsi,%rdi
mov    $0x4,%esi
call   1030 <strnlen@plt>
test   %eax,%eax
jle    116c <ht16k337Seg_printStrInternal+0x4c>
cmp    $0x4,%eax
cmovb  %eax,%r12d
xor    %ebx,%ebx
xchg   %ax,%ax
movsbl (%r15,%rbx,1),%edx
mov    %r14,%rdi
mov    %ebx,%esi
call   1040 <ht16k337Seg_printAscii@plt>
test   %eax,%eax
js     116e <ht16k337Seg_printStrInternal+0x4e>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1150 <ht16k337Seg_printStrInternal+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.ht16k33_7Segment = type { i32 }
define i32 @ht16k337Seg_printStrInternal(%struct.ht16k33_7Segment* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.ht16k33_7Segment*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store %struct.ht16k33_7Segment* %0, %struct.ht16k33_7Segment** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %5
%10 = call i32 @strnlen(i8* %9, i32 4)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp slt i32 %11, 4
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = load i32, i32* %6
br label %16
15: ; preds = %2
br label %16
16: ; preds = %15, %13
%17 = phi i32 [ %14, %13 ], [ 4, %15 ]
store i32 %17, i32* %6
store i32 0, i32* %7
br label %18
18: ; preds = %36, %16
%19 = load i32, i32* %7
%20 = load i32, i32* %6
%21 = icmp slt i32 %19, %20
br i1 %21, label %22, label %39
22: ; preds = %18
%23 = load %struct.ht16k33_7Segment*, %struct.ht16k33_7Segment** %4
%24 = load i32, i32* %7
%25 = load i8*, i8** %5
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i8, i8* %25, i64 %27
%29 = load i8, i8* %28
%30 = call i32 @ht16k337Seg_printAscii(%struct.ht16k33_7Segment* %23, i32 %24, i8 signext %29)
store i32 %30, i32* %8
%31 = load i32, i32* %8
%32 = icmp slt i32 %31, 0
br i1 %32, label %33, label %35
33: ; preds = %22
%34 = load i32, i32* %8
store i32 %34, i32* %3
br label %40
35: ; preds = %22
br label %36
36: ; preds = %35
%37 = load i32, i32* %7
%38 = add nsw i32 %37, 1
store i32 %38, i32* %7
br label %18
39: ; preds = %18
store i32 0, i32* %3
br label %40
40: ; preds = %39, %33
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
%struct.ht16k33_7Segment = type { i32 }
define i32 @ht16k337Seg_printStrInternal(%struct.ht16k33_7Segment* %0, i8* %1) {
%3 = tail call i32 @strnlen(i8* %1, i32 4)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = icmp ult i32 %3, 4
%7 = select i1 %6, i32 %3, i32 4
%8 = zext i32 %7 to i64
br label %11
9: ; preds = %11
%10 = icmp eq i64 %18, %8
br i1 %10, label %19, label %11
11: ; preds = %5, %9
%12 = phi i64 [ 0, %5 ], [ %18, %9 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %12
%14 = load i8, i8* %13
%15 = trunc i64 %12 to i32
%16 = tail call i32 @ht16k337Seg_printAscii(%struct.ht16k33_7Segment* %0, i32 %15, i8 signext %14)
%17 = icmp slt i32 %16, 0
%18 = add nuw nsw i64 %12, 1
br i1 %17, label %19, label %9
19: ; preds = %11, %9, %2
%20 = phi i32 [ 0, %2 ], [ 0, %9 ], [ %16, %11 ]
ret i32 %20
}