#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 */

/* Variables and functions */
char *calloc(int, int);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
char *realloc(char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int strlen(char *);
int /*<<< orphan*/ strncat(char *, char *, int);
char *getVersion(char *progname, int maj, int min, int submin, int svnrev,
                 int beta, int rc) {
  int len;
  char *temp;
  char *provis = calloc(1, 20 * sizeof(char));
  len = strlen(progname) + 201;
  temp = (char *)calloc(1, len * sizeof(char));
  snprintf(temp, len, "%s v%d.%d", progname, maj, min);
  if (submin > 0) {
    snprintf(provis, 20, ".%d", submin);
    strncat(temp, provis, len - strlen(temp));
    memset(provis, 0, 20);
  }
  if (rc > 0) {
    snprintf(provis, 20, " rc%d", rc);
    strncat(temp, provis, len - strlen(temp));
    memset(provis, 0, 20);
  } else if (beta > 0) {
    snprintf(provis, 20, " beta%d", beta);
    strncat(temp, provis, len - strlen(temp));
    memset(provis, 0, 20);
  }
  if (svnrev > 0) {
    snprintf(provis, 20, " r%d", svnrev);
    strncat(temp, provis, len - strlen(temp));
    memset(provis, 0, 20);
  }
  free(provis);
  temp = realloc(temp, strlen(temp) + 1);
  return temp;
}


x86 assembly (clang, -O0):
<getVersion>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
mov    0x10(%rbp),%eax
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
mov    $0x1,%edi
mov    $0x14,%esi
call   1080 <calloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
add    $0xc9,%eax
mov    %eax,-0x20(%rbp)
movslq -0x20(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%esi
mov    $0x1,%edi
call   1080 <calloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%esi
mov    -0x8(%rbp),%rcx
mov    -0xc(%rbp),%r8d
mov    -0x10(%rbp),%r9d
lea    0xe17(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    1255 <getVersion+0xe5>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x14,%esi
lea    0xdf9(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x44(%rbp),%edx
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
sub    %eax,%edx
call   1070 <strncat@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
cmpl   $0x0,0x10(%rbp)
jle    12bf <getVersion+0x14f>
mov    -0x30(%rbp),%rdi
mov    0x10(%rbp),%ecx
mov    $0x14,%esi
lea    0xd98(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x50(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x5c(%rbp),%edx
mov    -0x58(%rbp),%rdi
mov    -0x50(%rbp),%rsi
sub    %eax,%edx
call   1070 <strncat@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
jmp    1329 <getVersion+0x1b9>
cmpl   $0x0,-0x1c(%rbp)
jle    1324 <getVersion+0x1b4>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    $0x14,%esi
lea    0xd34(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x74(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x74(%rbp),%edx
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
sub    %eax,%edx
call   1070 <strncat@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
jmp    1329 <getVersion+0x1b9>
cmpl   $0x0,-0x18(%rbp)
jle    139a <getVersion+0x22a>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    $0x14,%esi
lea    0xcd2(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x88(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%eax
mov    %eax,-0x8c(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x8c(%rbp),%edx
mov    -0x88(%rbp),%rdi
mov    -0x80(%rbp),%rsi
sub    %eax,%edx
call   1070 <strncat@plt>
mov    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x98(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x98(%rbp),%rdi
mov    %eax,%esi
add    $0x1,%esi
call   1090 <realloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getVersion>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %r9d,0xc(%rsp)
mov    %r8d,0x8(%rsp)
mov    %ecx,%r12d
mov    %edx,0x10(%rsp)
mov    %esi,%r13d
mov    %rdi,%r15
mov    0x50(%rsp),%eax
mov    %eax,0x14(%rsp)
mov    $0x1,%edi
mov    $0x14,%esi
call   1080 <calloc@plt>
mov    %rax,%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
add    $0xc9,%ebp
mov    $0x1,%edi
mov    %ebp,%esi
call   1080 <calloc@plt>
mov    %rax,%rbx
lea    0xe2b(%rip),%rdx
mov    %rax,%rdi
mov    %ebp,%esi
mov    %r15,%rcx
mov    %r13d,%r8d
mov    0x10(%rsp),%r9d
xor    %eax,%eax
call   1050 <snprintf@plt>
test   %r12d,%r12d
jle    1230 <getVersion+0xc0>
lea    0xe0e(%rip),%rdx
mov    %r14,%rdi
mov    $0x14,%esi
mov    %r12d,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strncat@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    0x14(%rsp),%ecx
test   %ecx,%ecx
jle    1255 <getVersion+0xe5>
lea    0xdcb(%rip),%rdx
mov    %r14,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    0x8(%rsp),%r15d
jmp    1278 <getVersion+0x108>
mov    0xc(%rsp),%ecx
test   %ecx,%ecx
mov    0x8(%rsp),%r15d
jle    129e <getVersion+0x12e>
lea    0xda7(%rip),%rdx
mov    %r14,%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %ebp,%edx
sub    %eax,%edx
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <strncat@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
test   %r15d,%r15d
jle    12e2 <getVersion+0x172>
lea    0xd6e(%rip),%rdx
mov    %r14,%rdi
mov    $0x14,%esi
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <snprintf@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
sub    %eax,%ebp
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %ebp,%edx
call   1070 <strncat@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x14,%edx
call   1060 <memset@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%esi
mov    %rbx,%rdi
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1090 <realloc@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"%s v%d.%d\00"
@.str.1 = [4 x i8] c".%d\00"
@.str.2 = [6 x i8] c" rc%d\00"
@.str.3 = [8 x i8] c" beta%d\00"
@.str.4 = [5 x i8] c" r%d\00"
define i8* @getVersion(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i8*
%17 = alloca i8*
store i8* %0, i8** %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 %6, i32* %14
%18 = call i8* @calloc(i32 1, i32 20)
store i8* %18, i8** %17
%19 = load i8*, i8** %8
%20 = call i32 @strlen(i8* %19)
%21 = add nsw i32 %20, 201
store i32 %21, i32* %15
%22 = load i32, i32* %15
%23 = sext i32 %22 to i64
%24 = mul i64 %23, 1
%25 = trunc i64 %24 to i32
%26 = call i8* @calloc(i32 1, i32 %25)
store i8* %26, i8** %16
%27 = load i8*, i8** %16
%28 = load i32, i32* %15
%29 = load i8*, i8** %8
%30 = load i32, i32* %9
%31 = load i32, i32* %10
%32 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %27, i32 %28, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %29, i32 %30, i32 %31)
%33 = load i32, i32* %11
%34 = icmp sgt i32 %33, 0
br i1 %34, label %35, label %48
35: ; preds = %7
%36 = load i8*, i8** %17
%37 = load i32, i32* %11
%38 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %36, i32 20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %16
%40 = load i8*, i8** %17
%41 = load i32, i32* %15
%42 = load i8*, i8** %16
%43 = call i32 @strlen(i8* %42)
%44 = sub nsw i32 %41, %43
%45 = call i32 @strncat(i8* %39, i8* %40, i32 %44)
%46 = load i8*, i8** %17
%47 = call i32 @memset(i8* %46, i32 0, i32 20)
br label %48
48: ; preds = %35, %7
%49 = load i32, i32* %14
%50 = icmp sgt i32 %49, 0
br i1 %50, label %51, label %64
51: ; preds = %48
%52 = load i8*, i8** %17
%53 = load i32, i32* %14
%54 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %52, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %53)
%55 = load i8*, i8** %16
%56 = load i8*, i8** %17
%57 = load i32, i32* %15
%58 = load i8*, i8** %16
%59 = call i32 @strlen(i8* %58)
%60 = sub nsw i32 %57, %59
%61 = call i32 @strncat(i8* %55, i8* %56, i32 %60)
%62 = load i8*, i8** %17
%63 = call i32 @memset(i8* %62, i32 0, i32 20)
br label %81
64: ; preds = %48
%65 = load i32, i32* %13
%66 = icmp sgt i32 %65, 0
br i1 %66, label %67, label %80
67: ; preds = %64
%68 = load i8*, i8** %17
%69 = load i32, i32* %13
%70 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %68, i32 20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %69)
%71 = load i8*, i8** %16
%72 = load i8*, i8** %17
%73 = load i32, i32* %15
%74 = load i8*, i8** %16
%75 = call i32 @strlen(i8* %74)
%76 = sub nsw i32 %73, %75
%77 = call i32 @strncat(i8* %71, i8* %72, i32 %76)
%78 = load i8*, i8** %17
%79 = call i32 @memset(i8* %78, i32 0, i32 20)
br label %80
80: ; preds = %67, %64
br label %81
81: ; preds = %80, %51
%82 = load i32, i32* %12
%83 = icmp sgt i32 %82, 0
br i1 %83, label %84, label %97
84: ; preds = %81
%85 = load i8*, i8** %17
%86 = load i32, i32* %12
%87 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %85, i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %86)
%88 = load i8*, i8** %16
%89 = load i8*, i8** %17
%90 = load i32, i32* %15
%91 = load i8*, i8** %16
%92 = call i32 @strlen(i8* %91)
%93 = sub nsw i32 %90, %92
%94 = call i32 @strncat(i8* %88, i8* %89, i32 %93)
%95 = load i8*, i8** %17
%96 = call i32 @memset(i8* %95, i32 0, i32 20)
br label %97
97: ; preds = %84, %81
%98 = load i8*, i8** %17
%99 = call i32 @free(i8* %98)
%100 = load i8*, i8** %16
%101 = load i8*, i8** %16
%102 = call i32 @strlen(i8* %101)
%103 = add nsw i32 %102, 1
%104 = call i8* @realloc(i8* %100, i32 %103)
store i8* %104, i8** %16
%105 = load i8*, i8** %16
ret i8* %105
}

LLVM IR (-O2):
@.str = [10 x i8] c"%s v%d.%d\00"
@.str.1 = [4 x i8] c".%d\00"
@.str.2 = [6 x i8] c" rc%d\00"
@.str.3 = [8 x i8] c" beta%d\00"
@.str.4 = [5 x i8] c" r%d\00"
define i8* @getVersion(i8* %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i32 %6) {
%8 = tail call dereferenceable_or_null(20) i8* @calloc(i32 1, i32 20)
%9 = tail call i32 @strlen(i8* %0)
%10 = add nsw i32 %9, 201
%11 = tail call i8* @calloc(i32 1, i32 %10)
%12 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 %10, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %0, i32 %1, i32 %2)
%13 = icmp sgt i32 %3, 0
br i1 %13, label %14, label %20
14: ; preds = %7
%15 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %3)
%16 = tail call i32 @strlen(i8* %11)
%17 = sub nsw i32 %10, %16
%18 = tail call i32 @strncat(i8* %11, i8* %8, i32 %17)
%19 = tail call i32 @memset(i8* %8, i32 0, i32 20)
br label %20
20: ; preds = %14, %7
%21 = icmp sgt i32 %6, 0
br i1 %21, label %22, label %24
22: ; preds = %20
%23 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %6)
br label %28
24: ; preds = %20
%25 = icmp sgt i32 %5, 0
br i1 %25, label %26, label %33
26: ; preds = %24
%27 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %5)
br label %28
28: ; preds = %22, %26
%29 = tail call i32 @strlen(i8* %11)
%30 = sub nsw i32 %10, %29
%31 = tail call i32 @strncat(i8* %11, i8* %8, i32 %30)
%32 = tail call i32 @memset(i8* %8, i32 0, i32 20)
br label %33
33: ; preds = %28, %24
%34 = icmp sgt i32 %4, 0
br i1 %34, label %35, label %41
35: ; preds = %33
%36 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %4)
%37 = tail call i32 @strlen(i8* %11)
%38 = sub nsw i32 %10, %37
%39 = tail call i32 @strncat(i8* %11, i8* %8, i32 %38)
%40 = tail call i32 @memset(i8* %8, i32 0, i32 20)
br label %41
41: ; preds = %35, %33
%42 = tail call i32 @free(i8* %8)
%43 = tail call i32 @strlen(i8* %11)
%44 = add nsw i32 %43, 1
%45 = tail call i8* @realloc(i8* %11, i32 %44)
ret i8* %45
}