#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 */
size_t snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char *,
                unsigned char const);
size_t get_max_width(const unsigned char *p, const size_t N) {
  size_t max_width = 0;
  for (size_t i = 0; i < N; ++i) {
    const size_t width = snprintf(NULL, 0, "%d", p[i]);
    if (width > max_width) {
      max_width = width;
    }
  }
  return max_width;
}


x86 assembly (clang, -O0):
<get_max_width>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    118c <get_max_width+0x7c>
mov    -0x8(%rbp),%rax
mov    -0x20(%rbp),%rcx
xor    %edx,%edx
mov    %edx,%edi
xor    %esi,%esi
lea    0xead(%rip),%rdx
movzbl (%rax,%rcx,1),%ecx
call   1030 <snprintf@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jbe    1176 <get_max_width+0x66>
mov    -0x28(%rbp),%rax
mov    %rax,-0x18(%rbp)
jmp    117b <get_max_width+0x6b>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1130 <get_max_width+0x20>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_max_width>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rsi,%rsi
je     1153 <get_max_width+0x43>
mov    %rsi,%r14
mov    %rdi,%r15
xor    %r13d,%r13d
lea    0xed2(%rip),%r12
xor    %ebx,%ebx
movzbl (%r15,%rbx,1),%ecx
xor    %edi,%edi
xor    %esi,%esi
mov    %r12,%rdx
call   1030 <snprintf@plt>
cmp    %r13,%rax
cmova  %rax,%r13
add    $0x1,%rbx
cmp    %rbx,%r14
jne    1130 <get_max_width+0x20>
jmp    1156 <get_max_width+0x46>
xor    %r13d,%r13d
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

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