#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 */
char *strchr(char *, char);
int /*<<< orphan*/ strcmp(char *, char *);
int strlen(char *);
char *gg_get_line(char **ptr) {
  char *foo, *res;
  if (!ptr || !*ptr || !strcmp(*ptr, ""))
    return NULL;
  res = *ptr;
  if (!(foo = strchr(*ptr, '\n')))
    *ptr += strlen(*ptr);
  else {
    *ptr = foo + 1;
    *foo = 0;
    if (strlen(res) > 1 && res[strlen(res) - 1] == '\r')
      res[strlen(res) - 1] = 0;
  }
  return res;
}


x86 assembly (clang, -O0):
<gg_get_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1171 <gg_get_line+0x41>
mov    -0x10(%rbp),%rax
cmpq   $0x0,(%rax)
je     1171 <gg_get_line+0x41>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe9d(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%eax
jne    117e <gg_get_line+0x4e>
movq   $0x0,-0x8(%rbp)
jmp    124b <gg_get_line+0x11b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cb <gg_get_line+0x9b>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <strlen@plt>
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
movslq %edx,%rdx
add    %rdx,%rcx
mov    %rcx,(%rax)
jmp    1243 <gg_get_line+0x113>
mov    -0x18(%rbp),%rcx
add    $0x1,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x1,%eax
jle    123e <gg_get_line+0x10e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xd,%eax
jne    123e <gg_get_line+0x10e>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
jmp    1243 <gg_get_line+0x113>
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<gg_get_line>:
push   %r14
push   %rbx
push   %rax
test   %rdi,%rdi
je     118a <gg_get_line+0x6a>
mov    %rdi,%rbx
mov    (%rdi),%r14
test   %r14,%r14
je     118a <gg_get_line+0x6a>
cmpb   $0x0,(%r14)
je     118a <gg_get_line+0x6a>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1198 <gg_get_line+0x78>
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,(%rbx)
movb   $0x0,(%rax)
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jl     118d <gg_get_line+0x6d>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmpb   $0xd,-0x1(%rax,%r14,1)
jne    118d <gg_get_line+0x6d>
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%r14,1)
jmp    118d <gg_get_line+0x6d>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
add    %rax,(%rbx)
jmp    118d <gg_get_line+0x6d>

LLVM IR (-O0):
@.str = [1 x i8] zeroinitializer
define i8* @gg_get_line(i8** %0) {
%2 = alloca i8*
%3 = alloca i8**
%4 = alloca i8*
%5 = alloca i8*
store i8** %0, i8*** %3
%6 = load i8**, i8*** %3
%7 = icmp ne i8** %6, null
br i1 %7, label %8, label %17
8: ; preds = %1
%9 = load i8**, i8*** %3
%10 = load i8*, i8** %9
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %8
%13 = load i8**, i8*** %3
%14 = load i8*, i8** %13
%15 = call i32 @strcmp(i8* %14, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%16 = icmp ne i32 %15, 0
br i1 %16, label %18, label %17
17: ; preds = %12, %8, %1
store i8* null, i8** %2
br label %61
18: ; preds = %12
%19 = load i8**, i8*** %3
%20 = load i8*, i8** %19
store i8* %20, i8** %5
%21 = load i8**, i8*** %3
%22 = load i8*, i8** %21
%23 = call i8* @strchr(i8* %22, i8 signext 10)
store i8* %23, i8** %4
%24 = icmp ne i8* %23, null
br i1 %24, label %33, label %25
25: ; preds = %18
%26 = load i8**, i8*** %3
%27 = load i8*, i8** %26
%28 = call i32 @strlen(i8* %27)
%29 = load i8**, i8*** %3
%30 = load i8*, i8** %29
%31 = sext i32 %28 to i64
%32 = getelementptr inbounds i8, i8* %30, i64 %31
store i8* %32, i8** %29
br label %59
33: ; preds = %18
%34 = load i8*, i8** %4
%35 = getelementptr inbounds i8, i8* %34, i64 1
%36 = load i8**, i8*** %3
store i8* %35, i8** %36
%37 = load i8*, i8** %4
store i8 0, i8* %37
%38 = load i8*, i8** %5
%39 = call i32 @strlen(i8* %38)
%40 = icmp sgt i32 %39, 1
br i1 %40, label %41, label %58
41: ; preds = %33
%42 = load i8*, i8** %5
%43 = load i8*, i8** %5
%44 = call i32 @strlen(i8* %43)
%45 = sub nsw i32 %44, 1
%46 = sext i32 %45 to i64
%47 = getelementptr inbounds i8, i8* %42, i64 %46
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = icmp eq i32 %49, 13
br i1 %50, label %51, label %58
51: ; preds = %41
%52 = load i8*, i8** %5
%53 = load i8*, i8** %5
%54 = call i32 @strlen(i8* %53)
%55 = sub nsw i32 %54, 1
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %52, i64 %56
store i8 0, i8* %57
br label %58
58: ; preds = %51, %41, %33
br label %59
59: ; preds = %58, %25
%60 = load i8*, i8** %5
store i8* %60, i8** %2
br label %61
61: ; preds = %59, %17
%62 = load i8*, i8** %2
ret i8* %62
}

LLVM IR (-O2):
define i8* @gg_get_line(i8** %0) {
%2 = icmp eq i8** %0, null
br i1 %2, label %33, label %3
3: ; preds = %1
%4 = load i8*, i8** %0
%5 = icmp eq i8* %4, null
br i1 %5, label %33, label %6
6: ; preds = %3
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %33, label %9
9: ; preds = %6
%10 = tail call i8* @strchr(i8* %4, i8 signext 10)
%11 = icmp eq i8* %10, null
br i1 %11, label %12, label %17
12: ; preds = %9
%13 = tail call i32 @strlen(i8* %4)
%14 = load i8*, i8** %0
%15 = sext i32 %13 to i64
%16 = getelementptr inbounds i8, i8* %14, i64 %15
store i8* %16, i8** %0
br label %33
17: ; preds = %9
%18 = getelementptr inbounds i8, i8* %10, i64 1
store i8* %18, i8** %0
store i8 0, i8* %10
%19 = tail call i32 @strlen(i8* %4)
%20 = icmp sgt i32 %19, 1
br i1 %20, label %21, label %33
21: ; preds = %17
%22 = tail call i32 @strlen(i8* %4)
%23 = add nsw i32 %22, -1
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8, i8* %4, i64 %24
%26 = load i8, i8* %25
%27 = icmp eq i8 %26, 13
br i1 %27, label %28, label %33
28: ; preds = %21
%29 = tail call i32 @strlen(i8* %4)
%30 = add nsw i32 %29, -1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %4, i64 %31
store i8 0, i8* %32
br label %33
33: ; preds = %12, %28, %21, %17, %1, %3, %6
%34 = phi i8* [ null, %6 ], [ null, %3 ], [ null, %1 ], [ %4, %17 ], [ %4, %21 ], [ %4, %28 ], [ %4, %12 ]
ret i8* %34
}