#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 uint32_t;

/* Variables and functions */
int snprintf(char *, int, char *, char *, int);
int /*<<< orphan*/ strcpy(char *, char *);
void fh_cpu_print(uint32_t cpu_mask, char *buf, int size) {
  char *ptr = buf;
  int len = 0, i, first = 1;
  if (cpu_mask) {
    for (i = 0; i < 32; i++) {
      if (cpu_mask & (1 << i)) {
        len = snprintf(ptr, size, "%s%d", first ? "" : ",", i);
        size -= len;
        ptr += len;
        first = 0;
      }
    }
  } else {
    strcpy(buf, "?");
  }
}


x86 assembly (clang, -O0):
<fh_cpu_print>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x1,-0x2c(%rbp)
cmpl   $0x0,-0x4(%rbp)
je     11ea <fh_cpu_print+0xca>
movl   $0x0,-0x28(%rbp)
cmpl   $0x20,-0x28(%rbp)
jge    11e5 <fh_cpu_print+0xc5>
mov    -0x4(%rbp),%eax
mov    -0x28(%rbp),%ecx
mov    $0x1,%edx
shl    %cl,%edx
mov    %edx,%ecx
and    %ecx,%eax
cmp    $0x0,%eax
je     11d2 <fh_cpu_print+0xb2>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x2c(%rbp),%edx
lea    0xe77(%rip),%rcx
lea    0xe71(%rip),%rax
cmp    $0x0,%edx
cmovne %rax,%rcx
mov    -0x28(%rbp),%r8d
lea    0xe59(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x14(%rbp),%eax
sub    %ecx,%eax
mov    %eax,-0x14(%rbp)
mov    -0x24(%rbp),%ecx
mov    -0x20(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x2c(%rbp)
jmp    11d7 <fh_cpu_print+0xb7>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    1159 <fh_cpu_print+0x39>
jmp    11fa <fh_cpu_print+0xda>
mov    -0x10(%rbp),%rdi
lea    0xe12(%rip),%rsi
call   1030 <strcpy@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fh_cpu_print>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
test   %edi,%edi
je     1198 <fh_cpu_print+0x78>
mov    %edx,%ebp
mov    %edi,%r14d
xor    %ebx,%ebx
mov    $0x1,%eax
lea    0xec1(%rip),%r13
lea    0xeb4(%rip),%r12
jmp    1158 <fh_cpu_print+0x38>
xchg   %ax,%ax
add    $0x1,%ebx
cmp    $0x20,%ebx
je     1189 <fh_cpu_print+0x69>
bt     %ebx,%r14d
jae    1150 <fh_cpu_print+0x30>
test   %eax,%eax
mov    %r13,%rcx
lea    0xe9b(%rip),%rax
cmove  %rax,%rcx
mov    %r15,%rdi
mov    %ebp,%esi
mov    %r12,%rdx
mov    %ebx,%r8d
call   1040 <snprintf@plt>
sub    %eax,%ebp
cltq
add    %rax,%r15
xor    %eax,%eax
jmp    1150 <fh_cpu_print+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe68(%rip),%rsi
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
jmp    1030 <strcpy@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c",\00"
@.str.3 = [2 x i8] c"?\00"
define void @fh_cpu_print(i32 %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 %0, i32* %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%11 = load i8*, i8** %5
store i8* %11, i8** %7
store i32 0, i32* %8
store i32 1, i32* %10
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 0
br i1 %13, label %14, label %45
14: ; preds = %3
store i32 0, i32* %9
br label %15
15: ; preds = %41, %14
%16 = load i32, i32* %9
%17 = icmp slt i32 %16, 32
br i1 %17, label %18, label %44
18: ; preds = %15
%19 = load i32, i32* %4
%20 = load i32, i32* %9
%21 = shl i32 1, %20
%22 = and i32 %19, %21
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %40
24: ; preds = %18
%25 = load i8*, i8** %7
%26 = load i32, i32* %6
%27 = load i32, i32* %10
%28 = icmp ne i32 %27, 0
%29 = zext i1 %28 to i64
%30 = select i1 %28, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0)
%31 = load i32, i32* %9
%32 = call i32 @snprintf(i8* %25, i32 %26, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %30, i32 %31)
store i32 %32, i32* %8
%33 = load i32, i32* %8
%34 = load i32, i32* %6
%35 = sub nsw i32 %34, %33
store i32 %35, i32* %6
%36 = load i32, i32* %8
%37 = load i8*, i8** %7
%38 = sext i32 %36 to i64
%39 = getelementptr inbounds i8, i8* %37, i64 %38
store i8* %39, i8** %7
store i32 0, i32* %10
br label %40
40: ; preds = %24, %18
br label %41
41: ; preds = %40
%42 = load i32, i32* %9
%43 = add nsw i32 %42, 1
store i32 %43, i32* %9
br label %15
44: ; preds = %15
br label %48
45: ; preds = %3
%46 = load i8*, i8** %5
%47 = call i32 @strcpy(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %48
48: ; preds = %45, %44
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%d\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [2 x i8] c",\00"
@.str.3 = [2 x i8] c"?\00"
define void @fh_cpu_print(i32 %0, i8* %1, i32 %2) {
%4 = icmp eq i32 %0, 0
br i1 %4, label %26, label %5
5: ; preds = %3, %20
%6 = phi i32 [ %23, %20 ], [ 1, %3 ]
%7 = phi i32 [ %24, %20 ], [ 0, %3 ]
%8 = phi i8* [ %22, %20 ], [ %1, %3 ]
%9 = phi i32 [ %21, %20 ], [ %2, %3 ]
%10 = shl nuw i32 1, %7
%11 = and i32 %10, %0
%12 = icmp eq i32 %11, 0
br i1 %12, label %20, label %13
13: ; preds = %5
%14 = icmp eq i32 %6, 0
%15 = select i1 %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
%16 = tail call i32 @snprintf(i8* %8, i32 %9, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %15, i32 %7)
%17 = sub nsw i32 %9, %16
%18 = sext i32 %16 to i64
%19 = getelementptr inbounds i8, i8* %8, i64 %18
br label %20
20: ; preds = %5, %13
%21 = phi i32 [ %17, %13 ], [ %9, %5 ]
%22 = phi i8* [ %19, %13 ], [ %8, %5 ]
%23 = phi i32 [ 0, %13 ], [ %6, %5 ]
%24 = add nuw nsw i32 %7, 1
%25 = icmp eq i32 %24, 32
br i1 %25, label %28, label %5
26: ; preds = %3
%27 = tail call i32 @strcpy(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %28
28: ; preds = %20, %26
ret void
}