#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);
  len = strlen(progname) + 200;
  temp = (char *)calloc(1, len);
  snprintf(temp, len, "%s %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    $0xc8,%eax
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%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    0xe1e(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
cmpl   $0x0,-0x14(%rbp)
jle    124e <getVersion+0xde>
mov    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x14,%esi
lea    0xdff(%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    12b8 <getVersion+0x148>
mov    -0x30(%rbp),%rdi
mov    0x10(%rbp),%ecx
mov    $0x14,%esi
lea    0xd9e(%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    1322 <getVersion+0x1b2>
cmpl   $0x0,-0x1c(%rbp)
jle    131d <getVersion+0x1ad>
mov    -0x30(%rbp),%rdi
mov    -0x1c(%rbp),%ecx
mov    $0x14,%esi
lea    0xd3a(%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    1322 <getVersion+0x1b2>
cmpl   $0x0,-0x18(%rbp)
jle    1393 <getVersion+0x223>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%ecx
mov    $0x14,%esi
lea    0xcd8(%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    $0xc8,%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    0xe0d(%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    0xdca(%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    0xda6(%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    0xd6d(%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 = [9 x i8] c"%s %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, 200
store i32 %21, i32* %15
%22 = load i32, i32* %15
%23 = call i8* @calloc(i32 1, i32 %22)
store i8* %23, i8** %16
%24 = load i8*, i8** %16
%25 = load i32, i32* %15
%26 = load i8*, i8** %8
%27 = load i32, i32* %9
%28 = load i32, i32* %10
%29 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %24, i32 %25, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* %26, i32 %27, i32 %28)
%30 = load i32, i32* %11
%31 = icmp sgt i32 %30, 0
br i1 %31, label %32, label %45
32: ; preds = %7
%33 = load i8*, i8** %17
%34 = load i32, i32* %11
%35 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %33, i32 20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %34)
%36 = load i8*, i8** %16
%37 = load i8*, i8** %17
%38 = load i32, i32* %15
%39 = load i8*, i8** %16
%40 = call i32 @strlen(i8* %39)
%41 = sub nsw i32 %38, %40
%42 = call i32 @strncat(i8* %36, i8* %37, i32 %41)
%43 = load i8*, i8** %17
%44 = call i32 @memset(i8* %43, i32 0, i32 20)
br label %45
45: ; preds = %32, %7
%46 = load i32, i32* %14
%47 = icmp sgt i32 %46, 0
br i1 %47, label %48, label %61
48: ; preds = %45
%49 = load i8*, i8** %17
%50 = load i32, i32* %14
%51 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %49, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 %50)
%52 = load i8*, i8** %16
%53 = load i8*, i8** %17
%54 = load i32, i32* %15
%55 = load i8*, i8** %16
%56 = call i32 @strlen(i8* %55)
%57 = sub nsw i32 %54, %56
%58 = call i32 @strncat(i8* %52, i8* %53, i32 %57)
%59 = load i8*, i8** %17
%60 = call i32 @memset(i8* %59, i32 0, i32 20)
br label %78
61: ; preds = %45
%62 = load i32, i32* %13
%63 = icmp sgt i32 %62, 0
br i1 %63, label %64, label %77
64: ; preds = %61
%65 = load i8*, i8** %17
%66 = load i32, i32* %13
%67 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %65, i32 20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %66)
%68 = load i8*, i8** %16
%69 = load i8*, i8** %17
%70 = load i32, i32* %15
%71 = load i8*, i8** %16
%72 = call i32 @strlen(i8* %71)
%73 = sub nsw i32 %70, %72
%74 = call i32 @strncat(i8* %68, i8* %69, i32 %73)
%75 = load i8*, i8** %17
%76 = call i32 @memset(i8* %75, i32 0, i32 20)
br label %77
77: ; preds = %64, %61
br label %78
78: ; preds = %77, %48
%79 = load i32, i32* %12
%80 = icmp sgt i32 %79, 0
br i1 %80, label %81, label %94
81: ; preds = %78
%82 = load i8*, i8** %17
%83 = load i32, i32* %12
%84 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %82, i32 20, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %83)
%85 = load i8*, i8** %16
%86 = load i8*, i8** %17
%87 = load i32, i32* %15
%88 = load i8*, i8** %16
%89 = call i32 @strlen(i8* %88)
%90 = sub nsw i32 %87, %89
%91 = call i32 @strncat(i8* %85, i8* %86, i32 %90)
%92 = load i8*, i8** %17
%93 = call i32 @memset(i8* %92, i32 0, i32 20)
br label %94
94: ; preds = %81, %78
%95 = load i8*, i8** %17
%96 = call i32 @free(i8* %95)
%97 = load i8*, i8** %16
%98 = load i8*, i8** %16
%99 = call i32 @strlen(i8* %98)
%100 = add nsw i32 %99, 1
%101 = call i8* @realloc(i8* %97, i32 %100)
store i8* %101, i8** %16
%102 = load i8*, i8** %16
ret i8* %102
}

LLVM IR (-O2):
@.str = [9 x i8] c"%s %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, 200
%11 = tail call i8* @calloc(i32 1, i32 %10)
%12 = tail call i32 (i8*, i32, i8*, ...) @snprintf(i8* %11, i32 %10, i8* getelementptr inbounds ([9 x i8], [9 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
}