#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 */
char *memchr(char *, char, int);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  char buf[512];
  char *e;
  int l;
  while ((l = read(0, buf, 512)) > 0) {
    e = memchr(buf, '\n', l);
    if (e) {
      l = e + 1 - buf;
      write(1, buf, l);
      return 0;
    }
    write(1, buf, l);
  }
  write(1, "\n", l);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x220,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x210(%rbp),%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,-0x21c(%rbp)
cmp    $0x0,%eax
jle    11f1 <main+0xc1>
lea    -0x210(%rbp),%rdi
mov    -0x21c(%rbp),%edx
mov    $0xa,%esi
call   1040 <memchr@plt>
mov    %rax,-0x218(%rbp)
cmpq   $0x0,-0x218(%rbp)
je     11d5 <main+0xa5>
mov    -0x218(%rbp),%rax
add    $0x1,%rax
lea    -0x210(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x21c(%rbp)
lea    -0x210(%rbp),%rsi
mov    -0x21c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
movl   $0x0,-0x4(%rbp)
jmp    120f <main+0xdf>
lea    -0x210(%rbp),%rsi
mov    -0x21c(%rbp),%edx
mov    $0x1,%edi
call   1030 <write@plt>
jmp    1149 <main+0x19>
mov    -0x21c(%rbp),%edx
mov    $0x1,%edi
lea    0xdfd(%rip),%rsi
call   1030 <write@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x220,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jle    1198 <main+0x68>
mov    %rsp,%r14
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r14,%rdi
mov    $0xa,%esi
mov    %ebx,%edx
call   1040 <memchr@plt>
test   %rax,%rax
jne    11b2 <main+0x82>
mov    $0x1,%edi
mov    %r14,%rsi
mov    %ebx,%edx
call   1030 <write@plt>
xor    %edi,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1050 <read@plt>
mov    %eax,%ebx
test   %eax,%eax
jg     1160 <main+0x30>
lea    0xe61(%rip),%rsi
mov    $0x1,%ebp
mov    $0x1,%edi
mov    %ebx,%edx
call   1030 <write@plt>
jmp    11c8 <main+0x98>
mov    %rsp,%rsi
sub    %esi,%eax
add    $0x1,%eax
mov    $0x1,%edi
mov    %eax,%edx
call   1030 <write@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i8*
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
br label %9
9: ; preds = %30, %2
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%11 = call i32 @read(i32 0, i8* %10, i32 512)
store i32 %11, i32* %8
%12 = icmp sgt i32 %11, 0
br i1 %12, label %13, label %34
13: ; preds = %9
%14 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%15 = load i32, i32* %8
%16 = call i8* @memchr(i8* %14, i8 signext 10, i32 %15)
store i8* %16, i8** %7
%17 = load i8*, i8** %7
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %30
19: ; preds = %13
%20 = load i8*, i8** %7
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%23 = ptrtoint i8* %21 to i64
%24 = ptrtoint i8* %22 to i64
%25 = sub i64 %23, %24
%26 = trunc i64 %25 to i32
store i32 %26, i32* %8
%27 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%28 = load i32, i32* %8
%29 = call i32 @write(i32 1, i8* %27, i32 %28)
store i32 0, i32* %3
br label %37
30: ; preds = %13
%31 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%32 = load i32, i32* %8
%33 = call i32 @write(i32 1, i8* %31, i32 %32)
br label %9
34: ; preds = %9
%35 = load i32, i32* %8
%36 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %35)
store i32 1, i32* %3
br label %37
37: ; preds = %34, %19
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 512)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %22
7: ; preds = %2, %18
%8 = phi i32 [ %20, %18 ], [ %5, %2 ]
%9 = call i8* @memchr(i8* %4, i8 signext 10, i32 %8)
%10 = icmp eq i8* %9, null
br i1 %10, label %18, label %11
11: ; preds = %7
%12 = getelementptr inbounds i8, i8* %9, i64 1
%13 = ptrtoint i8* %12 to i64
%14 = ptrtoint [512 x i8]* %3 to i64
%15 = sub i64 %13, %14
%16 = trunc i64 %15 to i32
%17 = call i32 @write(i32 1, i8* %4, i32 %16)
br label %25
18: ; preds = %7
%19 = call i32 @write(i32 1, i8* %4, i32 %8)
%20 = call i32 @read(i32 0, i8* %4, i32 512)
%21 = icmp sgt i32 %20, 0
br i1 %21, label %7, label %22
22: ; preds = %18, %2
%23 = phi i32 [ %5, %2 ], [ %20, %18 ]
%24 = call i32 @write(i32 1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 %23)
br label %25
25: ; preds = %22, %11
%26 = phi i32 [ 0, %11 ], [ 1, %22 ]
ret i32 %26
}