#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 EOF;
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int getchar();
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int getLine(char s[], int maxLength) {
  int c, count, i, validLine = 0;
  while (validLine == 0) {
    count = 0, i = 0;
    while (count <= maxLength && ((c = getchar()) != EOF) && (c != '\n')) {
      s[i++] = c;
      count++;
    }
    if (count > maxLength) {
      printf("Error - max line length is %d characters\n", maxLength);
      printf("Please retype line: ");
    } else
      validLine++;
    fflush(stdin);
  }
  if (c == '\n')
    s[i++] = c;
  s[i] = '\0';
  fflush(stdin);
  return i;
}


x86 assembly (clang, -O0):
<getLine>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    121d <getLine+0xed>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x14(%rbp),%ecx
xor    %eax,%eax
cmp    -0xc(%rbp),%ecx
mov    %al,-0x1d(%rbp)
jg     1199 <getLine+0x69>
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,%ecx
mov    %ecx,-0x10(%rbp)
xor    %eax,%eax
mov    0x2e5c(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x1d(%rbp)
je     1199 <getLine+0x69>
cmpl   $0xa,-0x10(%rbp)
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    11a9 <getLine+0x79>
jmp    11d1 <getLine+0xa1>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    115e <getLine+0x2e>
mov    -0x14(%rbp),%eax
cmp    -0xc(%rbp),%eax
jle    1201 <getLine+0xd1>
mov    -0xc(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe35(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    120a <getLine+0xda>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    0x2dd7(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
jmp    1146 <getLine+0x16>
cmpl   $0xa,-0x10(%rbp)
jne    1241 <getLine+0x111>
mov    -0x10(%rbp),%eax
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x18(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x18(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getLine>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %esi,%r14d
mov    %rdi,%rbx
lea    0x1(%r14),%r15d
mov    0x2e94(%rip),%r12
jmp    117d <getLine+0x4d>
xchg   %ax,%ax
lea    0xea9(%rip),%rdi
mov    %r14d,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xec2(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
mov    0x2e72(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
test   %r14d,%r14d
js     1150 <getLine+0x20>
xor    %r13d,%r13d
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <getchar@plt>
mov    %eax,%ebp
cmp    $0xa,%eax
je     11b3 <getLine+0x83>
cmp    (%r12),%ebp
je     11b3 <getLine+0x83>
mov    %bpl,(%rbx,%r13,1)
add    $0x1,%r13
cmp    %r13,%r15
jne    1190 <getLine+0x60>
jmp    1150 <getLine+0x20>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
cmp    $0xa,%ebp
jne    11d2 <getLine+0xa2>
movb   $0xa,(%rbx,%r13,1)
lea    0x1(%r13),%eax
mov    %eax,%r13d
movslq %r13d,%rbp
movb   $0x0,(%rbx,%rbp,1)
mov    0x2e08(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@EOF = global i32 0
@.str = [42 x i8] c"Error - max line length is %d characters\0A\00"
@.str.1 = [21 x i8] c"Please retype line: \00"
@stdin = global i32 0
define i32 @getLine(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
store i32 0, i32* %8
br label %9
9: ; preds = %47, %2
%10 = load i32, i32* %8
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %50
12: ; preds = %9
store i32 0, i32* %6
store i32 0, i32* %7
br label %13
13: ; preds = %26, %12
%14 = load i32, i32* %6
%15 = load i32, i32* %4
%16 = icmp sle i32 %14, %15
br i1 %16, label %17, label %24
17: ; preds = %13
%18 = call i32 (...) @getchar()
store i32 %18, i32* %5
%19 = load i32, i32* @EOF
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 10
br label %24
24: ; preds = %21, %17, %13
%25 = phi i1 [ false, %17 ], [ false, %13 ], [ %23, %21 ]
br i1 %25, label %26, label %36
26: ; preds = %24
%27 = load i32, i32* %5
%28 = trunc i32 %27 to i8
%29 = load i8*, i8** %3
%30 = load i32, i32* %7
%31 = add nsw i32 %30, 1
store i32 %31, i32* %7
%32 = sext i32 %30 to i64
%33 = getelementptr inbounds i8, i8* %29, i64 %32
store i8 %28, i8* %33
%34 = load i32, i32* %6
%35 = add nsw i32 %34, 1
store i32 %35, i32* %6
br label %13
36: ; preds = %24
%37 = load i32, i32* %6
%38 = load i32, i32* %4
%39 = icmp sgt i32 %37, %38
br i1 %39, label %40, label %44
40: ; preds = %36
%41 = load i32, i32* %4
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
br label %47
44: ; preds = %36
%45 = load i32, i32* %8
%46 = add nsw i32 %45, 1
store i32 %46, i32* %8
br label %47
47: ; preds = %44, %40
%48 = load i32, i32* @stdin
%49 = call i32 @fflush(i32 %48)
br label %9
50: ; preds = %9
%51 = load i32, i32* %5
%52 = icmp eq i32 %51, 10
br i1 %52, label %53, label %61
53: ; preds = %50
%54 = load i32, i32* %5
%55 = trunc i32 %54 to i8
%56 = load i8*, i8** %3
%57 = load i32, i32* %7
%58 = add nsw i32 %57, 1
store i32 %58, i32* %7
%59 = sext i32 %57 to i64
%60 = getelementptr inbounds i8, i8* %56, i64 %59
store i8 %55, i8* %60
br label %61
61: ; preds = %53, %50
%62 = load i8*, i8** %3
%63 = load i32, i32* %7
%64 = sext i32 %63 to i64
%65 = getelementptr inbounds i8, i8* %62, i64 %64
store i8 0, i8* %65
%66 = load i32, i32* @stdin
%67 = call i32 @fflush(i32 %66)
%68 = load i32, i32* %7
ret i32 %68
}

LLVM IR (-O2):
@EOF = global i32 0
@.str = [42 x i8] c"Error - max line length is %d characters\0A\00"
@.str.1 = [21 x i8] c"Please retype line: \00"
@stdin = global i32 0
define i32 @getLine(i8* nocapture writeonly %0, i32 %1) {
%3 = icmp slt i32 %1, 0
%4 = add i32 %1, 1
%5 = zext i32 %4 to i64
br label %6
6: ; preds = %19, %2
br i1 %3, label %19, label %7
7: ; preds = %6, %14
%8 = phi i64 [ %16, %14 ], [ 0, %6 ]
%9 = tail call i32 (...) @getchar()
%10 = load i32, i32* @EOF
%11 = icmp ne i32 %9, %10
%12 = icmp ne i32 %9, 10
%13 = and i1 %12, %11
br i1 %13, label %14, label %24
14: ; preds = %7
%15 = trunc i32 %9 to i8
%16 = add nuw nsw i64 %8, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %8
store i8 %15, i8* %17
%18 = icmp eq i64 %16, %5
br i1 %18, label %19, label %7
19: ; preds = %14, %6
%20 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str, i64 0, i64 0), i32 %1)
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @stdin
%23 = tail call i32 @fflush(i32 %22)
br label %6
24: ; preds = %7
%25 = trunc i64 %8 to i32
%26 = load i32, i32* @stdin
%27 = tail call i32 @fflush(i32 %26)
%28 = icmp eq i32 %9, 10
br i1 %28, label %29, label %34
29: ; preds = %24
%30 = add nsw i32 %25, 1
%31 = shl i64 %8, 32
%32 = ashr exact i64 %31, 32
%33 = getelementptr inbounds i8, i8* %0, i64 %32
store i8 10, i8* %33
br label %34
34: ; preds = %29, %24
%35 = phi i32 [ %30, %29 ], [ %25, %24 ]
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %0, i64 %36
store i8 0, i8* %37
%38 = load i32, i32* @stdin
%39 = tail call i32 @fflush(i32 %38)
ret i32 %35
}