#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*/ sprintf(char *, char *, int, ...);
void tostr(int *s, int numElems, char *outstr) {
  switch (numElems) {
  case 1:
    sprintf(outstr, "{0x%08X}", s[0]);
    break;
  case 2:
    sprintf(outstr, "{0x%08X,0x%08X}", s[0], s[1]);
    break;
  case 3:
    sprintf(outstr, "{0x%08X,0x%08X,0x%08X}", s[0], s[1], s[2]);
    break;
  case 4:
    sprintf(outstr, "{0x%08X,0x%08X,0x%08X,0x%08X}", s[0], s[1], s[2], s[3]);
    break;
  }
}


x86 assembly (clang, -O0):
<tostr>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x20(%rbp)
sub    $0x3,%eax
ja     11e8 <tostr+0xd8>
mov    -0x20(%rbp),%rax
lea    0xebd(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
lea    0xeb3(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11e8 <tostr+0xd8>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
lea    0xe98(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11e8 <tostr+0xd8>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%r8d
lea    0xe7c(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
jmp    11e8 <tostr+0xd8>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rax
mov    (%rax),%edx
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%r8d
mov    -0x8(%rbp),%rax
mov    0xc(%rax),%r9d
lea    0xe5f(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tostr>:
add    $0xffffffff,%esi
cmp    $0x3,%esi
ja     113d <tostr+0x2d>
lea    0xee1(%rip),%rax
movslq (%rax,%rsi,4),%rcx
add    %rax,%rcx
jmp    *%rcx
mov    (%rdi),%eax
lea    0xedf(%rip),%rsi
mov    %rdx,%rdi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
ret
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
lea    0xecf(%rip),%rsi
mov    %rdx,%rdi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
mov    0x8(%rdi),%r8d
lea    0xec3(%rip),%rsi
mov    %rdx,%rdi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>
mov    (%rdi),%eax
mov    0x4(%rdi),%ecx
mov    0x8(%rdi),%r8d
mov    0xc(%rdi),%r9d
lea    0xeba(%rip),%rsi
mov    %rdx,%rdi
mov    %eax,%edx
xor    %eax,%eax
jmp    1030 <sprintf@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"{0x%08X}\00"
@.str.1 = [16 x i8] c"{0x%08X,0x%08X}\00"
@.str.2 = [23 x i8] c"{0x%08X,0x%08X,0x%08X}\00"
@.str.3 = [30 x i8] c"{0x%08X,0x%08X,0x%08X,0x%08X}\00"
define void @tostr(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%7 = load i32, i32* %5
switch i32 %7, label %50 [
i32 1, label %8
i32 2, label %14
i32 3, label %23
i32 4, label %35
]
8: ; preds = %3
%9 = load i8*, i8** %6
%10 = load i32*, i32** %4
%11 = getelementptr inbounds i32, i32* %10, i64 0
%12 = load i32, i32* %11
%13 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %9, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
br label %50
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = load i32*, i32** %4
%17 = getelementptr inbounds i32, i32* %16, i64 0
%18 = load i32, i32* %17
%19 = load i32*, i32** %4
%20 = getelementptr inbounds i32, i32* %19, i64 1
%21 = load i32, i32* %20
%22 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %15, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %18, i32 %21)
br label %50
23: ; preds = %3
%24 = load i8*, i8** %6
%25 = load i32*, i32** %4
%26 = getelementptr inbounds i32, i32* %25, i64 0
%27 = load i32, i32* %26
%28 = load i32*, i32** %4
%29 = getelementptr inbounds i32, i32* %28, i64 1
%30 = load i32, i32* %29
%31 = load i32*, i32** %4
%32 = getelementptr inbounds i32, i32* %31, i64 2
%33 = load i32, i32* %32
%34 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %24, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32 %30, i32 %33)
br label %50
35: ; preds = %3
%36 = load i8*, i8** %6
%37 = load i32*, i32** %4
%38 = getelementptr inbounds i32, i32* %37, i64 0
%39 = load i32, i32* %38
%40 = load i32*, i32** %4
%41 = getelementptr inbounds i32, i32* %40, i64 1
%42 = load i32, i32* %41
%43 = load i32*, i32** %4
%44 = getelementptr inbounds i32, i32* %43, i64 2
%45 = load i32, i32* %44
%46 = load i32*, i32** %4
%47 = getelementptr inbounds i32, i32* %46, i64 3
%48 = load i32, i32* %47
%49 = call i32 (i8*, i8*, i32, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %39, i32 %42, i32 %45, i32 %48)
br label %50
50: ; preds = %3, %35, %23, %14, %8
ret void
}

LLVM IR (-O2):
@.str = [9 x i8] c"{0x%08X}\00"
@.str.1 = [16 x i8] c"{0x%08X,0x%08X}\00"
@.str.2 = [23 x i8] c"{0x%08X,0x%08X,0x%08X}\00"
@.str.3 = [30 x i8] c"{0x%08X,0x%08X,0x%08X,0x%08X}\00"
define void @tostr(i32* nocapture %0, i32 %1, i8* nocapture writeonly %2) {
switch i32 %1, label %28 [
i32 1, label %4
i32 2, label %7
i32 3, label %12
i32 4, label %19
]
4: ; preds = %3
%5 = load i32, i32* %0
%6 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %28
7: ; preds = %3
%8 = load i32, i32* %0
%9 = getelementptr inbounds i32, i32* %0, i64 1
%10 = load i32, i32* %9
%11 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i32 %8, i32 %10)
br label %28
12: ; preds = %3
%13 = load i32, i32* %0
%14 = getelementptr inbounds i32, i32* %0, i64 1
%15 = load i32, i32* %14
%16 = getelementptr inbounds i32, i32* %0, i64 2
%17 = load i32, i32* %16
%18 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0), i32 %13, i32 %15, i32 %17)
br label %28
19: ; preds = %3
%20 = load i32, i32* %0
%21 = getelementptr inbounds i32, i32* %0, i64 1
%22 = load i32, i32* %21
%23 = getelementptr inbounds i32, i32* %0, i64 2
%24 = load i32, i32* %23
%25 = getelementptr inbounds i32, i32* %0, i64 3
%26 = load i32, i32* %25
%27 = tail call i32 (i8*, i8*, i32, ...) @sprintf(i8* dereferenceable(1) %2, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0), i32 %20, i32 %22, i32 %24, i32 %26)
br label %28
28: ; preds = %3, %19, %12, %7, %4
ret void
}