#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 writelines(char *lineptr[], int nlines, int reverse) {
  while (nlines-- > 0)
    if (reverse)
      printf("%s\n", lineptr[nlines]);
    else
      printf("%s\n", *lineptr++);
}


x86 assembly (clang, -O0):
<writelines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1180 <writelines+0x70>
cmpl   $0x0,-0x10(%rbp)
je     115d <writelines+0x4d>
mov    -0x8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xead(%rip),%rdi
call   1030 <printf@plt>
jmp    117b <writelines+0x6b>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%rsi
lea    0xe8a(%rip),%rdi
call   1030 <printf@plt>
jmp    1122 <writelines+0x12>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writelines>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    1173 <writelines+0x63>
mov    %edx,%r15d
mov    %rdi,%rbx
xor    %r12d,%r12d
test   %edx,%edx
sete   %r12b
mov    %esi,%ebp
add    $0x1,%rbp
shl    $0x3,%r12
xor    %r13d,%r13d
lea    0xebe(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
lea    -0x2(%rbp),%eax
test   %r15d,%r15d
cmove  %r13,%rax
mov    (%rbx,%rax,8),%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbp
add    %r12,%rbx
cmp    $0x1,%rbp
ja     1150 <writelines+0x40>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

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