#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 getline(char *, int);
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int cur_length;
  int total_length;
  char cur_line[4];
  total_length = 0;
  while ((cur_length = getline(cur_line, 4)) != 0) {
    printf("%s", cur_line);
    total_length = total_length + cur_length;
    if (cur_length < 4) {
      printf("\n");
      printf("line length: %d\n", total_length);
      total_length = 0;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0xc(%rbp)
lea    -0x10(%rbp),%rdi
mov    $0x4,%esi
call   1040 <getline@plt>
mov    %eax,-0x8(%rbp)
cmp    $0x0,%eax
je     11a0 <main+0x80>
lea    -0x10(%rbp),%rsi
lea    0xea5(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%eax
add    -0x8(%rbp),%eax
mov    %eax,-0xc(%rbp)
cmpl   $0x4,-0x8(%rbp)
jge    119b <main+0x7b>
lea    0xe96(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xc(%rbp),%esi
lea    0xe76(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xc(%rbp)
jmp    1136 <main+0x16>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
lea    0xc(%rsp),%rdi
mov    $0x4,%esi
call   1050 <getline@plt>
test   %eax,%eax
je     11b1 <main+0x81>
mov    %eax,%ebx
lea    0xea8(%rip),%r14
lea    0xc(%rsp),%r12
lea    0xe9f(%rip),%r15
xor    %ebp,%ebp
jmp    1183 <main+0x53>
nopl   0x0(%rax,%rax,1)
mov    %r12,%rdi
mov    $0x4,%esi
call   1050 <getline@plt>
mov    %eax,%ebx
test   %eax,%eax
je     11b1 <main+0x81>
mov    %r14,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
add    %ebx,%ebp
cmp    $0x3,%ebx
jg     1170 <main+0x40>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %r15,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %ebp,%ebp
jmp    1170 <main+0x40>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.2 = [17 x i8] c"line length: %d\0A\00"
define i32 @main() {
%1 = alloca [4 x i8]
%2 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%3 = call i32 @getline(i8* %2, i32 4)
%4 = icmp eq i32 %3, 0
br i1 %4, label %18, label %5
5: ; preds = %0, %14
%6 = phi i32 [ %16, %14 ], [ %3, %0 ]
%7 = phi i32 [ %15, %14 ], [ 0, %0 ]
%8 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %2)
%9 = add nsw i32 %6, %7
%10 = icmp slt i32 %6, 4
br i1 %10, label %11, label %14
11: ; preds = %5
%12 = call i32 @putchar(i32 10)
%13 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i32 %9)
br label %14
14: ; preds = %11, %5
%15 = phi i32 [ 0, %11 ], [ %9, %5 ]
%16 = call i32 @getline(i8* %2, i32 4)
%17 = icmp eq i32 %16, 0
br i1 %17, label %18, label %5
18: ; preds = %14, %0
ret i32 0
}