#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 EOF;
int getc(int /*<<< orphan*/ *);
unsigned char *malloc(int);
unsigned char *realloc(unsigned char *, int);
unsigned char *_xdg_mime_magic_read_to_newline(FILE *magic_file,
                                               int *end_of_file) {
  unsigned char *retval;
  int c;
  int len, pos;
  len = 128;
  pos = 0;
  retval = malloc(len);
  *end_of_file = (0);
  while ((!(0))) {
    c = getc(magic_file);
    if (c == EOF) {
      *end_of_file = (!(0));
      break;
    }
    if (c == '\n' || c == '\000')
      break;
    retval[pos++] = (unsigned char)c;
    if (pos % 128 == 127) {
      len = len + 128;
      retval = realloc(retval, len);
    }
  }
  retval[pos] = '\000';
  return retval;
}


x86 assembly (clang, -O0):
<_xdg_mime_magic_read_to_newline>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x80,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x20(%rbp),%edi
call   1030 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
movl   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
call   1050 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e6e(%rip),%rcx
cmp    (%rcx),%eax
jne    1191 <_xdg_mime_magic_read_to_newline+0x61>
mov    -0x10(%rbp),%rax
movl   $0x1,(%rax)
jmp    11f8 <_xdg_mime_magic_read_to_newline+0xc8>
cmpl   $0xa,-0x1c(%rbp)
je     11a5 <_xdg_mime_magic_read_to_newline+0x75>
cmpl   $0x0,-0x1c(%rbp)
jne    11aa <_xdg_mime_magic_read_to_newline+0x7a>
jmp    11f8 <_xdg_mime_magic_read_to_newline+0xc8>
mov    -0x1c(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
mov    -0x24(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x24(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
mov    $0x80,%ecx
cltd
idiv   %ecx
cmp    $0x7f,%edx
jne    11f3 <_xdg_mime_magic_read_to_newline+0xc3>
mov    -0x20(%rbp),%eax
add    $0x80,%eax
mov    %eax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%esi
call   1040 <realloc@plt>
mov    %rax,-0x18(%rbp)
jmp    1164 <_xdg_mime_magic_read_to_newline+0x34>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_xdg_mime_magic_read_to_newline>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0x80,%r12d
mov    $0x80,%edi
call   1030 <malloc@plt>
mov    %rax,%rbx
movl   $0x0,(%r14)
mov    %r15,%rdi
call   1050 <getc@plt>
mov    0x2e7e(%rip),%r13
cmp    0x0(%r13),%eax
jne    1191 <_xdg_mime_magic_read_to_newline+0x61>
xor    %ebp,%ebp
movl   $0x1,(%r14)
mov    %ebp,%eax
movb   $0x0,(%rbx,%rax,1)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xor    %ebp,%ebp
jmp    11ae <_xdg_mime_magic_read_to_newline+0x7e>
cs nopw 0x0(%rax,%rax,1)
nop
mov    %r15,%rdi
call   1050 <getc@plt>
cmp    0x0(%r13),%eax
je     1172 <_xdg_mime_magic_read_to_newline+0x42>
test   %eax,%eax
je     1179 <_xdg_mime_magic_read_to_newline+0x49>
cmp    $0xa,%eax
je     1179 <_xdg_mime_magic_read_to_newline+0x49>
mov    %al,(%rbx,%rbp,1)
add    $0x1,%rbp
mov    %ebp,%eax
not    %eax
test   $0x7f,%al
jne    11a0 <_xdg_mime_magic_read_to_newline+0x70>
sub    $0xffffff80,%r12d
mov    %rbx,%rdi
mov    %r12d,%esi
call   1040 <realloc@plt>
mov    %rax,%rbx
jmp    11a0 <_xdg_mime_magic_read_to_newline+0x70>

LLVM IR (-O0):
@EOF = global i32 0
define i8* @_xdg_mime_magic_read_to_newline(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i32* %0, i32** %3
store i32* %1, i32** %4
store i32 128, i32* %7
store i32 0, i32* %8
%9 = load i32, i32* %7
%10 = call i8* @malloc(i32 %9)
store i8* %10, i8** %5
%11 = load i32*, i32** %4
store i32 0, i32* %11
br label %12
12: ; preds = %2, %44
%13 = load i32*, i32** %3
%14 = call i32 @getc(i32* %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = load i32, i32* @EOF
%17 = icmp eq i32 %15, %16
br i1 %17, label %18, label %20
18: ; preds = %12
%19 = load i32*, i32** %4
store i32 1, i32* %19
br label %45
20: ; preds = %12
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, 10
br i1 %22, label %26, label %23
23: ; preds = %20
%24 = load i32, i32* %6
%25 = icmp eq i32 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23, %20
br label %45
27: ; preds = %23
%28 = load i32, i32* %6
%29 = trunc i32 %28 to i8
%30 = load i8*, i8** %5
%31 = load i32, i32* %8
%32 = add nsw i32 %31, 1
store i32 %32, i32* %8
%33 = sext i32 %31 to i64
%34 = getelementptr inbounds i8, i8* %30, i64 %33
store i8 %29, i8* %34
%35 = load i32, i32* %8
%36 = srem i32 %35, 128
%37 = icmp eq i32 %36, 127
br i1 %37, label %38, label %44
38: ; preds = %27
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 128
store i32 %40, i32* %7
%41 = load i8*, i8** %5
%42 = load i32, i32* %7
%43 = call i8* @realloc(i8* %41, i32 %42)
store i8* %43, i8** %5
br label %44
44: ; preds = %38, %27
br label %12
45: ; preds = %26, %18
%46 = load i8*, i8** %5
%47 = load i32, i32* %8
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i8*, i8** %5
ret i8* %50
}

LLVM IR (-O2):
@EOF = global i32 0
define i8* @_xdg_mime_magic_read_to_newline(i32* nocapture %0, i32* nocapture writeonly %1) {
%3 = tail call dereferenceable_or_null(128) i8* @malloc(i32 128)
store i32 0, i32* %1
%4 = tail call i32 @getc(i32* %0)
%5 = load i32, i32* @EOF
%6 = icmp eq i32 %4, %5
br i1 %6, label %7, label %10
7: ; preds = %24, %2
%8 = phi i8* [ %3, %2 ], [ %25, %24 ]
%9 = phi i64 [ 0, %2 ], [ %17, %24 ]
store i32 1, i32* %1
br label %30
10: ; preds = %2, %24
%11 = phi i64 [ %17, %24 ], [ 0, %2 ]
%12 = phi i32 [ %27, %24 ], [ %4, %2 ]
%13 = phi i32 [ %26, %24 ], [ 128, %2 ]
%14 = phi i8* [ %25, %24 ], [ %3, %2 ]
switch i32 %12, label %15 [
i32 10, label %30
i32 0, label %30
]
15: ; preds = %10
%16 = trunc i32 %12 to i8
%17 = add nuw i64 %11, 1
%18 = getelementptr inbounds i8, i8* %14, i64 %11
store i8 %16, i8* %18
%19 = and i64 %17, 127
%20 = icmp eq i64 %19, 127
br i1 %20, label %21, label %24
21: ; preds = %15
%22 = add nsw i32 %13, 128
%23 = tail call i8* @realloc(i8* %14, i32 %22)
br label %24
24: ; preds = %21, %15
%25 = phi i8* [ %23, %21 ], [ %14, %15 ]
%26 = phi i32 [ %22, %21 ], [ %13, %15 ]
%27 = tail call i32 @getc(i32* %0)
%28 = load i32, i32* @EOF
%29 = icmp eq i32 %27, %28
br i1 %29, label %7, label %10
30: ; preds = %10, %10, %7
%31 = phi i8* [ %8, %7 ], [ %14, %10 ], [ %14, %10 ]
%32 = phi i64 [ %9, %7 ], [ %11, %10 ], [ %11, %10 ]
%33 = and i64 %32, 4294967295
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
ret i8* %31
}