#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*/ _putchar(char);
int _strlen(char *);
void puts_half(char *str) {
  int length = _strlen(str);
  int i = length / 2;
  length++;
  while (str[i] != '\0') {
    _putchar(str[i]);
    i++;
  }
  _putchar('\n');
}


x86 assembly (clang, -O0):
<puts_half>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <_strlen@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1183 <puts_half+0x63>
mov    -0x8(%rbp),%rax
movslq -0x10(%rbp),%rcx
movsbl (%rax,%rcx,1),%edi
call   1040 <_putchar@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    114f <puts_half+0x2f>
mov    $0xa,%edi
call   1040 <_putchar@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<puts_half>:
push   %rbx
mov    %rdi,%rbx
call   1030 <_strlen@plt>
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
movslq %ecx,%rcx
mov    (%rbx,%rcx,1),%al
test   %al,%al
je     1163 <puts_half+0x43>
add    %rcx,%rbx
add    $0x1,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
movsbl %al,%edi
call   1040 <_putchar@plt>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1150 <puts_half+0x30>
mov    $0xa,%edi
pop    %rbx
jmp    1040 <_putchar@plt>

LLVM IR (-O0):
define void @puts_half(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
store i8* %0, i8** %2
%5 = load i8*, i8** %2
%6 = call i32 @_strlen(i8* %5)
store i32 %6, i32* %3
%7 = load i32, i32* %3
%8 = sdiv i32 %7, 2
store i32 %8, i32* %4
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 1
store i32 %10, i32* %3
br label %11
11: ; preds = %19, %1
%12 = load i8*, i8** %2
%13 = load i32, i32* %4
%14 = sext i32 %13 to i64
%15 = getelementptr inbounds i8, i8* %12, i64 %14
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %28
19: ; preds = %11
%20 = load i8*, i8** %2
%21 = load i32, i32* %4
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8, i8* %20, i64 %22
%24 = load i8, i8* %23
%25 = call i32 @_putchar(i8 signext %24)
%26 = load i32, i32* %4
%27 = add nsw i32 %26, 1
store i32 %27, i32* %4
br label %11
28: ; preds = %11
%29 = call i32 @_putchar(i8 signext 10)
ret void
}

LLVM IR (-O2):
define void @puts_half(i8* %0) {
%2 = tail call i32 @_strlen(i8* %0)
%3 = sdiv i32 %2, 2
%4 = sext i32 %3 to i64
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %1, %8
%9 = phi i64 [ %12, %8 ], [ %4, %1 ]
%10 = phi i8 [ %14, %8 ], [ %6, %1 ]
%11 = tail call i32 @_putchar(i8 signext %10)
%12 = add i64 %9, 1
%13 = getelementptr inbounds i8, i8* %0, i64 %12
%14 = load i8, i8* %13
%15 = icmp eq i8 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %1
%17 = tail call i32 @_putchar(i8 signext 10)
ret void
}