#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 *malloc(int);
int read(int const, unsigned char *, int);
char *str_char(char *, char);
int get_next_line(int const fd, char **line) {
  unsigned char buf;
  int i;
  int ret;
  i = 0;
  *line = malloc(sizeof(char) * (i + 1));
  *line[0] = '\0';
  while ((ret = read(fd, &buf, 1))) {
    if ((char)buf == '\n')
      break;
    *line = str_char(*line, (buf > 127) ? (char)(-(buf - 127)) : (char)buf);
    i++;
  }
  return (ret);
}


x86 assembly (clang, -O0):
<get_next_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1040 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
movb   $0x0,(%rax)
mov    -0x4(%rbp),%edi
lea    -0x11(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     11f8 <get_next_line+0xc8>
movsbl -0x11(%rbp),%eax
cmp    $0xa,%eax
jne    119c <get_next_line+0x6c>
jmp    11f8 <get_next_line+0xc8>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
movzbl -0x11(%rbp),%eax
cmp    $0x7f,%eax
jle    11ca <get_next_line+0x9a>
movzbl -0x11(%rbp),%ecx
sub    $0x7f,%ecx
xor    %eax,%eax
sub    %ecx,%eax
movsbl %al,%eax
mov    %eax,-0x2c(%rbp)
jmp    11d1 <get_next_line+0xa1>
movsbl -0x11(%rbp),%eax
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x2c(%rbp),%eax
movsbl %al,%esi
call   1050 <str_char@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    116d <get_next_line+0x3d>
mov    -0x1c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_next_line>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%edi
call   1040 <malloc@plt>
mov    %rax,(%rbx)
movb   $0x0,(%rax)
lea    0xf(%rsp),%rsi
mov    %ebp,%edi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
je     11aa <get_next_line+0x7a>
mov    0xf(%rsp),%cl
cmp    $0xa,%cl
je     11aa <get_next_line+0x7a>
lea    0xf(%rsp),%r14
mov    (%rbx),%rdi
mov    $0x7f,%al
sub    %cl,%al
test   %cl,%cl
movzbl %al,%eax
movzbl %cl,%ecx
cmovs  %eax,%ecx
movsbl %cl,%esi
call   1050 <str_char@plt>
mov    %rax,(%rbx)
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %eax,%eax
je     11aa <get_next_line+0x7a>
movzbl 0xf(%rsp),%ecx
cmp    $0xa,%cl
jne    1170 <get_next_line+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
define i32 @get_next_line(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
%8 = load i32, i32* %6
%9 = add nsw i32 %8, 1
%10 = sext i32 %9 to i64
%11 = mul i64 1, %10
%12 = trunc i64 %11 to i32
%13 = call i8* @malloc(i32 %12)
%14 = load i8**, i8*** %4
store i8* %13, i8** %14
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
store i8 0, i8* %17
br label %18
18: ; preds = %43, %2
%19 = load i32, i32* %3
%20 = call i32 @read(i32 %19, i8* %5, i32 1)
store i32 %20, i32* %7
%21 = icmp ne i32 %20, 0
br i1 %21, label %22, label %50
22: ; preds = %18
%23 = load i8, i8* %5
%24 = sext i8 %23 to i32
%25 = icmp eq i32 %24, 10
br i1 %25, label %26, label %27
26: ; preds = %22
br label %50
27: ; preds = %22
%28 = load i8**, i8*** %4
%29 = load i8*, i8** %28
%30 = load i8, i8* %5
%31 = zext i8 %30 to i32
%32 = icmp sgt i32 %31, 127
br i1 %32, label %33, label %40
33: ; preds = %27
%34 = load i8, i8* %5
%35 = zext i8 %34 to i32
%36 = sub nsw i32 %35, 127
%37 = sub nsw i32 0, %36
%38 = trunc i32 %37 to i8
%39 = sext i8 %38 to i32
br label %43
40: ; preds = %27
%41 = load i8, i8* %5
%42 = sext i8 %41 to i32
br label %43
43: ; preds = %40, %33
%44 = phi i32 [ %39, %33 ], [ %42, %40 ]
%45 = trunc i32 %44 to i8
%46 = call i8* @str_char(i8* %29, i8 signext %45)
%47 = load i8**, i8*** %4
store i8* %46, i8** %47
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %18
50: ; preds = %26, %18
%51 = load i32, i32* %7
ret i32 %51
}

LLVM IR (-O2):
define i32 @get_next_line(i32 %0, i8** nocapture %1) {
%3 = alloca i8
%4 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
store i8* %4, i8** %1
store i8 0, i8* %4
%5 = call i32 @read(i32 %0, i8* %3, i32 1)
%6 = icmp eq i32 %5, 0
%7 = load i8, i8* %3
%8 = icmp eq i8 %7, 10
%9 = select i1 %6, i1 true, i1 %8
br i1 %9, label %22, label %10
10: ; preds = %2, %10
%11 = phi i8 [ %19, %10 ], [ %7, %2 ]
%12 = load i8*, i8** %1
%13 = icmp slt i8 %11, 0
%14 = sub i8 127, %11
%15 = select i1 %13, i8 %14, i8 %11
%16 = tail call i8* @str_char(i8* %12, i8 signext %15)
store i8* %16, i8** %1
%17 = call i32 @read(i32 %0, i8* %3, i32 1)
%18 = icmp eq i32 %17, 0
%19 = load i8, i8* %3
%20 = icmp eq i8 %19, 10
%21 = select i1 %18, i1 true, i1 %20
br i1 %21, label %22, label %10
22: ; preds = %10, %2
%23 = phi i32 [ %5, %2 ], [ %17, %10 ]
ret i32 %23
}