#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 */
struct rpmhead {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(unsigned int *);
unsigned int *headint32(struct rpmhead *, int, int *);
char *headstring(struct rpmhead *, int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ stderr;
scalar_t__ strlen(char *);
char *xmalloc(scalar_t__);
char *headtonevr(struct rpmhead *h) {
  char *name;
  unsigned int *epoch;
  char *version;
  char *release;
  char *nevr;
  int epochcnt = 0;
  name = headstring(h, 1000);
  version = headstring(h, 1001);
  release = headstring(h, 1002);
  epoch = headint32(h, 1003, &epochcnt);
  if (!name || !version || !release) {
    fprintf(stderr, "headtonevr: bad rpm header\n");
    exit(1);
  }
  if (epoch && epochcnt) {
    char epochbuf[11];
    sprintf(epochbuf, "%u", *epoch);
    nevr = xmalloc(strlen(name) + 1 + strlen(epochbuf) + 1 + strlen(version) +
                   1 + strlen(release) + 1);
    sprintf(nevr, "%s-%s:%s-%s", name, epochbuf, version, release);
  } else {
    nevr =
        xmalloc(strlen(name) + 1 + strlen(version) + 1 + strlen(release) + 1);
    sprintf(nevr, "%s-%s-%s", name, version, release);
  }
  if (epoch)
    free(epoch);
  return nevr;
}


x86 assembly (clang, -O0):
<headtonevr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e8,%esi
call   1080 <headstring@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3e9,%esi
call   1080 <headstring@plt>
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3ea,%esi
call   1080 <headstring@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x3eb,%esi
lea    -0x34(%rbp),%rdx
call   1070 <headint32@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1200 <headtonevr+0x80>
cmpq   $0x0,-0x20(%rbp)
je     1200 <headtonevr+0x80>
cmpq   $0x0,-0x28(%rbp)
jne    121f <headtonevr+0x9f>
mov    0x2dd9(%rip),%rax
mov    (%rax),%edi
lea    0xdf0(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
cmpq   $0x0,-0x18(%rbp)
je     12d7 <headtonevr+0x157>
cmpl   $0x0,-0x34(%rbp)
je     12d7 <headtonevr+0x157>
lea    -0x3f(%rbp),%rdi
mov    -0x18(%rbp),%rax
mov    (%rax),%edx
lea    0xdd7(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
lea    -0x3f(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x58(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x50(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x48(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x48(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    -0x3f(%rbp),%rcx
mov    -0x20(%rbp),%r8
mov    -0x28(%rbp),%r9
lea    0xd54(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
jmp    133e <headtonevr+0x1be>
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
add    $0x1,%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
mov    -0x68(%rbp),%rax
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x60(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x60(%rbp),%rdi
add    %rax,%rdi
add    $0x1,%rdi
call   1050 <xmalloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    -0x28(%rbp),%r8
lea    0xcf4(%rip),%rsi
mov    $0x0,%al
call   1090 <sprintf@plt>
cmpq   $0x0,-0x18(%rbp)
je     1352 <headtonevr+0x1d2>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<headtonevr>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%rbp
movl   $0x0,0xc(%rsp)
mov    $0x3e8,%esi
call   1080 <headstring@plt>
mov    %rax,%r14
mov    %rbp,%rdi
mov    $0x3e9,%esi
call   1080 <headstring@plt>
mov    %rax,%r15
mov    %rbp,%rdi
mov    $0x3ea,%esi
call   1080 <headstring@plt>
mov    %rax,%rbx
lea    0xc(%rsp),%rdx
mov    %rbp,%rdi
mov    $0x3eb,%esi
call   1070 <headint32@plt>
test   %r14,%r14
je     12f7 <headtonevr+0x177>
test   %r15,%r15
je     12f7 <headtonevr+0x177>
test   %rbx,%rbx
je     12f7 <headtonevr+0x177>
mov    %rax,%r12
test   %rax,%rax
je     128d <headtonevr+0x10d>
cmpl   $0x0,0xc(%rsp)
je     128d <headtonevr+0x10d>
mov    (%r12),%edx
lea    0xe07(%rip),%rsi
lea    0x1d(%rsp),%rbp
mov    %rbp,%rdi
xor    %eax,%eax
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,0x10(%rsp)
mov    %rbp,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    0x10(%rsp),%r13
add    %rbp,%r13
lea    (%rax,%r13,1),%rdi
add    $0x4,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%rbp
lea    0xdb1(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
lea    0x1d(%rsp),%rcx
mov    %r15,%r8
mov    %rbx,%r9
xor    %eax,%eax
call   1090 <sprintf@plt>
test   %r12,%r12
jne    12dd <headtonevr+0x15d>
jmp    12e5 <headtonevr+0x165>
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rax,%r13
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
call   1040 <strlen@plt>
add    %r13,%rbp
lea    (%rax,%rbp,1),%rdi
add    $0x3,%rdi
call   1050 <xmalloc@plt>
mov    %rax,%rbp
lea    0xd66(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rbx,%r8
xor    %eax,%eax
call   1090 <sprintf@plt>
test   %r12,%r12
je     12e5 <headtonevr+0x165>
mov    %r12,%rdi
call   1030 <free@plt>
mov    %rbp,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
lea    0xcf9(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
%struct.rpmhead = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"headtonevr: bad rpm header\0A\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [12 x i8] c"%s-%s:%s-%s\00"
@.str.3 = [9 x i8] c"%s-%s-%s\00"
define i8* @headtonevr(%struct.rpmhead* %0) {
%2 = alloca %struct.rpmhead*
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca [11 x i8]
store %struct.rpmhead* %0, %struct.rpmhead** %2
store i32 0, i32* %8
%10 = load %struct.rpmhead*, %struct.rpmhead** %2
%11 = call i8* @headstring(%struct.rpmhead* %10, i32 1000)
store i8* %11, i8** %3
%12 = load %struct.rpmhead*, %struct.rpmhead** %2
%13 = call i8* @headstring(%struct.rpmhead* %12, i32 1001)
store i8* %13, i8** %5
%14 = load %struct.rpmhead*, %struct.rpmhead** %2
%15 = call i8* @headstring(%struct.rpmhead* %14, i32 1002)
store i8* %15, i8** %6
%16 = load %struct.rpmhead*, %struct.rpmhead** %2
%17 = call i32* @headint32(%struct.rpmhead* %16, i32 1003, i32* %8)
store i32* %17, i32** %4
%18 = load i8*, i8** %3
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %26
20: ; preds = %1
%21 = load i8*, i8** %5
%22 = icmp ne i8* %21, null
br i1 %22, label %23, label %26
23: ; preds = %20
%24 = load i8*, i8** %6
%25 = icmp ne i8* %24, null
br i1 %25, label %30, label %26
26: ; preds = %23, %20, %1
%27 = load i32, i32* @stderr
%28 = call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%29 = call i32 @exit(i32 1)
unreachable
30: ; preds = %23
%31 = load i32*, i32** %4
%32 = icmp ne i32* %31, null
br i1 %32, label %33, label %63
33: ; preds = %30
%34 = load i32, i32* %8
%35 = icmp ne i32 %34, 0
br i1 %35, label %36, label %63
36: ; preds = %33
%37 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%38 = load i32*, i32** %4
%39 = load i32, i32* %38
%40 = call i32 (i8*, i8*, ...) @sprintf(i8* %37, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %39)
%41 = load i8*, i8** %3
%42 = call i64 @strlen(i8* %41)
%43 = add nsw i64 %42, 1
%44 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%45 = call i64 @strlen(i8* %44)
%46 = add nsw i64 %43, %45
%47 = add nsw i64 %46, 1
%48 = load i8*, i8** %5
%49 = call i64 @strlen(i8* %48)
%50 = add nsw i64 %47, %49
%51 = add nsw i64 %50, 1
%52 = load i8*, i8** %6
%53 = call i64 @strlen(i8* %52)
%54 = add nsw i64 %51, %53
%55 = add nsw i64 %54, 1
%56 = call i8* @xmalloc(i64 %55)
store i8* %56, i8** %7
%57 = load i8*, i8** %7
%58 = load i8*, i8** %3
%59 = getelementptr inbounds [11 x i8], [11 x i8]* %9, i64 0, i64 0
%60 = load i8*, i8** %5
%61 = load i8*, i8** %6
%62 = call i32 (i8*, i8*, ...) @sprintf(i8* %57, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %58, i8* %59, i8* %60, i8* %61)
br label %81
63: ; preds = %33, %30
%64 = load i8*, i8** %3
%65 = call i64 @strlen(i8* %64)
%66 = add nsw i64 %65, 1
%67 = load i8*, i8** %5
%68 = call i64 @strlen(i8* %67)
%69 = add nsw i64 %66, %68
%70 = add nsw i64 %69, 1
%71 = load i8*, i8** %6
%72 = call i64 @strlen(i8* %71)
%73 = add nsw i64 %70, %72
%74 = add nsw i64 %73, 1
%75 = call i8* @xmalloc(i64 %74)
store i8* %75, i8** %7
%76 = load i8*, i8** %7
%77 = load i8*, i8** %3
%78 = load i8*, i8** %5
%79 = load i8*, i8** %6
%80 = call i32 (i8*, i8*, ...) @sprintf(i8* %76, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %77, i8* %78, i8* %79)
br label %81
81: ; preds = %63, %36
%82 = load i32*, i32** %4
%83 = icmp ne i32* %82, null
br i1 %83, label %84, label %87
84: ; preds = %81
%85 = load i32*, i32** %4
%86 = call i32 @free(i32* %85)
br label %87
87: ; preds = %84, %81
%88 = load i8*, i8** %7
ret i8* %88
}

LLVM IR (-O2):
%struct.rpmhead = type { i32 }
@stderr = global i32 0
@.str = [28 x i8] c"headtonevr: bad rpm header\0A\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [12 x i8] c"%s-%s:%s-%s\00"
@.str.3 = [9 x i8] c"%s-%s-%s\00"
define i8* @headtonevr(%struct.rpmhead* %0) {
%2 = alloca i32
%3 = alloca [11 x i8]
%4 = bitcast i32* %2 to i8*
store i32 0, i32* %2
%5 = tail call i8* @headstring(%struct.rpmhead* %0, i32 1000)
%6 = tail call i8* @headstring(%struct.rpmhead* %0, i32 1001)
%7 = tail call i8* @headstring(%struct.rpmhead* %0, i32 1002)
%8 = call i32* @headint32(%struct.rpmhead* %0, i32 1003, i32* %2)
%9 = icmp ne i8* %5, null
%10 = icmp ne i8* %6, null
%11 = select i1 %9, i1 %10, i1 false
%12 = icmp ne i8* %7, null
%13 = select i1 %11, i1 %12, i1 false
br i1 %13, label %18, label %14
14: ; preds = %1
%15 = load i32, i32* @stderr
%16 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %1
%19 = icmp ne i32* %8, null
%20 = load i32, i32* %2
%21 = icmp ne i32 %20, 0
%22 = select i1 %19, i1 %21, i1 false
br i1 %22, label %23, label %37
23: ; preds = %18
%24 = getelementptr inbounds [11 x i8], [11 x i8]* %3, i64 0, i64 0
%25 = load i32, i32* %8
%26 = call i32 (i8*, i8*, ...) @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %25)
%27 = call i64 @strlen(i8* %5)
%28 = call i64 @strlen(i8* %24)
%29 = call i64 @strlen(i8* %6)
%30 = call i64 @strlen(i8* %7)
%31 = add i64 %27, 4
%32 = add i64 %31, %28
%33 = add i64 %32, %29
%34 = add i64 %33, %30
%35 = call i8* @xmalloc(i64 %34)
%36 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %35, i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %5, i8* %24, i8* %6, i8* %7)
br label %46
37: ; preds = %18
%38 = call i64 @strlen(i8* %5)
%39 = call i64 @strlen(i8* %6)
%40 = call i64 @strlen(i8* %7)
%41 = add i64 %38, 3
%42 = add i64 %41, %39
%43 = add i64 %42, %40
%44 = call i8* @xmalloc(i64 %43)
%45 = call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %44, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %5, i8* %6, i8* %7)
br label %46
46: ; preds = %37, %23
%47 = phi i8* [ %35, %23 ], [ %44, %37 ]
br i1 %19, label %48, label %50
48: ; preds = %46
%49 = call i32 @free(i32* %8)
br label %50
50: ; preds = %48, %46
ret i8* %47
}