#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*/ fputc(char, int /*<<< orphan*/);
int /*<<< orphan*/ stdout;
int strlen(char *);
int char_test_main2() {
  char *str1 = "helloworld";
  int i;
  int j = strlen(str1);
  for (i = 0; i < j; i++) {
    fputc(str1[i], stdout);
  }
  return 0;
}


x86 assembly (clang, -O0):
<char_test_main2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    117c <char_test_main2+0x5c>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,1),%al
mov    0x2e7c(%rip),%rcx
mov    (%rcx),%esi
movsbl %al,%edi
call   1040 <fputc@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1146 <char_test_main2+0x26>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_test_main2>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xed1(%rip),%r14
mov    %r14,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    1167 <char_test_main2+0x47>
mov    %eax,%r15d
xor    %ebx,%ebx
mov    0x2e99(%rip),%r12
nopw   0x0(%rax,%rax,1)
movsbl (%rbx,%r14,1),%edi
mov    (%r12),%esi
call   1040 <fputc@plt>
add    $0x1,%rbx
cmp    %rbx,%r15
jne    1150 <char_test_main2+0x30>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [11 x i8] c"helloworld\00"
@stdout = global i32 0
define i32 @char_test_main2() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i32
store i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8** %1
%4 = load i8*, i8** %1
%5 = call i32 @strlen(i8* %4)
store i32 %5, i32* %3
store i32 0, i32* %2
br label %6
6: ; preds = %18, %0
%7 = load i32, i32* %2
%8 = load i32, i32* %3
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %21
10: ; preds = %6
%11 = load i8*, i8** %1
%12 = load i32, i32* %2
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %11, i64 %13
%15 = load i8, i8* %14
%16 = load i32, i32* @stdout
%17 = call i32 @fputc(i8 signext %15, i32 %16)
br label %18
18: ; preds = %10
%19 = load i32, i32* %2
%20 = add nsw i32 %19, 1
store i32 %20, i32* %2
br label %6
21: ; preds = %6
ret i32 0
}

LLVM IR (-O2):
@.str = [11 x i8] c"helloworld\00"
@stdout = global i32 0
define i32 @char_test_main2() {
%1 = tail call i32 @strlen(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0))
%2 = icmp sgt i32 %1, 0
br i1 %2, label %3, label %13
3: ; preds = %0
%4 = zext i32 %1 to i64
br label %5
5: ; preds = %3, %5
%6 = phi i64 [ 0, %3 ], [ %11, %5 ]
%7 = getelementptr inbounds [11 x i8], [11 x i8]* @.str, i64 0, i64 %6
%8 = load i8, i8* %7
%9 = load i32, i32* @stdout
%10 = tail call i32 @fputc(i8 signext %8, i32 %9)
%11 = add nuw nsw i64 %6, 1
%12 = icmp eq i64 %11, %4
br i1 %12, label %13, label %5
13: ; preds = %5, %0
ret i32 0
}