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


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
cmp    -0x10(%rbp),%eax
jge    116f <writelines+0x5f>
jmp    1133 <writelines+0x23>
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    116a <writelines+0x5a>
mov    -0x8(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x8(%rbp)
mov    (%rax),%rsi
lea    0xea0(%rip),%rdi
call   1030 <printf@plt>
jmp    1133 <writelines+0x23>
jmp    11b2 <writelines+0xa2>
jmp    1174 <writelines+0x64>
mov    -0x10(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x10(%rbp)
cmp    $0x0,%eax
jle    11ad <writelines+0x9d>
mov    -0x8(%rbp),%rax
mov    -0xc(%rbp),%ecx
sub    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe5d(%rip),%rdi
call   1030 <printf@plt>
jmp    1174 <writelines+0x64>
jmp    11b2 <writelines+0xa2>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writelines>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r15
mov    %esi,%ebx
sub    %edx,%ebx
jge    1149 <writelines+0x39>
mov    %esi,%ebp
test   %esi,%esi
jle    117c <writelines+0x6c>
add    $0x1,%ebp
lea    0xed0(%rip),%r14
mov    (%r15),%rsi
add    $0x8,%r15
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1130 <writelines+0x20>
jmp    117c <writelines+0x6c>
test   %edx,%edx
jle    117c <writelines+0x6c>
mov    %edx,%ebp
add    $0x1,%rbp
lea    0xea6(%rip),%r14
nopw   0x0(%rax,%rax,1)
movslq %ebx,%rbx
mov    (%r15,%rbx,8),%rsi
mov    %r14,%rdi
call   1030 <printf@plt>
add    $0xffffffffffffffff,%rbp
add    $0x1,%ebx
cmp    $0x1,%rbp
ja     1160 <writelines+0x50>
add    $0x8,%rsp
pop    %rbx
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
%7 = load i32, i32* %5
%8 = load i32, i32* %6
%9 = icmp slt i32 %7, %8
br i1 %9, label %10, label %21
10: ; preds = %3
br label %11
11: ; preds = %15, %10
%12 = load i32, i32* %5
%13 = add nsw i32 %12, -1
store i32 %13, i32* %5
%14 = icmp sgt i32 %12, 0
br i1 %14, label %15, label %20
15: ; preds = %11
%16 = load i8**, i8*** %4
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %4
%18 = load i8*, i8** %16
%19 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %18)
br label %11
20: ; preds = %11
br label %37
21: ; preds = %3
br label %22
22: ; preds = %26, %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, -1
store i32 %24, i32* %6
%25 = icmp sgt i32 %23, 0
br i1 %25, label %26, label %36
26: ; preds = %22
%27 = load i8**, i8*** %4
%28 = load i32, i32* %5
%29 = load i32, i32* %6
%30 = sub nsw i32 %28, %29
%31 = sub nsw i32 %30, 1
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %27, i64 %32
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %22
36: ; preds = %22
br label %37
37: ; preds = %36, %20
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 slt i32 %1, %2
br i1 %4, label %9, label %5
5: ; preds = %3
%6 = icmp sgt i32 %2, 0
br i1 %6, label %7, label %29
7: ; preds = %5
%8 = zext i32 %2 to i64
br label %19
9: ; preds = %3
%10 = icmp sgt i32 %1, 0
br i1 %10, label %11, label %29
11: ; preds = %9, %11
%12 = phi i32 [ %14, %11 ], [ %1, %9 ]
%13 = phi i8** [ %15, %11 ], [ %0, %9 ]
%14 = add nsw i32 %12, -1
%15 = getelementptr inbounds i8*, i8** %13, i64 1
%16 = load i8*, i8** %13
%17 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = icmp ugt i32 %12, 1
br i1 %18, label %11, label %29
19: ; preds = %7, %19
%20 = phi i64 [ %8, %7 ], [ %21, %19 ]
%21 = add nsw i64 %20, -1
%22 = trunc i64 %20 to i32
%23 = sub i32 %1, %22
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %0, i64 %24
%26 = load i8*, i8** %25
%27 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %26)
%28 = icmp ugt i64 %20, 1
br i1 %28, label %19, label %29
29: ; preds = %19, %11, %5, %9
ret void
}