#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 int /*<<< orphan*/ fmt;

/* Variables and functions */
int ENOTSUP;
int /*<<< orphan*/ snprintf(char *, size_t, char *, ...);
int xset_fill_buf(int base, int i, char *buf, size_t buf_len) {
  char fmt[16];
  switch (base) {
  case 8:
    snprintf(fmt, sizeof(fmt), "0%%o");
    break;
  case 10:
    snprintf(fmt, sizeof(fmt), "%%d");
    break;
  case 16:
    snprintf(fmt, sizeof(fmt), "0x%%x");
    break;
  default:
    return -ENOTSUP;
  }
  snprintf(buf, buf_len, fmt, i);
  return 0;
}


x86 assembly (clang, -O0):
<xset_fill_buf>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x34(%rbp)
sub    $0x8,%eax
je     115c <xset_fill_buf+0x4c>
jmp    113a <xset_fill_buf+0x2a>
mov    -0x34(%rbp),%eax
sub    $0xa,%eax
je     1178 <xset_fill_buf+0x68>
jmp    114b <xset_fill_buf+0x3b>
mov    -0x34(%rbp),%eax
sub    $0x10,%eax
je     1194 <xset_fill_buf+0x84>
jmp    11b0 <xset_fill_buf+0xa0>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
lea    0xe94(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11c3 <xset_fill_buf+0xb3>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
lea    0xe7d(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11c3 <xset_fill_buf+0xb3>
lea    -0x30(%rbp),%rdi
mov    $0x10,%esi
lea    0xe65(%rip),%rdx
mov    $0x0,%al
call   1030 <snprintf@plt>
jmp    11c3 <xset_fill_buf+0xb3>
xor    %eax,%eax
mov    0x2e2f(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    11e0 <xset_fill_buf+0xd0>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
lea    -0x30(%rbp),%rdx
mov    -0xc(%rbp),%ecx
mov    $0x0,%al
call   1030 <snprintf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xset_fill_buf>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rcx,%r14
mov    %rdx,%r12
mov    %esi,%r15d
cmp    $0x8,%edi
je     113d <xset_fill_buf+0x2d>
cmp    $0x10,%edi
je     1146 <xset_fill_buf+0x36>
cmp    $0xa,%edi
jne    1176 <xset_fill_buf+0x66>
lea    0xeca(%rip),%rdx
jmp    114d <xset_fill_buf+0x3d>
lea    0xebc(%rip),%rdx
jmp    114d <xset_fill_buf+0x3d>
lea    0xebc(%rip),%rdx
xor    %ebp,%ebp
mov    %rsp,%rbx
mov    $0x10,%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1030 <snprintf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1030 <snprintf@plt>
jmp    1181 <xset_fill_buf+0x71>
mov    0x2e6b(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"0%%o\00"
@.str.1 = [4 x i8] c"%%d\00"
@.str.2 = [6 x i8] c"0x%%x\00"
@ENOTSUP = global i32 0
define i32 @xset_fill_buf(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 [16 x i8]
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i64 %3, i64* %9
%11 = load i32, i32* %6
switch i32 %11, label %21 [
i32 8, label %12
i32 10, label %15
i32 16, label %18
]
12: ; preds = %4
%13 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%14 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %13, i64 16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %24
15: ; preds = %4
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%17 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %16, i64 16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %24
18: ; preds = %4
%19 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%20 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %19, i64 16, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
br label %24
21: ; preds = %4
%22 = load i32, i32* @ENOTSUP
%23 = sub nsw i32 0, %22
store i32 %23, i32* %5
br label %30
24: ; preds = %18, %15, %12
%25 = load i8*, i8** %8
%26 = load i64, i64* %9
%27 = getelementptr inbounds [16 x i8], [16 x i8]* %10, i64 0, i64 0
%28 = load i32, i32* %7
%29 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %25, i64 %26, i8* %27, i32 %28)
store i32 0, i32* %5
br label %30
30: ; preds = %24, %21
%31 = load i32, i32* %5
ret i32 %31
}

LLVM IR (-O2):
@.str = [5 x i8] c"0%%o\00"
@.str.1 = [4 x i8] c"%%d\00"
@.str.2 = [6 x i8] c"0x%%x\00"
@ENOTSUP = global i32 0
define i32 @xset_fill_buf(i32 %0, i32 %1, i8* nocapture writeonly %2, i64 %3) {
%5 = alloca [16 x i8]
%6 = getelementptr inbounds [16 x i8], [16 x i8]* %5, i64 0, i64 0
switch i32 %0, label %9 [
i32 8, label %12
i32 10, label %7
i32 16, label %8
]
7: ; preds = %4
br label %12
8: ; preds = %4
br label %12
9: ; preds = %4
%10 = load i32, i32* @ENOTSUP
%11 = sub nsw i32 0, %10
br label %16
12: ; preds = %4, %8, %7
%13 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), %8 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %7 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), %4 ]
%14 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %6, i64 16, i8* %13)
%15 = call i32 (i8*, i64, i8*, ...) @snprintf(i8* %2, i64 %3, i8* %6, i32 %1)
br label %16
16: ; preds = %12, %9
%17 = phi i32 [ %11, %9 ], [ 0, %12 ]
ret i32 %17
}