#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 getc(int /*<<< orphan*/ *);
int read_stringline(FILE *fp, char *a) {
  int i = 0;
  int c;
  a[0] = '\0';
  while (((c = getc(fp)) != EOF) && (c != '\n')) {
    a[i++] = c;
  }
  a[i] = '\0';
  return 0;
}


x86 assembly (clang, -O0):
<read_stringline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1030 <getc@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
xor    %eax,%eax
mov    0x2ea3(%rip),%rdx
cmp    (%rdx),%ecx
mov    %al,-0x19(%rbp)
je     115a <read_stringline+0x4a>
cmpl   $0xa,-0x18(%rbp)
setne  %al
mov    %al,-0x19(%rbp)
mov    -0x19(%rbp),%al
test   $0x1,%al
jne    116a <read_stringline+0x5a>
jmp    1189 <read_stringline+0x79>
mov    -0x18(%rbp),%eax
mov    %al,%dl
mov    -0x10(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    112e <read_stringline+0x1e>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_stringline>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r12
movb   $0x0,(%rsi)
call   1030 <getc@plt>
xor    %ecx,%ecx
cmp    $0xa,%eax
je     115c <read_stringline+0x4c>
mov    0x2eb4(%rip),%r15
cmp    (%r15),%eax
je     115c <read_stringline+0x4c>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
mov    %r12,%rdi
call   1030 <getc@plt>
cmp    $0xa,%eax
je     115a <read_stringline+0x4a>
cmp    (%r15),%eax
jne    1140 <read_stringline+0x30>
mov    %ebx,%ecx
movb   $0x0,(%r14,%rcx,1)
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@EOF = global i32 0
define i32 @read_stringline(i32* nocapture %0, i8* nocapture writeonly %1) {
store i8 0, i8* %1
%3 = tail call i32 @getc(i32* %0)
%4 = load i32, i32* @EOF
%5 = icmp ne i32 %3, %4
%6 = icmp ne i32 %3, 10
%7 = and i1 %6, %5
br i1 %7, label %8, label %21
8: ; preds = %2, %8
%9 = phi i64 [ %12, %8 ], [ 0, %2 ]
%10 = phi i32 [ %14, %8 ], [ %3, %2 ]
%11 = trunc i32 %10 to i8
%12 = add nuw i64 %9, 1
%13 = getelementptr inbounds i8, i8* %1, i64 %9
store i8 %11, i8* %13
%14 = tail call i32 @getc(i32* %0)
%15 = load i32, i32* @EOF
%16 = icmp ne i32 %14, %15
%17 = icmp ne i32 %14, 10
%18 = and i1 %17, %16
br i1 %18, label %8, label %19
19: ; preds = %8
%20 = and i64 %12, 4294967295
br label %21
21: ; preds = %19, %2
%22 = phi i64 [ 0, %2 ], [ %20, %19 ]
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 0, i8* %23
ret i32 0
}