#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*/ free(char *);
int /*<<< orphan*/ id3_text_field(char *, size_t *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, ...);
unsigned int uintlen(int);
void id3_track_numbering(char *frame, size_t *offset, int track,
                         int track_count) {
  unsigned tr_len = uintlen(track + 1);
  unsigned tr_count_len = uintlen(track);
  if (track + 1 < 10)
    tr_len++;
  if (track_count < 10)
    tr_count_len++;
  char *tr_str = (char *)malloc(sizeof(char) * tr_len + 2);
  if (track + 1 < 10)
    sprintf(tr_str, "0%u", track + 1);
  else
    sprintf(tr_str, "%u", track + 1);
  char *tr_count_str = (char *)malloc(sizeof(char) * tr_count_len + 2);
  if (track_count < 10)
    sprintf(tr_count_str, "0%u", track_count);
  else
    sprintf(tr_count_str, "%u", track_count);
  char *numbering = (char *)malloc(sizeof(char) * tr_len + tr_count_len + 3);
  sprintf(numbering, "%s/%s", tr_str, tr_count_str);
  id3_text_field(frame, offset, numbering);
  free(tr_str);
  free(tr_count_str);
  free(numbering);
}


x86 assembly (clang, -O0):
<id3_track_numbering>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1030 <uintlen@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x14(%rbp),%edi
call   1030 <uintlen@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    $0xa,%eax
jge    1197 <id3_track_numbering+0x47>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    11aa <id3_track_numbering+0x5a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
shl    $0x0,%rax
add    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x14(%rbp),%eax
add    $0x1,%eax
cmp    $0xa,%eax
jge    11ec <id3_track_numbering+0x9c>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe20(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1204 <id3_track_numbering+0xb4>
mov    -0x28(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    $0x1,%edx
lea    0xe04(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x20(%rbp),%eax
shl    $0x0,%rax
add    $0x2,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    123e <id3_track_numbering+0xee>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdce(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
jmp    1253 <id3_track_numbering+0x103>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%edx
lea    0xdb5(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x1c(%rbp),%eax
shl    $0x0,%rax
mov    -0x20(%rbp),%ecx
add    %rcx,%rax
add    $0x3,%rax
mov    %eax,%edi
call   1060 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
lea    0xd82(%rip),%rsi
mov    $0x0,%al
call   1070 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x38(%rbp),%rdx
call   1050 <id3_text_field@plt>
mov    -0x28(%rbp),%rdi
call   1040 <free@plt>
mov    -0x30(%rbp),%rdi
call   1040 <free@plt>
mov    -0x38(%rbp),%rdi
call   1040 <free@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<id3_track_numbering>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %ecx,%ebp
mov    %ecx,0xc(%rsp)
mov    %edx,%ebx
mov    %rsi,0x20(%rsp)
mov    %rdi,0x18(%rsp)
lea    0x1(%rbx),%r13d
mov    %r13d,%edi
call   1030 <uintlen@plt>
mov    %eax,%r12d
mov    %ebx,%edi
call   1030 <uintlen@plt>
xor    %ecx,%ecx
cmp    $0xa,%ebp
setl   %cl
lea    0xe6b(%rip),%rdx
lea    0xe65(%rip),%rbp
mov    %rbp,%r14
cmovl  %rdx,%r14
xor    %esi,%esi
cmp    $0x9,%ebx
setl   %sil
lea    0x2(%r12,%rsi,1),%edi
cmovl  %rdx,%rbp
add    %esi,%r12d
lea    (%rax,%rcx,1),%edx
mov    %rdx,0x10(%rsp)
lea    (%rax,%rcx,1),%ebx
add    $0x2,%ebx
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    %rbp,%rsi
mov    %r13d,%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    %ebx,%edi
call   1060 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    %r14,%rsi
mov    0xc(%rsp),%edx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    0x10(%rsp),%rax
lea    (%r12,%rax,1),%edi
add    $0x3,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
lea    0xdf0(%rip),%rsi
mov    %rax,%rdi
mov    %r15,%rdx
mov    %rbp,%rcx
xor    %eax,%eax
call   1070 <sprintf@plt>
mov    0x18(%rsp),%rdi
mov    0x20(%rsp),%rsi
mov    %rbx,%rdx
call   1050 <id3_text_field@plt>
mov    %r15,%rdi
call   1040 <free@plt>
mov    %rbp,%rdi
call   1040 <free@plt>
mov    %rbx,%rdi
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <free@plt>

LLVM IR (-O0):
@.str = [4 x i8] c"0%u\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define void @id3_track_numbering(i8* %0, i64* %1, i32 %2, i32 %3) {
%5 = alloca i8*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
store i8* %0, i8** %5
store i64* %1, i64** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
%14 = load i32, i32* %7
%15 = add nsw i32 %14, 1
%16 = call i32 @uintlen(i32 %15)
store i32 %16, i32* %9
%17 = load i32, i32* %7
%18 = call i32 @uintlen(i32 %17)
store i32 %18, i32* %10
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
%21 = icmp slt i32 %20, 10
br i1 %21, label %22, label %25
22: ; preds = %4
%23 = load i32, i32* %9
%24 = add i32 %23, 1
store i32 %24, i32* %9
br label %25
25: ; preds = %22, %4
%26 = load i32, i32* %8
%27 = icmp slt i32 %26, 10
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* %10
%30 = add i32 %29, 1
store i32 %30, i32* %10
br label %31
31: ; preds = %28, %25
%32 = load i32, i32* %9
%33 = zext i32 %32 to i64
%34 = mul i64 1, %33
%35 = add i64 %34, 2
%36 = trunc i64 %35 to i32
%37 = call i64 @malloc(i32 %36)
%38 = inttoptr i64 %37 to i8*
store i8* %38, i8** %11
%39 = load i32, i32* %7
%40 = add nsw i32 %39, 1
%41 = icmp slt i32 %40, 10
br i1 %41, label %42, label %47
42: ; preds = %31
%43 = load i8*, i8** %11
%44 = load i32, i32* %7
%45 = add nsw i32 %44, 1
%46 = call i32 (i8*, i8*, ...) @sprintf(i8* %43, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %45)
br label %52
47: ; preds = %31
%48 = load i8*, i8** %11
%49 = load i32, i32* %7
%50 = add nsw i32 %49, 1
%51 = call i32 (i8*, i8*, ...) @sprintf(i8* %48, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %50)
br label %52
52: ; preds = %47, %42
%53 = load i32, i32* %10
%54 = zext i32 %53 to i64
%55 = mul i64 1, %54
%56 = add i64 %55, 2
%57 = trunc i64 %56 to i32
%58 = call i64 @malloc(i32 %57)
%59 = inttoptr i64 %58 to i8*
store i8* %59, i8** %12
%60 = load i32, i32* %8
%61 = icmp slt i32 %60, 10
br i1 %61, label %62, label %66
62: ; preds = %52
%63 = load i8*, i8** %12
%64 = load i32, i32* %8
%65 = call i32 (i8*, i8*, ...) @sprintf(i8* %63, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %64)
br label %70
66: ; preds = %52
%67 = load i8*, i8** %12
%68 = load i32, i32* %8
%69 = call i32 (i8*, i8*, ...) @sprintf(i8* %67, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %68)
br label %70
70: ; preds = %66, %62
%71 = load i32, i32* %9
%72 = zext i32 %71 to i64
%73 = mul i64 1, %72
%74 = load i32, i32* %10
%75 = zext i32 %74 to i64
%76 = add i64 %73, %75
%77 = add i64 %76, 3
%78 = trunc i64 %77 to i32
%79 = call i64 @malloc(i32 %78)
%80 = inttoptr i64 %79 to i8*
store i8* %80, i8** %13
%81 = load i8*, i8** %13
%82 = load i8*, i8** %11
%83 = load i8*, i8** %12
%84 = call i32 (i8*, i8*, ...) @sprintf(i8* %81, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %82, i8* %83)
%85 = load i8*, i8** %5
%86 = load i64*, i64** %6
%87 = load i8*, i8** %13
%88 = call i32 @id3_text_field(i8* %85, i64* %86, i8* %87)
%89 = load i8*, i8** %11
%90 = call i32 @free(i8* %89)
%91 = load i8*, i8** %12
%92 = call i32 @free(i8* %91)
%93 = load i8*, i8** %13
%94 = call i32 @free(i8* %93)
ret void
}

LLVM IR (-O2):
@.str = [4 x i8] c"0%u\00"
@.str.1 = [3 x i8] c"%u\00"
@.str.2 = [6 x i8] c"%s/%s\00"
define void @id3_track_numbering(i8* %0, i64* %1, i32 %2, i32 %3) {
%5 = add nsw i32 %2, 1
%6 = tail call i32 @uintlen(i32 %5)
%7 = tail call i32 @uintlen(i32 %2)
%8 = icmp slt i32 %2, 9
%9 = zext i1 %8 to i32
%10 = add i32 %6, %9
%11 = icmp slt i32 %3, 10
%12 = zext i1 %11 to i32
%13 = add i32 %7, %12
%14 = add i32 %10, 2
%15 = tail call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
%17 = select i1 %8, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%18 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %16, i8* dereferenceable(1) %17, i32 %5)
%19 = add i32 %13, 2
%20 = tail call i64 @malloc(i32 %19)
%21 = inttoptr i64 %20 to i8*
%22 = select i1 %11, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%23 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %21, i8* dereferenceable(1) %22, i32 %3)
%24 = add i32 %10, 3
%25 = add i32 %24, %13
%26 = tail call i64 @malloc(i32 %25)
%27 = inttoptr i64 %26 to i8*
%28 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %27, i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i8* %16, i8* %21)
%29 = tail call i32 @id3_text_field(i8* %0, i64* %1, i8* %27)
%30 = tail call i32 @free(i8* %16)
%31 = tail call i32 @free(i8* %21)
%32 = tail call i32 @free(i8* %27)
ret void
}