#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 getline(char **, size_t *, int /*<<< orphan*/ *);
char *get_hex_line(FILE *fp) {
  char *line = NULL;
  size_t size;
  int nchars;
  nchars = getline(&line, &size, fp);
  if (nchars < 0) {
    line = NULL;
    goto out;
  }
  do {
    char c = line[nchars - 1];
    if (c == '\r' || c == '\n') {
      line[nchars - 1] = '\0';
      nchars--;
    } else {
      break;
    }
  } while (nchars > 0);
out:
  return line;
}


x86 assembly (clang, -O0):
<get_hex_line>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
mov    -0x8(%rbp),%rdx
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jge    114f <get_hex_line+0x3f>
movq   $0x0,-0x10(%rbp)
jmp    11b9 <get_hex_line+0xa9>
jmp    1154 <get_hex_line+0x44>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
mov    (%rax,%rcx,1),%al
mov    %al,-0x1d(%rbp)
movsbl -0x1d(%rbp),%eax
cmp    $0xd,%eax
je     1181 <get_hex_line+0x71>
movsbl -0x1d(%rbp),%eax
cmp    $0xa,%eax
jne    11a0 <get_hex_line+0x90>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x1c(%rbp)
jmp    11a5 <get_hex_line+0x95>
jmp    11b4 <get_hex_line+0xa4>
jmp    11aa <get_hex_line+0x9a>
cmpl   $0x0,-0x1c(%rbp)
jg     1154 <get_hex_line+0x44>
jmp    11b9 <get_hex_line+0xa9>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_hex_line>:
sub    $0x18,%rsp
mov    %rdi,%rdx
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <getline@plt>
test   %eax,%eax
js     1168 <get_hex_line+0x58>
mov    %eax,%ecx
add    $0x1,%rcx
jmp    114f <get_hex_line+0x3f>
nopl   0x0(%rax,%rax,1)
movb   $0x0,-0x2(%rax,%rcx,1)
add    $0xffffffffffffffff,%rcx
cmp    $0x1,%rcx
jbe    116f <get_hex_line+0x5f>
mov    0x8(%rsp),%rax
movzbl -0x2(%rax,%rcx,1),%edx
cmp    $0xd,%dl
je     1140 <get_hex_line+0x30>
cmp    $0xa,%dl
je     1140 <get_hex_line+0x30>
add    $0x18,%rsp
ret
xor    %eax,%eax
add    $0x18,%rsp
ret
mov    0x8(%rsp),%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
define i8* @get_hex_line(i32* %0) {
%2 = alloca i32*
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i32
%6 = alloca i8
store i32* %0, i32** %2
store i8* null, i8** %3
%7 = load i32*, i32** %2
%8 = call i32 @getline(i8** %3, i64* %4, i32* %7)
store i32 %8, i32* %5
%9 = load i32, i32* %5
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %1
store i8* null, i8** %3
br label %41
12: ; preds = %1
br label %13
13: ; preds = %37, %12
%14 = load i8*, i8** %3
%15 = load i32, i32* %5
%16 = sub nsw i32 %15, 1
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds i8, i8* %14, i64 %17
%19 = load i8, i8* %18
store i8 %19, i8* %6
%20 = load i8, i8* %6
%21 = sext i8 %20 to i32
%22 = icmp eq i32 %21, 13
br i1 %22, label %27, label %23
23: ; preds = %13
%24 = load i8, i8* %6
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %35
27: ; preds = %23, %13
%28 = load i8*, i8** %3
%29 = load i32, i32* %5
%30 = sub nsw i32 %29, 1
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds i8, i8* %28, i64 %31
store i8 0, i8* %32
%33 = load i32, i32* %5
%34 = add nsw i32 %33, -1
store i32 %34, i32* %5
br label %36
35: ; preds = %23
br label %40
36: ; preds = %27
br label %37
37: ; preds = %36
%38 = load i32, i32* %5
%39 = icmp sgt i32 %38, 0
br i1 %39, label %13, label %40
40: ; preds = %37, %35
br label %41
41: ; preds = %40, %11
%42 = load i8*, i8** %3
ret i8* %42
}

LLVM IR (-O2):
define i8* @get_hex_line(i32* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = bitcast i64* %3 to i8*
%6 = call i32 @getline(i8** %2, i64* %3, i32* %0)
%7 = icmp slt i32 %6, 0
br i1 %7, label %20, label %8
8: ; preds = %1
%9 = zext i32 %6 to i64
br label %10
10: ; preds = %8, %16
%11 = phi i64 [ %9, %8 ], [ %13, %16 ]
%12 = load i8*, i8** %2
%13 = add nsw i64 %11, -1
%14 = getelementptr inbounds i8, i8* %12, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %20 [
i8 13, label %16
i8 10, label %16
]
16: ; preds = %10, %10
store i8 0, i8* %14
%17 = icmp ugt i64 %11, 1
br i1 %17, label %10, label %18
18: ; preds = %16
%19 = load i8*, i8** %2
br label %20
20: ; preds = %10, %1, %18
%21 = phi i8* [ %19, %18 ], [ null, %1 ], [ %12, %10 ]
ret i8* %21
}