#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 */
int /*<<< orphan*/ float_string(float, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
scalar_t__ strlen(char *);
char *format_string(char *id, float args[], int n, int *new_size) {
  int total_size = 0;
  total_size += 1 + strlen(id);
  char new_args[6][4];
  static char ans[100];
  strcat(ans, id);
  strcat(ans, (char *)":");
  int i = 0;
  float item;
  char dummy[3 + 3];
  for (; i < n; i++) {
    item = args[i];
    float_string(item, dummy, 3);
    total_size += 1 + strlen(dummy);
    strcat(ans, dummy);
    if (i == n - 1)
      strcat(ans, (char *)";");
    else
      strcat(ans, (char *)":");
  }
  total_size += 1;
  *new_size = total_size;
  return ans;
}


x86 assembly (clang, -O0):
<format_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rsi
lea    0x2edd(%rip),%rdi
call   1050 <strcat@plt>
lea    0x2ed1(%rip),%rdi
lea    0xe7a(%rip),%rsi
call   1050 <strcat@plt>
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    123c <format_string+0x10c>
mov    -0x10(%rbp),%rax
movslq -0x44(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
movss  %xmm0,-0x48(%rbp)
movss  -0x48(%rbp),%xmm0
lea    -0x4e(%rbp),%rdi
mov    $0x3,%esi
call   1030 <float_string@plt>
lea    -0x4e(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rcx
add    $0x1,%rcx
movslq -0x24(%rbp),%rax
add    %rcx,%rax
mov    %eax,-0x24(%rbp)
lea    -0x4e(%rbp),%rsi
lea    0x2e68(%rip),%rdi
call   1050 <strcat@plt>
mov    -0x44(%rbp),%eax
mov    -0x14(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1216 <format_string+0xe6>
lea    0x2e4b(%rip),%rdi
lea    0xdf6(%rip),%rsi
call   1050 <strcat@plt>
jmp    1229 <format_string+0xf9>
lea    0x2e33(%rip),%rdi
lea    0xddc(%rip),%rsi
call   1050 <strcat@plt>
jmp    122e <format_string+0xfe>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1192 <format_string+0x62>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
lea    0x2dfb(%rip),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<format_string>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,(%rsp)
mov    %edx,%r13d
mov    %rsi,%r15
mov    %rdi,%rbp
call   1040 <strlen@plt>
mov    %rax,%rbx
add    $0x1,%ebx
lea    0x2ef3(%rip),%r14
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <strcat@plt>
lea    0xe91(%rip),%rsi
mov    %r14,%rdi
call   1050 <strcat@plt>
test   %r13d,%r13d
jle    11f3 <format_string+0xc3>
lea    -0x1(%r13),%eax
mov    %rax,0x8(%rsp)
mov    %r13d,%r12d
mov    %r15,%r14
xor    %r15d,%r15d
lea    0x12(%rsp),%r13
lea    0x2eb6(%rip),%rbp
nopw   0x0(%rax,%rax,1)
movss  (%r14,%r15,4),%xmm0
mov    %r13,%rdi
mov    $0x3,%esi
call   1030 <float_string@plt>
mov    %r13,%rdi
call   1040 <strlen@plt>
add    %eax,%ebx
add    $0x1,%ebx
mov    %rbp,%rdi
mov    %r13,%rsi
call   1050 <strcat@plt>
cmp    %r15,0x8(%rsp)
lea    0xe29(%rip),%rsi
lea    0xe24(%rip),%rax
cmove  %rax,%rsi
mov    %rbp,%rdi
call   1050 <strcat@plt>
add    $0x1,%r15
cmp    %r15,%r12
jne    11a0 <format_string+0x70>
add    $0x1,%ebx
mov    (%rsp),%rax
mov    %ebx,(%rax)
lea    0x2e4d(%rip),%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@format_string.ans = internal global [100 x i8] zeroinitializer
@.str = [2 x i8] c":\00"
@.str.1 = [2 x i8] c";\00"
define i8* @format_string(i8* %0, float* %1, i32 %2, i32* %3) {
%5 = alloca i8*
%6 = alloca float*
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32
%10 = alloca [6 x [4 x i8]]
%11 = alloca i32
%12 = alloca float
%13 = alloca [6 x i8]
store i8* %0, i8** %5
store float* %1, float** %6
store i32 %2, i32* %7
store i32* %3, i32** %8
store i32 0, i32* %9
%14 = load i8*, i8** %5
%15 = call i64 @strlen(i8* %14)
%16 = add nsw i64 1, %15
%17 = load i32, i32* %9
%18 = sext i32 %17 to i64
%19 = add nsw i64 %18, %16
%20 = trunc i64 %19 to i32
store i32 %20, i32* %9
%21 = load i8*, i8** %5
%22 = call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* %21)
%23 = call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %11
br label %24
24: ; preds = %55, %4
%25 = load i32, i32* %11
%26 = load i32, i32* %7
%27 = icmp slt i32 %25, %26
br i1 %27, label %28, label %58
28: ; preds = %24
%29 = load float*, float** %6
%30 = load i32, i32* %11
%31 = sext i32 %30 to i64
%32 = getelementptr inbounds float, float* %29, i64 %31
%33 = load float, float* %32
store float %33, float* %12
%34 = load float, float* %12
%35 = getelementptr inbounds [6 x i8], [6 x i8]* %13, i64 0, i64 0
%36 = call i32 @float_string(float %34, i8* %35, i32 3)
%37 = getelementptr inbounds [6 x i8], [6 x i8]* %13, i64 0, i64 0
%38 = call i64 @strlen(i8* %37)
%39 = add nsw i64 1, %38
%40 = load i32, i32* %9
%41 = sext i32 %40 to i64
%42 = add nsw i64 %41, %39
%43 = trunc i64 %42 to i32
store i32 %43, i32* %9
%44 = getelementptr inbounds [6 x i8], [6 x i8]* %13, i64 0, i64 0
%45 = call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %11
%47 = load i32, i32* %7
%48 = sub nsw i32 %47, 1
%49 = icmp eq i32 %46, %48
br i1 %49, label %50, label %52
50: ; preds = %28
%51 = call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
br label %54
52: ; preds = %28
%53 = call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %54
54: ; preds = %52, %50
br label %55
55: ; preds = %54
%56 = load i32, i32* %11
%57 = add nsw i32 %56, 1
store i32 %57, i32* %11
br label %24
58: ; preds = %24
%59 = load i32, i32* %9
%60 = add nsw i32 %59, 1
store i32 %60, i32* %9
%61 = load i32, i32* %9
%62 = load i32*, i32** %8
store i32 %61, i32* %62
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0)
}

LLVM IR (-O2):
@format_string.ans = internal global [100 x i8] zeroinitializer
@.str = [2 x i8] c":\00"
@.str.1 = [2 x i8] c";\00"
define i8* @format_string(i8* %0, float* nocapture %1, i32 %2, i32* nocapture writeonly %3) {
%5 = alloca [6 x i8]
%6 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%7 = trunc i64 %6 to i32
%8 = add i32 %7, 1
%9 = tail call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* %0)
%10 = tail call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = getelementptr inbounds [6 x i8], [6 x i8]* %5, i64 0, i64 0
%12 = icmp sgt i32 %2, 0
br i1 %12, label %13, label %33
13: ; preds = %4
%14 = add nsw i32 %2, -1
%15 = zext i32 %14 to i64
%16 = zext i32 %2 to i64
br label %17
17: ; preds = %13, %17
%18 = phi i64 [ 0, %13 ], [ %31, %17 ]
%19 = phi i32 [ %8, %13 ], [ %26, %17 ]
%20 = getelementptr inbounds float, float* %1, i64 %18
%21 = load float, float* %20
%22 = call i32 @float_string(float %21, i8* %11, i32 3)
%23 = call i64 @strlen(i8* %11)
%24 = trunc i64 %23 to i32
%25 = add i32 %19, 1
%26 = add i32 %25, %24
%27 = call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* %11)
%28 = icmp eq i64 %18, %15
%29 = select i1 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0)
%30 = call i32 @strcat(i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0), i8* %29)
%31 = add nuw nsw i64 %18, 1
%32 = icmp eq i64 %31, %16
br i1 %32, label %33, label %17
33: ; preds = %17, %4
%34 = phi i32 [ %8, %4 ], [ %26, %17 ]
%35 = add nsw i32 %34, 1
store i32 %35, i32* %3
ret i8* getelementptr inbounds ([100 x i8], [100 x i8]* @format_string.ans, i64 0, i64 0)
}