#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*/ snprintf(char *, size_t, char *, char *, int);
void fill_buffers(char **buffers, int num_bufs, size_t size, char *str) {
  for (int index = 0; index < num_bufs; ++index) {
    snprintf(buffers[index], size, "%s: %d", str, index);
  }
}


x86 assembly (clang, -O0):
<fill_buffers>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    116c <fill_buffers+0x5c>
mov    -0x8(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rcx
mov    -0x24(%rbp),%r8d
lea    0xea7(%rip),%rdx
call   1030 <snprintf@plt>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    112e <fill_buffers+0x1e>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fill_buffers>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %esi,%esi
jle    115e <fill_buffers+0x4e>
mov    %rcx,%r14
mov    %rdx,%r15
mov    %rdi,%r12
mov    %esi,%ebp
xor    %ebx,%ebx
lea    0xecd(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    (%r12,%rbx,8),%rdi
mov    %r15,%rsi
mov    %r13,%rdx
mov    %r14,%rcx
mov    %ebx,%r8d
call   1030 <snprintf@plt>
add    $0x1,%rbx
cmp    %rbx,%rbp
jne    1140 <fill_buffers+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [7 x i8] c"%s: %d\00"
define void @fill_buffers(i8** nocapture %0, i32 %1, i64 %2, i8* %3) {
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %4
%7 = zext i32 %1 to i64
br label %9
8: ; preds = %9, %4
ret void
9: ; preds = %6, %9
%10 = phi i64 [ 0, %6 ], [ %15, %9 ]
%11 = getelementptr inbounds i8*, i8** %0, i64 %10
%12 = load i8*, i8** %11
%13 = trunc i64 %10 to i32
%14 = tail call i32 @snprintf(i8* %12, i64 %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8* %3, i32 %13)
%15 = add nuw nsw i64 %10, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %8, label %9
}