#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 *xgetchar();
void getline(char *s) {
  int c;
  char *p = s;
  while (p < s + 200 - 1)
    if ((*p++ = xgetchar()) == '\n') {
      *p = '\0';
      return;
    }
  p[-1] = '\n';
  p[0] = '\0';
  while ((c = xgetchar()) != '\n')
    ;
  printf("Line too long, truncated to %s\n", s - 200);
}


x86 assembly (clang, -O0):
<getline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0xc8,%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jae    1185 <getline+0x65>
mov    $0x0,%al
call   1040 <xgetchar@plt>
mov    -0x18(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %al,(%rcx)
movsbl %al,%eax
cmp    $0xa,%eax
jne    1180 <getline+0x60>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
jmp    11c3 <getline+0xa3>
jmp    1134 <getline+0x14>
mov    -0x18(%rbp),%rax
movb   $0xa,-0x1(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    $0x0,%al
call   1040 <xgetchar@plt>
mov    %eax,-0xc(%rbp)
cmp    $0xa,%eax
je     11ac <getline+0x8c>
jmp    1194 <getline+0x74>
mov    -0x8(%rbp),%rsi
add    $0xffffffffffffff38,%rsi
lea    0xe42(%rip),%rdi
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getline>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %ebx,%ebx
nopl   0x0(%rax)
cmp    $0xc7,%rbx
je     1159 <getline+0x39>
xor    %eax,%eax
call   1040 <xgetchar@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0xa,%al
jne    1130 <getline+0x10>
movb   $0x0,(%r14,%rbx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
movw   $0xa,-0x1(%r14,%rbx,1)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1040 <xgetchar@plt>
cmp    $0xa,%eax
jne    1170 <getline+0x50>
add    $0xffffffffffffff38,%r14
lea    0xe76(%rip),%rdi
mov    %r14,%rsi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1030 <printf@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Line too long, truncated to %s\0A\00"
define void @getline(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i8* %0, i8** %2
%5 = load i8*, i8** %2
store i8* %5, i8** %4
br label %6
6: ; preds = %21, %1
%7 = load i8*, i8** %4
%8 = load i8*, i8** %2
%9 = getelementptr inbounds i8, i8* %8, i64 200
%10 = getelementptr inbounds i8, i8* %9, i64 -1
%11 = icmp ult i8* %7, %10
br i1 %11, label %12, label %22
12: ; preds = %6
%13 = call i8* (...) @xgetchar()
%14 = ptrtoint i8* %13 to i8
%15 = load i8*, i8** %4
%16 = getelementptr inbounds i8, i8* %15, i32 1
store i8* %16, i8** %4
store i8 %14, i8* %15
%17 = sext i8 %14 to i32
%18 = icmp eq i32 %17, 10
br i1 %18, label %19, label %21
19: ; preds = %12
%20 = load i8*, i8** %4
store i8 0, i8* %20
br label %36
21: ; preds = %12
br label %6
22: ; preds = %6
%23 = load i8*, i8** %4
%24 = getelementptr inbounds i8, i8* %23, i64 -1
store i8 10, i8* %24
%25 = load i8*, i8** %4
%26 = getelementptr inbounds i8, i8* %25, i64 0
store i8 0, i8* %26
br label %27
27: ; preds = %31, %22
%28 = call i8* (...) @xgetchar()
%29 = ptrtoint i8* %28 to i32
store i32 %29, i32* %3
%30 = icmp ne i32 %29, 10
br i1 %30, label %31, label %32
31: ; preds = %27
br label %27
32: ; preds = %27
%33 = load i8*, i8** %2
%34 = getelementptr inbounds i8, i8* %33, i64 -200
%35 = call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32, %19
ret void
}

LLVM IR (-O2):
@.str = [32 x i8] c"Line too long, truncated to %s\0A\00"
define void @getline(i8* %0) {
br label %2
2: ; preds = %6, %1
%3 = phi i64 [ 0, %1 ], [ %10, %6 ]
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = icmp eq i64 %3, 199
br i1 %5, label %14, label %6
6: ; preds = %2
%7 = tail call i8* (...) @xgetchar()
%8 = ptrtoint i8* %7 to i64
%9 = trunc i64 %8 to i8
%10 = add nuw nsw i64 %3, 1
store i8 %9, i8* %4
%11 = icmp eq i8 %9, 10
br i1 %11, label %12, label %2
12: ; preds = %6
%13 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %13
br label %24
14: ; preds = %2
%15 = getelementptr inbounds i8, i8* %4, i64 -1
store i8 10, i8* %15
store i8 0, i8* %4
br label %16
16: ; preds = %16, %14
%17 = tail call i8* (...) @xgetchar()
%18 = ptrtoint i8* %17 to i64
%19 = trunc i64 %18 to i32
%20 = icmp eq i32 %19, 10
br i1 %20, label %21, label %16
21: ; preds = %16
%22 = getelementptr inbounds i8, i8* %0, i64 -200
%23 = tail call i32 @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %12
ret void
}