#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *strchr(char *, char);
int readline(char *in, int in_size, FILE *from) {
  char *cptr;
  memset(in, 0, in_size * sizeof(char));
  int cond = (fgets(in, in_size, from)) != NULL;
  if (cond) {
    char *tmp = strchr(in, '\n');
    tmp[0] = '\0';
  }
  return cond;
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x18(%rbp),%rdx
call   1050 <fgets@plt>
cmp    $0x0,%rax
setne  %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     119a <readline+0x6a>
mov    -0x8(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x24(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
xor    %esi,%esi
mov    %ebp,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1050 <fgets@plt>
mov    %rax,%r14
test   %rax,%rax
je     116a <readline+0x3a>
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
movb   $0x0,(%rax)
xor    %eax,%eax
test   %r14,%r14
setne  %al
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @readline(i8* %0, i32 %1, i32* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32* %2, i32** %6
%10 = load i8*, i8** %4
%11 = load i32, i32* %5
%12 = sext i32 %11 to i64
%13 = mul i64 %12, 1
%14 = trunc i64 %13 to i32
%15 = call i32 @memset(i8* %10, i32 0, i32 %14)
%16 = load i8*, i8** %4
%17 = load i32, i32* %5
%18 = load i32*, i32** %6
%19 = call i32* @fgets(i8* %16, i32 %17, i32* %18)
%20 = icmp ne i32* %19, null
%21 = zext i1 %20 to i32
store i32 %21, i32* %8
%22 = load i32, i32* %8
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %29
24: ; preds = %3
%25 = load i8*, i8** %4
%26 = call i8* @strchr(i8* %25, i8 signext 10)
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = getelementptr inbounds i8, i8* %27, i64 0
store i8 0, i8* %28
br label %29
29: ; preds = %24, %3
%30 = load i32, i32* %8
ret i32 %30
}

LLVM IR (-O2):
define i32 @readline(i8* %0, i32 %1, i32* nocapture %2) {
%4 = tail call i32 @memset(i8* %0, i32 0, i32 %1)
%5 = tail call i32* @fgets(i8* %0, i32 %1, i32* %2)
%6 = icmp ne i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
store i8 0, i8* %8
br label %9
9: ; preds = %7, %3
%10 = zext i1 %6 to i32
ret i32 %10
}