#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 */
void *getc(int /*<<< orphan*/ *);
char *xmalloc(int);
char *rpmlgetstr(FILE *fp) {
  int l;
  char *s, *s2;
  l = getc(fp);
  s = s2 = xmalloc(l + 2);
  while (l-- > 0)
    *s2++ = getc(fp);
  *s2 = 0;
  return s;
}


x86 assembly (clang, -O0):
<rpmlgetstr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
add    $0x2,%edi
call   1030 <xmalloc@plt>
mov    %rax,-0x20(%rbp)
mov    %rax,-0x18(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
jle    1180 <rpmlgetstr+0x60>
mov    -0x8(%rbp),%rdi
call   1040 <getc@plt>
mov    %al,%cl
mov    -0x20(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x20(%rbp)
mov    %cl,(%rax)
jmp    114b <rpmlgetstr+0x2b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rpmlgetstr>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
call   1040 <getc@plt>
mov    %rax,%r12
lea    0x2(%rax),%edi
call   1030 <xmalloc@plt>
mov    %rax,%r15
mov    %rax,%rbx
test   %r12d,%r12d
jle    1168 <rpmlgetstr+0x48>
add    $0x1,%r12d
mov    %r15,%rbx
nopl   (%rax)
mov    %r14,%rdi
call   1040 <getc@plt>
mov    %al,(%rbx)
add    $0x1,%rbx
add    $0xffffffff,%r12d
cmp    $0x1,%r12d
ja     1150 <rpmlgetstr+0x30>
movb   $0x0,(%rbx)
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i8* @rpmlgetstr(i32* %0) {
%2 = alloca i32*
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
store i32* %0, i32** %2
%6 = load i32*, i32** %2
%7 = call i8* @getc(i32* %6)
%8 = ptrtoint i8* %7 to i32
store i32 %8, i32* %3
%9 = load i32, i32* %3
%10 = add nsw i32 %9, 2
%11 = call i8* @xmalloc(i32 %10)
store i8* %11, i8** %5
store i8* %11, i8** %4
br label %12
12: ; preds = %16, %1
%13 = load i32, i32* %3
%14 = add nsw i32 %13, -1
store i32 %14, i32* %3
%15 = icmp sgt i32 %13, 0
br i1 %15, label %16, label %22
16: ; preds = %12
%17 = load i32*, i32** %2
%18 = call i8* @getc(i32* %17)
%19 = ptrtoint i8* %18 to i8
%20 = load i8*, i8** %5
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %5
store i8 %19, i8* %20
br label %12
22: ; preds = %12
%23 = load i8*, i8** %5
store i8 0, i8* %23
%24 = load i8*, i8** %4
ret i8* %24
}

LLVM IR (-O2):
define i8* @rpmlgetstr(i32* nocapture %0) {
%2 = tail call i8* @getc(i32* %0)
%3 = ptrtoint i8* %2 to i64
%4 = trunc i64 %3 to i32
%5 = add nsw i32 %4, 2
%6 = tail call i8* @xmalloc(i32 %5)
%7 = icmp sgt i32 %4, 0
br i1 %7, label %8, label %17
8: ; preds = %1, %8
%9 = phi i8* [ %15, %8 ], [ %6, %1 ]
%10 = phi i32 [ %11, %8 ], [ %4, %1 ]
%11 = add nsw i32 %10, -1
%12 = tail call i8* @getc(i32* %0)
%13 = ptrtoint i8* %12 to i64
%14 = trunc i64 %13 to i8
%15 = getelementptr inbounds i8, i8* %9, i64 1
store i8 %14, i8* %9
%16 = icmp ugt i32 %10, 1
br i1 %16, label %8, label %17
17: ; preds = %8, %1
%18 = phi i8* [ %6, %1 ], [ %15, %8 ]
store i8 0, i8* %18
ret i8* %6
}