#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 /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
void *getc(int /*<<< orphan*/ *);
int rpmlget16(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *xrealloc(char *, int);
char *rpmlgetfn(FILE *fp, char **lastfnp, int *lastfnlp) {
  int ol, l;
  char *n;
  char *lastfn = *lastfnp;
  int lastfnl = *lastfnlp;
  ol = getc(fp);
  if (ol == EOF) {
    fprintf(stderr, "rpmlgetfn: EOF reached!\n");
    exit(1);
  }
  l = getc(fp);
  if (l == 255)
    l = rpmlget16(fp);
  if (l + ol + 1 > lastfnl) {
    lastfn = xrealloc(lastfn, l + ol + 1);
    lastfnl = l + ol + 1;
  }
  n = lastfn + ol;
  while (l-- > 0)
    *n++ = getc(fp);
  *n = 0;
  *lastfnp = lastfn;
  *lastfnlp = lastfnl;
  return lastfn;
}


x86 assembly (clang, -O0):
<rpmlgetfn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rax
mov    (%rax),%eax
mov    %eax,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2e5a(%rip),%rcx
cmp    (%rcx),%eax
jne    11b5 <rpmlgetfn+0x65>
mov    0x2e3b(%rip),%rax
mov    (%rax),%edi
lea    0xe5a(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xff,-0x20(%rbp)
jne    11da <rpmlgetfn+0x8a>
mov    -0x8(%rbp),%rdi
call   1040 <rpmlget16@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x1,%eax
cmp    -0x34(%rbp),%eax
jle    120e <rpmlgetfn+0xbe>
mov    -0x30(%rbp),%rdi
mov    -0x20(%rbp),%esi
add    -0x1c(%rbp),%esi
add    $0x1,%esi
call   1030 <xrealloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%eax
add    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rax
movslq -0x1c(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x20(%rbp)
cmp    $0x0,%eax
jle    1252 <rpmlgetfn+0x102>
mov    -0x8(%rbp),%rdi
call   1070 <getc@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x28(%rbp)
mov    %cl,(%rax)
jmp    121d <rpmlgetfn+0xcd>
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x30(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x34(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpmlgetfn>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rdx,%rbp
mov    %rdi,%r15
mov    %rsi,0x8(%rsp)
mov    (%rsi),%r13
mov    (%rdx),%r12d
call   1070 <getc@plt>
mov    %rax,%r14
mov    0x2e6a(%rip),%rax
cmp    %r14d,(%rax)
je     121f <rpmlgetfn+0xcf>
mov    %r15,%rdi
call   1070 <getc@plt>
mov    %rax,%rbx
cmp    $0xff,%ebx
jne    11a4 <rpmlgetfn+0x54>
mov    %r15,%rdi
call   1040 <rpmlget16@plt>
mov    %eax,%ebx
lea    (%rbx,%r14,1),%eax
cmp    %r12d,%eax
mov    %rbp,0x10(%rsp)
jl     11c8 <rpmlgetfn+0x78>
lea    (%rbx,%r14,1),%r12d
add    $0x1,%r12d
mov    %r13,%rdi
mov    %r12d,%esi
call   1030 <xrealloc@plt>
mov    %rax,%r13
movslq %r14d,%rbp
add    %r13,%rbp
test   %ebx,%ebx
jle    11f9 <rpmlgetfn+0xa9>
add    $0x1,%ebx
mov    0x8(%rsp),%r14
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
call   1070 <getc@plt>
mov    %al,0x0(%rbp)
add    $0x1,%rbp
add    $0xffffffff,%ebx
cmp    $0x1,%ebx
ja     11e0 <rpmlgetfn+0x90>
jmp    11fe <rpmlgetfn+0xae>
mov    0x8(%rsp),%r14
movb   $0x0,0x0(%rbp)
mov    %r13,(%r14)
mov    0x10(%rsp),%rax
mov    %r12d,(%rax)
mov    %r13,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2db2(%rip),%rax
mov    (%rax),%edi
lea    0xdd1(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@EOF = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"rpmlgetfn: EOF reached!\0A\00"
define i8* @rpmlgetfn(i32* %0, i8** %1, i32* %2) {
%4 = alloca i32*
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i32* %0, i32** %4
store i8** %1, i8*** %5
store i32* %2, i32** %6
%12 = load i8**, i8*** %5
%13 = load i8*, i8** %12
store i8* %13, i8** %10
%14 = load i32*, i32** %6
%15 = load i32, i32* %14
store i32 %15, i32* %11
%16 = load i32*, i32** %4
%17 = call i8* @getc(i32* %16)
%18 = ptrtoint i8* %17 to i32
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = load i32, i32* @EOF
%21 = icmp eq i32 %19, %20
br i1 %21, label %22, label %26
22: ; preds = %3
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%25 = call i32 @exit(i32 1)
unreachable
26: ; preds = %3
%27 = load i32*, i32** %4
%28 = call i8* @getc(i32* %27)
%29 = ptrtoint i8* %28 to i32
store i32 %29, i32* %8
%30 = load i32, i32* %8
%31 = icmp eq i32 %30, 255
br i1 %31, label %32, label %35
32: ; preds = %26
%33 = load i32*, i32** %4
%34 = call i32 @rpmlget16(i32* %33)
store i32 %34, i32* %8
br label %35
35: ; preds = %32, %26
%36 = load i32, i32* %8
%37 = load i32, i32* %7
%38 = add nsw i32 %36, %37
%39 = add nsw i32 %38, 1
%40 = load i32, i32* %11
%41 = icmp sgt i32 %39, %40
br i1 %41, label %42, label %53
42: ; preds = %35
%43 = load i8*, i8** %10
%44 = load i32, i32* %8
%45 = load i32, i32* %7
%46 = add nsw i32 %44, %45
%47 = add nsw i32 %46, 1
%48 = call i8* @xrealloc(i8* %43, i32 %47)
store i8* %48, i8** %10
%49 = load i32, i32* %8
%50 = load i32, i32* %7
%51 = add nsw i32 %49, %50
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %53
53: ; preds = %42, %35
%54 = load i8*, i8** %10
%55 = load i32, i32* %7
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds i8, i8* %54, i64 %56
store i8* %57, i8** %9
br label %58
58: ; preds = %62, %53
%59 = load i32, i32* %8
%60 = add nsw i32 %59, -1
store i32 %60, i32* %8
%61 = icmp sgt i32 %59, 0
br i1 %61, label %62, label %68
62: ; preds = %58
%63 = load i32*, i32** %4
%64 = call i8* @getc(i32* %63)
%65 = ptrtoint i8* %64 to i8
%66 = load i8*, i8** %9
%67 = getelementptr inbounds i8, i8* %66, i32 1
store i8* %67, i8** %9
store i8 %65, i8* %66
br label %58
68: ; preds = %58
%69 = load i8*, i8** %9
store i8 0, i8* %69
%70 = load i8*, i8** %10
%71 = load i8**, i8*** %5
store i8* %70, i8** %71
%72 = load i32, i32* %11
%73 = load i32*, i32** %6
store i32 %72, i32* %73
%74 = load i8*, i8** %10
ret i8* %74
}

LLVM IR (-O2):
@EOF = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"rpmlgetfn: EOF reached!\0A\00"
define i8* @rpmlgetfn(i32* %0, i8** nocapture %1, i32* nocapture %2) {
%4 = load i8*, i8** %1
%5 = load i32, i32* %2
%6 = tail call i8* @getc(i32* %0)
%7 = ptrtoint i8* %6 to i64
%8 = trunc i64 %7 to i32
%9 = load i32, i32* @EOF
%10 = icmp eq i32 %9, %8
br i1 %10, label %11, label %15
11: ; preds = %3
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @exit(i32 1)
unreachable
15: ; preds = %3
%16 = tail call i8* @getc(i32* %0)
%17 = ptrtoint i8* %16 to i64
%18 = trunc i64 %17 to i32
%19 = icmp eq i32 %18, 255
br i1 %19, label %20, label %22
20: ; preds = %15
%21 = tail call i32 @rpmlget16(i32* %0)
br label %22
22: ; preds = %20, %15
%23 = phi i32 [ %21, %20 ], [ %18, %15 ]
%24 = add nsw i32 %23, %8
%25 = add nsw i32 %24, 1
%26 = icmp slt i32 %24, %5
br i1 %26, label %29, label %27
27: ; preds = %22
%28 = tail call i8* @xrealloc(i8* %4, i32 %25)
br label %29
29: ; preds = %27, %22
%30 = phi i8* [ %28, %27 ], [ %4, %22 ]
%31 = phi i32 [ %25, %27 ], [ %5, %22 ]
%32 = shl i64 %7, 32
%33 = ashr exact i64 %32, 32
%34 = getelementptr inbounds i8, i8* %30, i64 %33
%35 = icmp sgt i32 %23, 0
br i1 %35, label %36, label %45
36: ; preds = %29, %36
%37 = phi i8* [ %43, %36 ], [ %34, %29 ]
%38 = phi i32 [ %39, %36 ], [ %23, %29 ]
%39 = add nsw i32 %38, -1
%40 = tail call i8* @getc(i32* %0)
%41 = ptrtoint i8* %40 to i64
%42 = trunc i64 %41 to i8
%43 = getelementptr inbounds i8, i8* %37, i64 1
store i8 %42, i8* %37
%44 = icmp ugt i32 %38, 1
br i1 %44, label %36, label %45
45: ; preds = %36, %29
%46 = phi i8* [ %34, %29 ], [ %43, %36 ]
store i8 0, i8* %46
store i8* %30, i8** %1
store i32 %31, i32* %2
ret i8* %30
}