#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*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ rewind(int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int strlen(char *);
int ReadLine1(char s[], int maxlen) {
  int len_s;
  fgets(s, maxlen, stdin);
  len_s = strlen(s);
  if (s[len_s - 1] == '\n') {
    s[len_s - 1] = '\0';
    len_s -= 1;
  }
  rewind(stdin);
  return len_s;
}


x86 assembly (clang, -O0):
<ReadLine1>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    0x2e9b(%rip),%rax
mov    (%rax),%edx
call   1050 <fgets@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1194 <ReadLine1+0x64>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x10(%rbp),%eax
sub    $0x1,%eax
mov    %eax,-0x10(%rbp)
mov    0x2e4d(%rip),%rax
mov    (%rax),%edi
call   1040 <rewind@plt>
mov    -0x10(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ReadLine1>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
mov    0x2eaa(%rip),%r14
mov    (%r14),%edx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%ebp
cltq
cmpb   $0xa,-0x1(%rbx,%rax,1)
jne    1163 <ReadLine1+0x33>
add    $0xffffffffffffffff,%rax
movb   $0x0,(%rbx,%rax,1)
mov    %eax,%ebp
mov    (%r14),%edi
call   1040 <rewind@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdin = global i32 0
define i32 @ReadLine1(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = load i32, i32* %4
%8 = load i32, i32* @stdin
%9 = call i32 @fgets(i8* %6, i32 %7, i32 %8)
%10 = load i8*, i8** %3
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %5
%12 = load i8*, i8** %3
%13 = load i32, i32* %5
%14 = sub nsw i32 %13, 1
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8, i8* %12, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 10
br i1 %19, label %20, label %28
20: ; preds = %2
%21 = load i8*, i8** %3
%22 = load i32, i32* %5
%23 = sub nsw i32 %22, 1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %21, i64 %24
store i8 0, i8* %25
%26 = load i32, i32* %5
%27 = sub nsw i32 %26, 1
store i32 %27, i32* %5
br label %28
28: ; preds = %20, %2
%29 = load i32, i32* @stdin
%30 = call i32 @rewind(i32 %29)
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@stdin = global i32 0
define i32 @ReadLine1(i8* %0, i32 %1) {
%3 = load i32, i32* @stdin
%4 = tail call i32 @fgets(i8* %0, i32 %1, i32 %3)
%5 = tail call i32 @strlen(i8* %0)
%6 = add nsw i32 %5, -1
%7 = sext i32 %6 to i64
%8 = getelementptr inbounds i8, i8* %0, i64 %7
%9 = load i8, i8* %8
%10 = icmp eq i8 %9, 10
br i1 %10, label %11, label %12
11: ; preds = %2
store i8 0, i8* %8
br label %12
12: ; preds = %11, %2
%13 = phi i32 [ %6, %11 ], [ %5, %2 ]
%14 = load i32, i32* @stdin
%15 = tail call i32 @rewind(i32 %14)
ret i32 %13
}