#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*/ sprintf(char *, char *, char, unsigned int);
void set_bg_digits(unsigned int len, unsigned int *digits,
                   const unsigned int *mods, char sep, char *buf) {
  unsigned int i;
  for (i = 0; i < len; ++i) {
    unsigned int base = (i == (len - 1)) ? 1000 : 0;
    buf += sprintf(buf, "%c%d", sep, base + (digits[i] % mods[i]));
  }
}


x86 assembly (clang, -O0):
<set_bg_digits>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %cl,%al
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %al,-0x19(%rbp)
mov    %r8,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x4(%rbp),%eax
jae    11b0 <set_bg_digits+0xa0>
mov    -0x2c(%rbp),%edx
mov    -0x4(%rbp),%esi
sub    $0x1,%esi
xor    %eax,%eax
mov    $0x3e8,%ecx
cmp    %esi,%edx
cmove  %ecx,%eax
mov    %eax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x19(%rbp),%al
mov    %al,-0x31(%rbp)
mov    -0x30(%rbp),%ecx
mov    -0x10(%rbp),%rax
mov    -0x2c(%rbp),%edx
mov    (%rax,%rdx,4),%eax
mov    -0x18(%rbp),%rsi
mov    -0x2c(%rbp),%edx
mov    %edx,%r8d
xor    %edx,%edx
divl   (%rsi,%r8,4)
mov    -0x31(%rbp),%al
add    %edx,%ecx
lea    0xe76(%rip),%rsi
movsbl %al,%edx
call   1030 <sprintf@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1133 <set_bg_digits+0x23>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_bg_digits>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %edi,%edi
je     1179 <set_bg_digits+0x69>
mov    %r8,%rbx
mov    %rdx,%rbp
mov    %rsi,%r13
lea    -0x1(%rdi),%eax
mov    %rax,(%rsp)
mov    %edi,%r12d
xor    %r14d,%r14d
movsbl %cl,%r15d
nopl   0x0(%rax)
mov    0x0(%r13,%r14,4),%eax
xor    %edx,%edx
divl   0x0(%rbp,%r14,4)
lea    0x3e8(%rdx),%ecx
cmp    %r14,(%rsp)
cmovne %edx,%ecx
mov    %rbx,%rdi
lea    0xe9d(%rip),%rsi
mov    %r15d,%edx
call   1030 <sprintf@plt>
cltq
add    %rax,%rbx
add    $0x1,%r14
cmp    %r14,%r12
jne    1140 <set_bg_digits+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%c%d\00"
define void @set_bg_digits(i32 %0, i32* %1, i32* %2, i8 signext %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i32*
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
store i32 %0, i32* %6
store i32* %1, i32** %7
store i32* %2, i32** %8
store i8 %3, i8* %9
store i8* %4, i8** %10
store i32 0, i32* %11
br label %13
13: ; preds = %43, %5
%14 = load i32, i32* %11
%15 = load i32, i32* %6
%16 = icmp ult i32 %14, %15
br i1 %16, label %17, label %46
17: ; preds = %13
%18 = load i32, i32* %11
%19 = load i32, i32* %6
%20 = sub i32 %19, 1
%21 = icmp eq i32 %18, %20
%22 = zext i1 %21 to i64
%23 = select i1 %21, i32 1000, i32 0
store i32 %23, i32* %12
%24 = load i8*, i8** %10
%25 = load i8, i8* %9
%26 = load i32, i32* %12
%27 = load i32*, i32** %7
%28 = load i32, i32* %11
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i32, i32* %27, i64 %29
%31 = load i32, i32* %30
%32 = load i32*, i32** %8
%33 = load i32, i32* %11
%34 = zext i32 %33 to i64
%35 = getelementptr inbounds i32, i32* %32, i64 %34
%36 = load i32, i32* %35
%37 = urem i32 %31, %36
%38 = add i32 %26, %37
%39 = call i32 @sprintf(i8* %24, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8 signext %25, i32 %38)
%40 = load i8*, i8** %10
%41 = sext i32 %39 to i64
%42 = getelementptr inbounds i8, i8* %40, i64 %41
store i8* %42, i8** %10
br label %43
43: ; preds = %17
%44 = load i32, i32* %11
%45 = add i32 %44, 1
store i32 %45, i32* %11
br label %13
46: ; preds = %13
ret void
}

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