#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 getl(char *, int);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ reverse(char *, int);
int main() {
  int len;
  char line[1024];
  while ((len = getl(line, 1024)) > 0) {
    if (len > 1) {
      printf("Before reverse: %s", line);
      reverse(line, len);
      printf("After reverse: %s", line);
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x410(%rbp),%rdi
mov    $0x400,%esi
call   1040 <getl@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
jle    11a3 <main+0x73>
cmpl   $0x1,-0x8(%rbp)
jle    119e <main+0x6e>
lea    -0x410(%rbp),%rsi
lea    0xe89(%rip),%rdi
call   1050 <printf@plt>
lea    -0x410(%rbp),%rdi
mov    -0x8(%rbp),%esi
call   1030 <reverse@plt>
lea    -0x410(%rbp),%rsi
lea    0xe7a(%rip),%rdi
call   1050 <printf@plt>
jmp    1142 <main+0x12>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsp,%rdi
mov    $0x400,%esi
call   1040 <getl@plt>
test   %eax,%eax
jle    11aa <main+0x7a>
mov    %eax,%ebp
mov    %rsp,%rbx
lea    0xea6(%rip),%r14
lea    0xeb2(%rip),%r15
jmp    1183 <main+0x53>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x400,%esi
call   1040 <getl@plt>
mov    %eax,%ebp
test   %eax,%eax
jle    11aa <main+0x7a>
cmp    $0x1,%ebp
je     1170 <main+0x40>
mov    %r14,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1030 <reverse@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <printf@plt>
jmp    1170 <main+0x40>
xor    %eax,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Before reverse: %s\00"
@.str.1 = [18 x i8] c"After reverse: %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [1024 x i8]
store i32 0, i32* %1
br label %4
4: ; preds = %19, %0
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%6 = call i32 @getl(i8* %5, i32 1024)
store i32 %6, i32* %2
%7 = icmp sgt i32 %6, 0
br i1 %7, label %8, label %20
8: ; preds = %4
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 1
br i1 %10, label %11, label %19
11: ; preds = %8
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%13 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %12)
%14 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%15 = load i32, i32* %2
%16 = call i32 @reverse(i8* %14, i32 %15)
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%18 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %11, %8
br label %4
20: ; preds = %4
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
@.str = [19 x i8] c"Before reverse: %s\00"
@.str.1 = [18 x i8] c"After reverse: %s\00"
define i32 @main() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = call i32 @getl(i8* %2, i32 1024)
%4 = icmp sgt i32 %3, 0
br i1 %4, label %5, label %15
5: ; preds = %0, %12
%6 = phi i32 [ %13, %12 ], [ %3, %0 ]
%7 = icmp eq i32 %6, 1
br i1 %7, label %12, label %8
8: ; preds = %5
%9 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %2)
%10 = call i32 @reverse(i8* %2, i32 %6)
%11 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %12
12: ; preds = %8, %5
%13 = call i32 @getl(i8* %2, i32 1024)
%14 = icmp sgt i32 %13, 0
br i1 %14, label %5, label %15
15: ; preds = %12, %0
ret i32 0
}