#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 EOF;
int fscanf(int /*<<< orphan*/ *, char *, char *);
int readline(FILE *fid, char *str) {
  char c;
  int cont = 0, flag = 0;
  flag = fscanf(fid, "%c", &c);
  while ((c != '\n') && (flag != EOF)) {
    str[cont] = c;
    flag = fscanf(fid, "%c", &c);
    cont++;
  }
  str[cont] = '\0';
  return (flag);
}


x86 assembly (clang, -O0):
<readline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xec7(%rip),%rsi
lea    -0x11(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
movsbl -0x11(%rbp),%ecx
xor    %eax,%eax
cmp    $0xa,%ecx
mov    %al,-0x1d(%rbp)
je     1169 <readline+0x59>
mov    -0x1c(%rbp),%eax
mov    0x2e87(%rip),%rcx
cmp    (%rcx),%eax
setne  %al
mov    %al,-0x1d(%rbp)
mov    -0x1d(%rbp),%al
test   $0x1,%al
jne    1179 <readline+0x69>
jmp    11ac <readline+0x9c>
mov    -0x11(%rbp),%dl
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
lea    0xe6e(%rip),%rsi
lea    -0x11(%rbp),%rdx
call   1030 <fscanf@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1145 <readline+0x35>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0xed8(%rip),%rsi
lea    0x7(%rsp),%rdx
call   1030 <fscanf@plt>
mov    0x7(%rsp),%cl
xor    %edx,%edx
cmp    $0xa,%cl
je     1188 <readline+0x78>
mov    0x2ea4(%rip),%r13
cmp    0x0(%r13),%eax
je     1188 <readline+0x78>
xor    %ebp,%ebp
lea    0xead(%rip),%r15
lea    0x7(%rsp),%r12
nopl   0x0(%rax,%rax,1)
mov    %cl,(%r14,%rbp,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <fscanf@plt>
add    $0x1,%rbp
movzbl 0x7(%rsp),%ecx
cmp    $0xa,%cl
je     1186 <readline+0x76>
cmp    0x0(%r13),%eax
jne    1160 <readline+0x50>
mov    %ebp,%edx
movb   $0x0,(%r14,%rdx,1)
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%c\00"
@EOF = global i32 0
define i32 @readline(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i32
%7 = alloca i32
store i32* %0, i32** %3
store i8* %1, i8** %4
store i32 0, i32* %6
store i32 0, i32* %7
%8 = load i32*, i32** %3
%9 = call i32 @fscanf(i32* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
store i32 %9, i32* %7
br label %10
10: ; preds = %20, %2
%11 = load i8, i8* %5
%12 = sext i8 %11 to i32
%13 = icmp ne i32 %12, 10
br i1 %13, label %14, label %18
14: ; preds = %10
%15 = load i32, i32* %7
%16 = load i32, i32* @EOF
%17 = icmp ne i32 %15, %16
br label %18
18: ; preds = %14, %10
%19 = phi i1 [ false, %10 ], [ %17, %14 ]
br i1 %19, label %20, label %30
20: ; preds = %18
%21 = load i8, i8* %5
%22 = load i8*, i8** %4
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %22, i64 %24
store i8 %21, i8* %25
%26 = load i32*, i32** %3
%27 = call i32 @fscanf(i32* %26, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %5)
store i32 %27, i32* %7
%28 = load i32, i32* %6
%29 = add nsw i32 %28, 1
store i32 %29, i32* %6
br label %10
30: ; preds = %18
%31 = load i8*, i8** %4
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i32, i32* %7
ret i32 %35
}

LLVM IR (-O2):
@.str = [3 x i8] c"%c\00"
@EOF = global i32 0
define i32 @readline(i32* nocapture %0, i8* nocapture writeonly %1) {
%3 = alloca i8
%4 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%5 = load i8, i8* %3
%6 = icmp ne i8 %5, 10
%7 = load i32, i32* @EOF
%8 = icmp ne i32 %4, %7
%9 = select i1 %6, i1 %8, i1 false
br i1 %9, label %10, label %23
10: ; preds = %2, %10
%11 = phi i64 [ %15, %10 ], [ 0, %2 ]
%12 = phi i8 [ %16, %10 ], [ %5, %2 ]
%13 = getelementptr inbounds i8, i8* %1, i64 %11
store i8 %12, i8* %13
%14 = call i32 @fscanf(i32* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %3)
%15 = add nuw i64 %11, 1
%16 = load i8, i8* %3
%17 = icmp ne i8 %16, 10
%18 = load i32, i32* @EOF
%19 = icmp ne i32 %14, %18
%20 = select i1 %17, i1 %19, i1 false
br i1 %20, label %10, label %21
21: ; preds = %10
%22 = and i64 %15, 4294967295
br label %23
23: ; preds = %21, %2
%24 = phi i64 [ 0, %2 ], [ %22, %21 ]
%25 = phi i32 [ %4, %2 ], [ %14, %21 ]
%26 = getelementptr inbounds i8, i8* %1, i64 %24
store i8 0, i8* %26
ret i32 %25
}