#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*/ term_addch(unsigned char);
size_t term_width();
void xminibuf_write(const char *s) {
  size_t x;
  for (x = 0; *s != '\0' && x < term_width(); s++) {
    term_addch(*(unsigned char *)s);
    ++x;
  }
}


x86 assembly (clang, -O0):
<xminibuf_write>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x11(%rbp)
je     1168 <xminibuf_write+0x48>
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   1040 <term_width@plt>
mov    %rax,%rcx
mov    -0x20(%rbp),%rax
cmp    %rcx,%rax
setb   %al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1178 <xminibuf_write+0x58>
jmp    11a1 <xminibuf_write+0x81>
mov    -0x8(%rbp),%rax
movzbl (%rax),%edi
call   1030 <term_addch@plt>
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    1134 <xminibuf_write+0x14>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xminibuf_write>:
push   %r14
push   %rbx
push   %rax
cmpb   $0x0,(%rdi)
je     1152 <xminibuf_write+0x32>
mov    %rdi,%r14
xor    %ebx,%ebx
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <term_width@plt>
cmp    %rax,%rbx
jae    1152 <xminibuf_write+0x32>
movzbl (%r14,%rbx,1),%edi
call   1030 <term_addch@plt>
cmpb   $0x0,0x1(%r14,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1130 <xminibuf_write+0x10>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define void @xminibuf_write(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
store i8* %0, i8** %2
store i64 0, i64* %3
br label %4
4: ; preds = %21, %1
%5 = load i8*, i8** %2
%6 = load i8, i8* %5
%7 = sext i8 %6 to i32
%8 = icmp ne i32 %7, 0
br i1 %8, label %9, label %13
9: ; preds = %4
%10 = load i64, i64* %3
%11 = call i64 (...) @term_width()
%12 = icmp ult i64 %10, %11
br label %13
13: ; preds = %9, %4
%14 = phi i1 [ false, %4 ], [ %12, %9 ]
br i1 %14, label %15, label %24
15: ; preds = %13
%16 = load i8*, i8** %2
%17 = load i8, i8* %16
%18 = call i32 @term_addch(i8 zeroext %17)
%19 = load i64, i64* %3
%20 = add i64 %19, 1
store i64 %20, i64* %3
br label %21
21: ; preds = %15
%22 = load i8*, i8** %2
%23 = getelementptr inbounds i8, i8* %22, i32 1
store i8* %23, i8** %2
br label %4
24: ; preds = %13
ret void
}

LLVM IR (-O2):
define void @xminibuf_write(i8* nocapture %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %16, label %4
4: ; preds = %1, %9
%5 = phi i64 [ %12, %9 ], [ 0, %1 ]
%6 = phi i8* [ %13, %9 ], [ %0, %1 ]
%7 = tail call i64 (...) @term_width()
%8 = icmp ult i64 %5, %7
br i1 %8, label %9, label %16
9: ; preds = %4
%10 = load i8, i8* %6
%11 = tail call i32 @term_addch(i8 zeroext %10)
%12 = add nuw i64 %5, 1
%13 = getelementptr inbounds i8, i8* %6, i64 1
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %4
16: ; preds = %4, %9, %1
ret void
}