#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*/ assert(int);
int /*<<< orphan*/ free(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ skiboot_snprintf(char *, int, int, char *, int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
scalar_t__ strncmp(char *, char *, int);
void test_printf_o(void) {
  char *buf = (char *)malloc(32);
  char buf2[32];
  skiboot_snprintf(buf, 32, 32, "%o", 0x12345678);
  snprintf(buf2, 32, "%o", 0x12345678);
  assert(0 == strncmp(buf, buf2, 32));
  free(buf);
}


x86 assembly (clang, -O0):
<test_printf_o>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    $0x20,%edx
lea    0xe7a(%rip),%rcx
mov    $0x12345678,%r8d
mov    %edx,%esi
call   1040 <skiboot_snprintf@plt>
lea    -0x30(%rbp),%rdi
mov    $0x20,%esi
lea    0xe5d(%rip),%rdx
mov    $0x12345678,%ecx
call   1060 <snprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x30(%rbp),%rsi
mov    $0x20,%edx
call   1050 <strncmp@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1070 <assert@plt>
mov    -0x8(%rbp),%rdi
call   1030 <free@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_printf_o>:
push   %r15
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    $0x20,%edi
call   1080 <malloc@plt>
mov    %rax,%rbx
lea    0xe83(%rip),%r14
mov    %rax,%rdi
mov    $0x20,%esi
mov    $0x20,%edx
mov    %r14,%rcx
mov    $0x12345678,%r8d
call   1040 <skiboot_snprintf@plt>
mov    %rsp,%r15
mov    %r15,%rdi
mov    $0x20,%esi
mov    %r14,%rdx
mov    $0x12345678,%ecx
call   1060 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x20,%edx
call   1050 <strncmp@plt>
xor    %edi,%edi
test   %rax,%rax
sete   %dil
call   1070 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%o\00"
define void @test_printf_o() {
%1 = alloca i8*
%2 = alloca [32 x i8]
%3 = call i64 @malloc(i32 32)
%4 = inttoptr i64 %3 to i8*
store i8* %4, i8** %1
%5 = load i8*, i8** %1
%6 = call i32 @skiboot_snprintf(i8* %5, i32 32, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 305419896)
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%8 = call i32 @snprintf(i8* %7, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 305419896)
%9 = load i8*, i8** %1
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%11 = call i64 @strncmp(i8* %9, i8* %10, i32 32)
%12 = icmp eq i64 0, %11
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = load i8*, i8** %1
%16 = call i32 @free(i8* %15)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%o\00"
define void @test_printf_o() {
%1 = alloca [32 x i8]
%2 = tail call i64 @malloc(i32 32)
%3 = inttoptr i64 %2 to i8*
%4 = getelementptr inbounds [32 x i8], [32 x i8]* %1, i64 0, i64 0
%5 = tail call i32 @skiboot_snprintf(i8* %3, i32 32, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 305419896)
%6 = call i32 @snprintf(i8* %4, i32 32, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 305419896)
%7 = call i64 @strncmp(i8* %3, i8* %4, i32 32)
%8 = icmp eq i64 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = call i32 @free(i8* %3)
ret void
}