#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 EOF;
int FCGI_getchar();
char *FCGI_gets(char *str) {
  char *s;
  int c;
  for (s = str; ((c = FCGI_getchar()) != '\n');) {
    if (c == EOF) {
      if (s == str)
        return NULL;
      else
        break;
    } else
      *s++ = (char)c;
  }
  *s = 0;
  return str;
}


x86 assembly (clang, -O0):
<FCGI_gets>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1030 <FCGI_getchar@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0xa,%eax
je     1184 <FCGI_gets+0x74>
mov    -0x1c(%rbp),%eax
mov    0x2ea7(%rip),%rcx
cmp    (%rcx),%eax
jne    1169 <FCGI_gets+0x59>
mov    -0x18(%rbp),%rax
cmp    -0x10(%rbp),%rax
jne    1164 <FCGI_gets+0x54>
movq   $0x0,-0x8(%rbp)
jmp    1193 <FCGI_gets+0x83>
jmp    1184 <FCGI_gets+0x74>
mov    -0x1c(%rbp),%eax
mov    %al,%cl
mov    -0x18(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x18(%rbp)
mov    %cl,(%rax)
jmp    1124 <FCGI_gets+0x14>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FCGI_gets>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
xor    %eax,%eax
call   1030 <FCGI_getchar@plt>
mov    %r14,%rbx
cmp    $0xa,%eax
je     1153 <FCGI_gets+0x43>
mov    0x2eba(%rip),%r15
xor    %ebx,%ebx
cmp    (%r15),%eax
je     114b <FCGI_gets+0x3b>
mov    %al,(%r14,%rbx,1)
xor    %eax,%eax
call   1030 <FCGI_getchar@plt>
add    $0x1,%rbx
cmp    $0xa,%eax
jne    1130 <FCGI_gets+0x20>
jmp    1150 <FCGI_gets+0x40>
test   %rbx,%rbx
je     115f <FCGI_gets+0x4f>
add    %r14,%rbx
movb   $0x0,(%rbx)
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret
xor    %r14d,%r14d
jmp    1156 <FCGI_gets+0x46>

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

LLVM IR (-O2):
@EOF = global i32 0
define i8* @FCGI_gets(i8* writeonly %0) {
%2 = tail call i32 (...) @FCGI_getchar()
%3 = icmp eq i32 %2, 10
br i1 %3, label %16, label %4
4: ; preds = %1, %11
%5 = phi i32 [ %14, %11 ], [ %2, %1 ]
%6 = phi i8* [ %13, %11 ], [ %0, %1 ]
%7 = load i32, i32* @EOF
%8 = icmp eq i32 %5, %7
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = icmp eq i8* %6, %0
br i1 %10, label %18, label %16
11: ; preds = %4
%12 = trunc i32 %5 to i8
%13 = getelementptr inbounds i8, i8* %6, i64 1
store i8 %12, i8* %6
%14 = tail call i32 (...) @FCGI_getchar()
%15 = icmp eq i32 %14, 10
br i1 %15, label %16, label %4
16: ; preds = %11, %1, %9
%17 = phi i8* [ %6, %9 ], [ %0, %1 ], [ %13, %11 ]
store i8 0, i8* %17
br label %18
18: ; preds = %9, %16
%19 = phi i8* [ %0, %16 ], [ null, %9 ]
ret i8* %19
}