#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 */
struct source {
  int dummy;
};

/* Variables and functions */
int BUFSIZ;
int EOF;
char *bstrdup(char *);
int src_getcharstring(struct source *);
char *src_getlinestring(struct source *src) {
  char buf[BUFSIZ];
  int i, ch;
  i = 0;
  while (i < BUFSIZ - 1) {
    ch = src_getcharstring(src);
    if (ch == EOF)
      break;
    buf[i++] = ch;
    if (ch == '\n')
      break;
  }
  buf[i] = '\0';
  return (bstrdup(buf));
}


x86 assembly (clang, -O0):
<src_getlinestring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x28(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e6f(%rip),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jge    11c7 <src_getlinestring+0xa7>
mov    -0x8(%rbp),%rdi
call   1040 <src_getcharstring@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2e5c(%rip),%rcx
cmp    (%rcx),%eax
jne    1199 <src_getlinestring+0x79>
jmp    11c7 <src_getlinestring+0xa7>
mov    -0x28(%rbp),%rax
mov    -0x20(%rbp),%ecx
mov    %cl,%dl
mov    -0x1c(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x1c(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
cmpl   $0xa,-0x20(%rbp)
jne    11c2 <src_getlinestring+0xa2>
jmp    11c7 <src_getlinestring+0xa7>
jmp    115f <src_getlinestring+0x3f>
mov    -0x28(%rbp),%rdi
movslq -0x1c(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
call   1030 <bstrdup@plt>
mov    -0x10(%rbp),%rcx
mov    %rcx,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<src_getlinestring>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2ea3(%rip),%r15
mov    (%r15),%eax
mov    %rsp,%r12
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r12
mov    %r12,%rsp
cmp    $0x2,%eax
jl     1190 <src_getlinestring+0x70>
mov    %rdi,%r14
xor    %eax,%eax
mov    0x2e8b(%rip),%r13
nopl   (%rax)
mov    %rax,%rbx
mov    %r14,%rdi
call   1040 <src_getcharstring@plt>
cmp    0x0(%r13),%eax
je     1192 <src_getlinestring+0x72>
mov    %al,(%r12,%rbx,1)
cmp    $0xa,%eax
je     118a <src_getlinestring+0x6a>
lea    0x1(%rbx),%rax
movslq (%r15),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
jl     1160 <src_getlinestring+0x40>
add    $0x1,%rbx
jmp    1192 <src_getlinestring+0x72>
xor    %ebx,%ebx
movslq %ebx,%rax
movb   $0x0,(%r12,%rax,1)
mov    %r12,%rdi
call   1030 <bstrdup@plt>
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.source = type { i32 }
@BUFSIZ = global i32 0
@EOF = global i32 0
define i8* @src_getlinestring(%struct.source* %0) {
%2 = alloca %struct.source*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
store %struct.source* %0, %struct.source** %2
%7 = load i32, i32* @BUFSIZ
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %3
%10 = alloca i8, i64 %8
store i64 %8, i64* %4
store i32 0, i32* %5
br label %11
11: ; preds = %33, %1
%12 = load i32, i32* %5
%13 = load i32, i32* @BUFSIZ
%14 = sub nsw i32 %13, 1
%15 = icmp slt i32 %12, %14
br i1 %15, label %16, label %34
16: ; preds = %11
%17 = load %struct.source*, %struct.source** %2
%18 = call i32 @src_getcharstring(%struct.source* %17)
store i32 %18, i32* %6
%19 = load i32, i32* %6
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %23
22: ; preds = %16
br label %34
23: ; preds = %16
%24 = load i32, i32* %6
%25 = trunc i32 %24 to i8
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %10, i64 %28
store i8 %25, i8* %29
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 10
br i1 %31, label %32, label %33
32: ; preds = %23
br label %34
33: ; preds = %23
br label %11
34: ; preds = %32, %22, %11
%35 = load i32, i32* %5
%36 = sext i32 %35 to i64
%37 = getelementptr inbounds i8, i8* %10, i64 %36
store i8 0, i8* %37
%38 = call i8* @bstrdup(i8* %10)
%39 = load i8*, i8** %3
ret i8* %38
}

LLVM IR (-O2):
%struct.source = type { i32 }
@BUFSIZ = global i32 0
@EOF = global i32 0
define i8* @src_getlinestring(%struct.source* %0) {
%2 = load i32, i32* @BUFSIZ
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = icmp sgt i32 %2, 1
br i1 %5, label %6, label %21
6: ; preds = %1, %16
%7 = phi i64 [ %13, %16 ], [ 0, %1 ]
%8 = tail call i32 @src_getcharstring(%struct.source* %0)
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %8, %9
br i1 %10, label %21, label %11
11: ; preds = %6
%12 = trunc i32 %8 to i8
%13 = add nuw nsw i64 %7, 1
%14 = getelementptr inbounds i8, i8* %4, i64 %7
store i8 %12, i8* %14
%15 = icmp eq i32 %8, 10
br i1 %15, label %21, label %16
16: ; preds = %11
%17 = load i32, i32* @BUFSIZ
%18 = add nsw i32 %17, -1
%19 = sext i32 %18 to i64
%20 = icmp slt i64 %13, %19
br i1 %20, label %6, label %21
21: ; preds = %16, %6, %11, %1
%22 = phi i64 [ 0, %1 ], [ %13, %16 ], [ %7, %6 ], [ %13, %11 ]
%23 = shl i64 %22, 32
%24 = ashr exact i64 %23, 32
%25 = getelementptr inbounds i8, i8* %4, i64 %24
store i8 0, i8* %25
%26 = call i8* @bstrdup(i8* %4)
ret i8* %26
}