#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 sprintf(char *, char *, char *);
int output_unuseds(char *destination, int number_to_output, int first_time) {
  int total_bytes_outputted = 0;
  int bytes_outputted;
  while (number_to_output--) {
    if (first_time) {
      bytes_outputted = sprintf(destination, "%s", "unused");
      first_time = 0;
    } else {
      bytes_outputted = sprintf(destination, ",%s", "unused");
    }
    destination += bytes_outputted;
    total_bytes_outputted += bytes_outputted;
  }
  return total_bytes_outputted;
}


x86 assembly (clang, -O0):
<output_unuseds>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0xc(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0xc(%rbp)
cmp    $0x0,%eax
je     11a6 <output_unuseds+0x96>
cmpl   $0x0,-0x10(%rbp)
je     116d <output_unuseds+0x5d>
mov    -0x8(%rbp),%rdi
lea    0xeb6(%rip),%rsi
lea    0xea7(%rip),%rdx
call   1030 <sprintf@plt>
mov    %eax,-0x18(%rbp)
movl   $0x0,-0x10(%rbp)
jmp    1187 <output_unuseds+0x77>
mov    -0x8(%rbp),%rdi
lea    0xe8f(%rip),%rsi
lea    0xe81(%rip),%rdx
call   1030 <sprintf@plt>
mov    %eax,-0x18(%rbp)
mov    -0x18(%rbp),%ecx
mov    -0x8(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x18(%rbp),%eax
add    -0x14(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    1129 <output_unuseds+0x19>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<output_unuseds>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
test   %esi,%esi
je     1143 <output_unuseds+0x33>
mov    %esi,%r14d
mov    %rdi,%rbx
add    $0xffffffff,%r14d
test   %edx,%edx
je     1147 <output_unuseds+0x37>
movl   $0x646573,0x3(%rbx)
movl   $0x73756e75,(%rbx)
mov    $0x6,%ebp
test   %r14d,%r14d
jne    1164 <output_unuseds+0x54>
jmp    119b <output_unuseds+0x8b>
xor    %ebp,%ebp
jmp    119b <output_unuseds+0x8b>
lea    0xeb9(%rip),%rsi
lea    0xeab(%rip),%rdx
mov    %rbx,%rdi
call   1030 <sprintf@plt>
mov    %eax,%ebp
test   %r14d,%r14d
je     119b <output_unuseds+0x8b>
movslq %ebp,%rax
add    %rax,%rbx
lea    0xe96(%rip),%r15
lea    0xe88(%rip),%r12
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    %r12,%rdx
call   1030 <sprintf@plt>
cltq
add    %rax,%rbx
add    %eax,%ebp
add    $0xffffffff,%r14d
jne    1180 <output_unuseds+0x70>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [7 x i8] c"unused\00"
@.str.2 = [4 x i8] c",%s\00"
define i32 @output_unuseds(i8* %0, i32 %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %9
9: ; preds = %22, %3
%10 = load i32, i32* %5
%11 = add nsw i32 %10, -1
store i32 %11, i32* %5
%12 = icmp ne i32 %10, 0
br i1 %12, label %13, label %30
13: ; preds = %9
%14 = load i32, i32* %6
%15 = icmp ne i32 %14, 0
br i1 %15, label %16, label %19
16: ; preds = %13
%17 = load i8*, i8** %4
%18 = call i32 @sprintf(i8* %17, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %18, i32* %8
store i32 0, i32* %6
br label %22
19: ; preds = %13
%20 = load i8*, i8** %4
%21 = call i32 @sprintf(i8* %20, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
store i32 %21, i32* %8
br label %22
22: ; preds = %19, %16
%23 = load i32, i32* %8
%24 = load i8*, i8** %4
%25 = sext i32 %23 to i64
%26 = getelementptr inbounds i8, i8* %24, i64 %25
store i8* %26, i8** %4
%27 = load i32, i32* %8
%28 = load i32, i32* %7
%29 = add nsw i32 %28, %27
store i32 %29, i32* %7
br label %9
30: ; preds = %9
%31 = load i32, i32* %7
ret i32 %31
}

LLVM IR (-O2):
@.str.1 = [7 x i8] c"unused\00"
@.str.2 = [4 x i8] c",%s\00"
define i32 @output_unuseds(i8* nocapture writeonly %0, i32 %1, i32 %2) {
%4 = icmp eq i32 %1, 0
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = add nsw i32 %1, -1
%7 = icmp eq i32 %2, 0
br i1 %7, label %9, label %8
8: ; preds = %5
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(7) %0, i8* align 1 dereferenceable(7) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i64 7, i1 false)
br label %11
9: ; preds = %5
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %9, %8
%12 = phi i32 [ 6, %8 ], [ %10, %9 ]
%13 = icmp eq i32 %6, 0
br i1 %13, label %27, label %14
14: ; preds = %11
%15 = sext i32 %12 to i64
%16 = getelementptr inbounds i8, i8* %0, i64 %15
br label %17
17: ; preds = %14, %17
%18 = phi i32 [ %21, %17 ], [ %6, %14 ]
%19 = phi i32 [ %25, %17 ], [ %12, %14 ]
%20 = phi i8* [ %24, %17 ], [ %16, %14 ]
%21 = add nsw i32 %18, -1
%22 = tail call i32 @sprintf(i8* dereferenceable(1) %20, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %20, i64 %23
%25 = add nsw i32 %22, %19
%26 = icmp eq i32 %21, 0
br i1 %26, label %27, label %17
27: ; preds = %17, %11, %3
%28 = phi i32 [ 0, %3 ], [ %12, %11 ], [ %25, %17 ]
ret i32 %28
}