#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 */
typedef scalar_t__ uint8_t;
typedef int uint32_t;
typedef int int8_t;
typedef int /*<<< orphan*/ buffer;

/* Variables and functions */
scalar_t__ FORMAT_cat_uint32(char *, int, int);
int /*<<< orphan*/ memset(char *, char, int);
int /*<<< orphan*/ printf(char *, int, int, char *, scalar_t__, char *,
                          scalar_t__);
scalar_t__ strcmp(char *, char *);
int test(uint32_t n, int8_t chars, char *expected, uint8_t steps) {
  char buffer[128];
  uint8_t actual_steps;
  memset(buffer, 'A', sizeof(buffer));
  buffer[0] = 0;
  actual_steps = FORMAT_cat_uint32(buffer, n, chars);
  if (strcmp(buffer, expected) || (actual_steps != steps)) {
    printf("FAIL: n=%u, chars=%d, expected='%s'/%u, got='%s'/%u\n", n, chars,
           expected, steps, buffer, actual_steps);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<test>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
lea    -0xa0(%rbp),%rdi
mov    $0x41,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
movb   $0x0,-0xa0(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
call   1030 <FORMAT_cat_uint32@plt>
mov    %rax,-0xa8(%rbp)
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11ba <test+0x7a>
mov    -0xa8(%rbp),%rax
cmp    -0x20(%rbp),%rax
je     11f2 <test+0xb2>
mov    -0x8(%rbp),%esi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    -0x20(%rbp),%r8
lea    -0xa0(%rbp),%r9
mov    -0xa8(%rbp),%rax
lea    0xe23(%rip),%rdi
mov    %rax,(%rsp)
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    11f9 <test+0xb9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    %rcx,%r14
mov    %rdx,%r15
mov    %esi,%r12d
mov    %edi,%r13d
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x41,%esi
mov    $0x80,%edx
call   1050 <memset@plt>
movb   $0x0,0x10(%rsp)
mov    %rbx,%rdi
mov    %r13d,%esi
mov    %r12d,%edx
call   1030 <FORMAT_cat_uint32@plt>
mov    %rax,%rbp
mov    %rbx,%rdi
mov    %r15,%rsi
call   1060 <strcmp@plt>
test   %rax,%rax
jne    11a1 <test+0x61>
xor    %eax,%eax
cmp    %r14,%rbp
je     11c7 <test+0x87>
mov    %rbp,(%rsp)
lea    0xe54(%rip),%rdi
lea    0x10(%rsp),%r9
mov    %r13d,%esi
mov    %r12d,%edx
mov    %r15,%rcx
mov    %r14,%r8
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [53 x i8] c"FAIL: n=%u, chars=%d, expected='%s'/%u, got='%s'/%u\0A\00"
define i32 @test(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca [128 x i8]
%11 = alloca i64
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i8 signext 65, i32 128)
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
store i8 0, i8* %14
%15 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%16 = load i32, i32* %6
%17 = load i32, i32* %7
%18 = call i64 @FORMAT_cat_uint32(i8* %15, i32 %16, i32 %17)
store i64 %18, i64* %11
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%20 = load i8*, i8** %8
%21 = call i64 @strcmp(i8* %19, i8* %20)
%22 = icmp ne i64 %21, 0
br i1 %22, label %27, label %23
23: ; preds = %4
%24 = load i64, i64* %11
%25 = load i64, i64* %9
%26 = icmp ne i64 %24, %25
br i1 %26, label %27, label %35
27: ; preds = %23, %4
%28 = load i32, i32* %6
%29 = load i32, i32* %7
%30 = load i8*, i8** %8
%31 = load i64, i64* %9
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%33 = load i64, i64* %11
%34 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %28, i32 %29, i8* %30, i64 %31, i8* %32, i64 %33)
store i32 1, i32* %5
br label %36
35: ; preds = %23
store i32 0, i32* %5
br label %36
36: ; preds = %35, %27
%37 = load i32, i32* %5
ret i32 %37
}

LLVM IR (-O2):
@.str = [53 x i8] c"FAIL: n=%u, chars=%d, expected='%s'/%u, got='%s'/%u\0A\00"
define i32 @test(i32 %0, i32 %1, i8* %2, i64 %3) {
%5 = alloca [128 x i8]
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%7 = call i32 @memset(i8* %6, i8 signext 65, i32 128)
store i8 0, i8* %6
%8 = call i64 @FORMAT_cat_uint32(i8* %6, i32 %0, i32 %1)
%9 = call i64 @strcmp(i8* %6, i8* %2)
%10 = icmp eq i64 %9, 0
%11 = icmp eq i64 %8, %3
%12 = select i1 %10, i1 %11, i1 false
br i1 %12, label %15, label %13
13: ; preds = %4
%14 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str, i64 0, i64 0), i32 %0, i32 %1, i8* %2, i64 %3, i8* %6, i64 %8)
br label %15
15: ; preds = %4, %13
%16 = phi i32 [ 1, %13 ], [ 0, %4 ]
ret i32 %16
}