#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 snprintf(char *, int, char *, int);
char *m_strn(int value, unsigned int width) {
  static char buffer[(sizeof "-INT_MAX")];
  const int num_chars = snprintf(buffer, sizeof buffer, "%d", value);
  return num_chars > 0 && (width == 0 || (unsigned int)num_chars <= width)
             ? buffer
             : "?";
}


x86 assembly (clang, -O0):
<m_strn>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    -0x4(%rbp),%ecx
lea    0x2f01(%rip),%rdi
mov    $0x9,%esi
lea    0xecc(%rip),%rdx
call   1030 <snprintf@plt>
mov    %eax,-0xc(%rbp)
xor    %eax,%eax
cmpl   $0x0,-0xc(%rbp)
mov    %al,-0xd(%rbp)
jle    116c <m_strn+0x5c>
mov    $0x1,%al
cmpl   $0x0,-0x8(%rbp)
mov    %al,-0xe(%rbp)
je     1166 <m_strn+0x56>
mov    -0xc(%rbp),%eax
cmp    -0x8(%rbp),%eax
setbe  %al
mov    %al,-0xe(%rbp)
mov    -0xe(%rbp),%al
mov    %al,-0xd(%rbp)
mov    -0xd(%rbp),%dl
lea    0xe8d(%rip),%rax
lea    0x2eac(%rip),%rcx
test   $0x1,%dl
cmovne %rcx,%rax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<m_strn>:
push   %r14
push   %rbx
push   %rax
mov    %esi,%ebx
mov    %edi,%ecx
lea    0x2f0a(%rip),%r14
lea    0xeda(%rip),%rdx
mov    %r14,%rdi
mov    $0x9,%esi
call   1030 <snprintf@plt>
cmp    %ebx,%eax
lea    0xec7(%rip),%rdx
mov    %rdx,%rcx
cmovbe %r14,%rcx
test   %ebx,%ebx
cmove  %r14,%rcx
test   %eax,%eax
cmovle %rdx,%rcx
mov    %rcx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@m_strn.buffer = internal global [9 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"?\00"
define i8* @m_strn(i32 %0, i32 %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
store i32 %0, i32* %3
store i32 %1, i32* %4
%6 = load i32, i32* %3
%7 = call i32 @snprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @m_strn.buffer, i64 0, i64 0), i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %5
%8 = load i32, i32* %5
%9 = icmp sgt i32 %8, 0
br i1 %9, label %10, label %19
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 0
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = load i32, i32* %5
%15 = load i32, i32* %4
%16 = icmp ule i32 %14, %15
br label %17
17: ; preds = %13, %10
%18 = phi i1 [ true, %10 ], [ %16, %13 ]
br label %19
19: ; preds = %17, %2
%20 = phi i1 [ false, %2 ], [ %18, %17 ]
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @m_strn.buffer, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
ret i8* %22
}

LLVM IR (-O2):
@m_strn.buffer = internal global [9 x i8] zeroinitializer
@.str = [3 x i8] c"%d\00"
@.str.1 = [2 x i8] c"?\00"
define i8* @m_strn(i32 %0, i32 %1) {
%3 = tail call i32 @snprintf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @m_strn.buffer, i64 0, i64 0), i32 9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %0)
%4 = icmp sgt i32 %3, 0
%5 = icmp eq i32 %1, 0
%6 = icmp ule i32 %3, %1
%7 = select i1 %5, i1 true, i1 %6
%8 = and i1 %4, %7
%9 = select i1 %8, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @m_strn.buffer, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0)
ret i8* %9
}