#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*/ printf(char *, char);
void fun(char *ch, char *string) {
  int i, j = 0;
  for (i = 0; ch[i] != '\0'; i++)
    ;
  for (j = i - 1; j >= 0; j--) {
    printf("%c", ch[j]);
  }
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x14(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
je     1156 <fun+0x46>
jmp    1148 <fun+0x38>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    112e <fun+0x1e>
mov    -0x14(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jl     118f <fun+0x7f>
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
lea    0xe88(%rip),%rdi
movsbl (%rax,%rcx,1),%esi
call   1030 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x18(%rbp)
jmp    115f <fun+0x4f>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r15
xor    %ebx,%ebx
nopl   (%rax)
cmpb   $0x0,(%r15,%rbx,1)
lea    0x1(%rbx),%rbx
jne    1120 <fun+0x10>
cmp    $0x1,%ebx
je     115c <fun+0x4c>
lea    -0x1(%rbx),%r12d
add    $0xffffffffffffffff,%r12
lea    0xec1(%rip),%r14
nop
mov    %r12d,%eax
movsbl (%r15,%rax,1),%esi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebx
add    $0xffffffffffffffff,%r12
cmp    $0x1,%ebx
jg     1140 <fun+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
define void @fun(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %5
br label %7
7: ; preds = %16, %2
%8 = load i8*, i8** %3
%9 = load i32, i32* %5
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %8, i64 %10
%12 = load i8, i8* %11
%13 = sext i8 %12 to i32
%14 = icmp ne i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %7
br label %16
16: ; preds = %15
%17 = load i32, i32* %5
%18 = add nsw i32 %17, 1
store i32 %18, i32* %5
br label %7
19: ; preds = %7
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 1
store i32 %21, i32* %6
br label %22
22: ; preds = %32, %19
%23 = load i32, i32* %6
%24 = icmp sge i32 %23, 0
br i1 %24, label %25, label %35
25: ; preds = %22
%26 = load i8*, i8** %3
%27 = load i32, i32* %6
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %26, i64 %28
%30 = load i8, i8* %29
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %30)
br label %32
32: ; preds = %25
%33 = load i32, i32* %6
%34 = add nsw i32 %33, -1
store i32 %34, i32* %6
br label %22
35: ; preds = %22
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
define void @fun(i8* nocapture %0, i8* nocapture readnone %1) {
br label %3
3: ; preds = %3, %2
%4 = phi i64 [ %8, %3 ], [ 0, %2 ]
%5 = getelementptr inbounds i8, i8* %0, i64 %4
%6 = load i8, i8* %5
%7 = icmp eq i8 %6, 0
%8 = add nuw i64 %4, 1
br i1 %7, label %9, label %3
9: ; preds = %3
%10 = trunc i64 %4 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %23, label %12
12: ; preds = %9
%13 = and i64 %4, 4294967295
br label %14
14: ; preds = %12, %14
%15 = phi i64 [ %13, %12 ], [ %16, %14 ]
%16 = add nsw i64 %15, -1
%17 = and i64 %16, 4294967295
%18 = getelementptr inbounds i8, i8* %0, i64 %17
%19 = load i8, i8* %18
%20 = tail call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8 signext %19)
%21 = trunc i64 %15 to i32
%22 = icmp sgt i32 %21, 1
br i1 %22, label %14, label %23
23: ; preds = %14, %9
ret void
}