#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 */
char *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
int cpu_map_to_list(char *input, char *buffer, int bsize) {
  int pos = 0;
  char *current;
  int cur_hex;
  char *tmp;
  char buf[20];
  if (input == NULL || buffer == NULL || bsize <= 0)
    return 0;
  tmp = malloc((strlen(input) + 1) * sizeof(char));
  memcpy(tmp, input, strlen(input) + 1);
  memset(buffer, 0, bsize);
  while (strlen(tmp)) {
    current = &(tmp[strlen(tmp) - 1]);
    if (*current != ',') {
      cur_hex = (int)strtol(current, NULL, 16);
      if (cur_hex & 0x1) {
        sprintf(buf, "cpu%i ", pos);
        strcat(buffer, buf);
      }
      if (cur_hex & 0x2) {
        sprintf(buf, "cpu%i ", pos + 1);
        strcat(buffer, buf);
      }
      if (cur_hex & 0x4) {
        sprintf(buf, "cpu%i ", pos + 2);
        strcat(buffer, buf);
      }
      if (cur_hex & 0x8) {
        sprintf(buf, "cpu%i ", pos + 3);
        strcat(buffer, buf);
      }
      pos += 4;
    }
    *current = '\0';
  }
  return -1;
}


x86 assembly (clang, -O0):
<cpu_map_to_list>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11aa <cpu_map_to_list+0x3a>
cmpq   $0x0,-0x18(%rbp)
je     11aa <cpu_map_to_list+0x3a>
cmpl   $0x0,-0x1c(%rbp)
jg     11b6 <cpu_map_to_list+0x46>
movl   $0x0,-0x4(%rbp)
jmp    1348 <cpu_map_to_list+0x1d8>
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
add    $0x1,%eax
cltq
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x58(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x60(%rbp),%rdi
mov    -0x58(%rbp),%rsi
mov    %eax,%edx
add    $0x1,%edx
call   1060 <memcpy@plt>
mov    -0x18(%rbp),%rdi
mov    -0x1c(%rbp),%edx
xor    %esi,%esi
call   1040 <memset@plt>
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x0,%eax
je     1341 <cpu_map_to_list+0x1d1>
mov    -0x38(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x38(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2c,%eax
je     1335 <cpu_map_to_list+0x1c5>
mov    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
and    $0x1,%eax
cmp    $0x0,%eax
je     1296 <cpu_map_to_list+0x126>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%edx
lea    0xd7c(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x2c(%rbp),%eax
and    $0x2,%eax
cmp    $0x0,%eax
je     12c8 <cpu_map_to_list+0x158>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x1,%edx
lea    0xd4a(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x2c(%rbp),%eax
and    $0x4,%eax
cmp    $0x0,%eax
je     12fa <cpu_map_to_list+0x18a>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x2,%edx
lea    0xd18(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x2c(%rbp),%eax
and    $0x8,%eax
cmp    $0x0,%eax
je     132c <cpu_map_to_list+0x1bc>
lea    -0x50(%rbp),%rdi
mov    -0x20(%rbp),%edx
add    $0x3,%edx
lea    0xce6(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x18(%rbp),%rdi
lea    -0x50(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x20(%rbp),%eax
add    $0x4,%eax
mov    %eax,-0x20(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
jmp    120c <cpu_map_to_list+0x9c>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cpu_map_to_list>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %ecx,%ecx
test   %rdi,%rdi
je     12f3 <cpu_map_to_list+0x183>
mov    %rsi,%r14
test   %rsi,%rsi
je     12f3 <cpu_map_to_list+0x183>
mov    %edx,%r15d
test   %edx,%edx
jle    12f3 <cpu_map_to_list+0x183>
mov    %rdi,%rbp
call   1030 <strlen@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x1(%rax),%edx
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1060 <memcpy@plt>
xor    %ebp,%ebp
mov    %r14,%rdi
xor    %esi,%esi
mov    %r15d,%edx
call   1040 <memset@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    $0xffffffff,%ecx
test   %eax,%eax
je     12f3 <cpu_map_to_list+0x183>
mov    %rsp,%r13
jmp    1217 <cpu_map_to_list+0xa7>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    $0x4,%ebp
movb   $0x0,(%r15)
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
je     12ee <cpu_map_to_list+0x17e>
mov    %rbx,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rax,%rbx,1),%r15
add    $0xffffffffffffffff,%r15
cmpb   $0x2c,-0x1(%rax,%rbx,1)
je     1203 <cpu_map_to_list+0x93>
mov    %r15,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1050 <strtol@plt>
mov    %rax,%r12
test   $0x1,%r12b
jne    1260 <cpu_map_to_list+0xf0>
test   $0x2,%r12b
jne    1282 <cpu_map_to_list+0x112>
test   $0x4,%r12b
jne    12a5 <cpu_map_to_list+0x135>
test   $0x8,%r12b
je     1200 <cpu_map_to_list+0x90>
jmp    12cc <cpu_map_to_list+0x15c>
nopl   0x0(%rax)
mov    %r13,%rdi
lea    0xd96(%rip),%rsi
mov    %ebp,%edx
call   1090 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
test   $0x2,%r12b
je     124e <cpu_map_to_list+0xde>
lea    0x1(%rbp),%edx
mov    %r13,%rdi
lea    0xd71(%rip),%rsi
call   1090 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
test   $0x4,%r12b
je     1254 <cpu_map_to_list+0xe4>
lea    0x2(%rbp),%edx
mov    %r13,%rdi
lea    0xd4e(%rip),%rsi
call   1090 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
test   $0x8,%r12b
je     1200 <cpu_map_to_list+0x90>
lea    0x3(%rbp),%edx
mov    %r13,%rdi
lea    0xd27(%rip),%rsi
call   1090 <sprintf@plt>
mov    %r14,%rdi
mov    %r13,%rsi
call   1080 <strcat@plt>
jmp    1200 <cpu_map_to_list+0x90>
mov    $0xffffffff,%ecx
mov    %ecx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [7 x i8] c"cpu%i \00"
define i32 @cpu_map_to_list(i8* %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca [20 x i8]
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i32 0, i32* %8
%13 = load i8*, i8** %5
%14 = icmp eq i8* %13, null
br i1 %14, label %21, label %15
15: ; preds = %3
%16 = load i8*, i8** %6
%17 = icmp eq i8* %16, null
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i32, i32* %7
%20 = icmp sle i32 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %18, %15, %3
store i32 0, i32* %4
br label %110
22: ; preds = %18
%23 = load i8*, i8** %5
%24 = call i32 @strlen(i8* %23)
%25 = add nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 1
%28 = trunc i64 %27 to i32
%29 = call i8* @malloc(i32 %28)
store i8* %29, i8** %11
%30 = load i8*, i8** %11
%31 = load i8*, i8** %5
%32 = load i8*, i8** %5
%33 = call i32 @strlen(i8* %32)
%34 = add nsw i32 %33, 1
%35 = call i32 @memcpy(i8* %30, i8* %31, i32 %34)
%36 = load i8*, i8** %6
%37 = load i32, i32* %7
%38 = call i32 @memset(i8* %36, i32 0, i32 %37)
br label %39
39: ; preds = %107, %22
%40 = load i8*, i8** %11
%41 = call i32 @strlen(i8* %40)
%42 = icmp ne i32 %41, 0
br i1 %42, label %43, label %109
43: ; preds = %39
%44 = load i8*, i8** %11
%45 = load i8*, i8** %11
%46 = call i32 @strlen(i8* %45)
%47 = sub nsw i32 %46, 1
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %44, i64 %48
store i8* %49, i8** %9
%50 = load i8*, i8** %9
%51 = load i8, i8* %50
%52 = sext i8 %51 to i32
%53 = icmp ne i32 %52, 44
br i1 %53, label %54, label %107
54: ; preds = %43
%55 = load i8*, i8** %9
%56 = call i64 @strtol(i8* %55, i32* null, i32 16)
%57 = trunc i64 %56 to i32
store i32 %57, i32* %10
%58 = load i32, i32* %10
%59 = and i32 %58, 1
%60 = icmp ne i32 %59, 0
br i1 %60, label %61, label %68
61: ; preds = %54
%62 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%63 = load i32, i32* %8
%64 = call i32 @sprintf(i8* %62, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %63)
%65 = load i8*, i8** %6
%66 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%67 = call i32 @strcat(i8* %65, i8* %66)
br label %68
68: ; preds = %61, %54
%69 = load i32, i32* %10
%70 = and i32 %69, 2
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %80
72: ; preds = %68
%73 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%74 = load i32, i32* %8
%75 = add nsw i32 %74, 1
%76 = call i32 @sprintf(i8* %73, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %75)
%77 = load i8*, i8** %6
%78 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%79 = call i32 @strcat(i8* %77, i8* %78)
br label %80
80: ; preds = %72, %68
%81 = load i32, i32* %10
%82 = and i32 %81, 4
%83 = icmp ne i32 %82, 0
br i1 %83, label %84, label %92
84: ; preds = %80
%85 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%86 = load i32, i32* %8
%87 = add nsw i32 %86, 2
%88 = call i32 @sprintf(i8* %85, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %87)
%89 = load i8*, i8** %6
%90 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%91 = call i32 @strcat(i8* %89, i8* %90)
br label %92
92: ; preds = %84, %80
%93 = load i32, i32* %10
%94 = and i32 %93, 8
%95 = icmp ne i32 %94, 0
br i1 %95, label %96, label %104
96: ; preds = %92
%97 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%98 = load i32, i32* %8
%99 = add nsw i32 %98, 3
%100 = call i32 @sprintf(i8* %97, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %99)
%101 = load i8*, i8** %6
%102 = getelementptr inbounds [20 x i8], [20 x i8]* %12, i64 0, i64 0
%103 = call i32 @strcat(i8* %101, i8* %102)
br label %104
104: ; preds = %96, %92
%105 = load i32, i32* %8
%106 = add nsw i32 %105, 4
store i32 %106, i32* %8
br label %107
107: ; preds = %104, %43
%108 = load i8*, i8** %9
store i8 0, i8* %108
br label %39
109: ; preds = %39
store i32 -1, i32* %4
br label %110
110: ; preds = %109, %21
%111 = load i32, i32* %4
ret i32 %111
}

LLVM IR (-O2):
@.str = [7 x i8] c"cpu%i \00"
define i32 @cpu_map_to_list(i8* %0, i8* %1, i32 %2) {
%4 = alloca [20 x i8]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %4, i64 0, i64 0
%6 = icmp eq i8* %0, null
%7 = icmp eq i8* %1, null
%8 = or i1 %6, %7
%9 = icmp slt i32 %2, 1
%10 = or i1 %8, %9
br i1 %10, label %64, label %11
11: ; preds = %3
%12 = tail call i32 @strlen(i8* %0)
%13 = add nsw i32 %12, 1
%14 = tail call i8* @malloc(i32 %13)
%15 = tail call i32 @strlen(i8* %0)
%16 = add nsw i32 %15, 1
%17 = tail call i32 @memcpy(i8* %14, i8* %0, i32 %16)
%18 = tail call i32 @memset(i8* %1, i32 0, i32 %2)
%19 = call i32 @strlen(i8* %14)
%20 = icmp eq i32 %19, 0
br i1 %20, label %64, label %21
21: ; preds = %11, %60
%22 = phi i32 [ %61, %60 ], [ 0, %11 ]
%23 = call i32 @strlen(i8* %14)
%24 = add nsw i32 %23, -1
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %14, i64 %25
%27 = load i8, i8* %26
%28 = icmp eq i8 %27, 44
br i1 %28, label %60, label %29
29: ; preds = %21
%30 = call i64 @strtol(i8* nocapture %26, i32* null, i32 16)
%31 = trunc i64 %30 to i32
%32 = and i32 %31, 1
%33 = icmp eq i32 %32, 0
br i1 %33, label %37, label %34
34: ; preds = %29
%35 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %22)
%36 = call i32 @strcat(i8* %1, i8* %5)
br label %37
37: ; preds = %34, %29
%38 = and i32 %31, 2
%39 = icmp eq i32 %38, 0
br i1 %39, label %44, label %40
40: ; preds = %37
%41 = add nsw i32 %22, 1
%42 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %41)
%43 = call i32 @strcat(i8* %1, i8* %5)
br label %44
44: ; preds = %40, %37
%45 = and i32 %31, 4
%46 = icmp eq i32 %45, 0
br i1 %46, label %51, label %47
47: ; preds = %44
%48 = add nsw i32 %22, 2
%49 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %48)
%50 = call i32 @strcat(i8* %1, i8* %5)
br label %51
51: ; preds = %47, %44
%52 = and i32 %31, 8
%53 = icmp eq i32 %52, 0
br i1 %53, label %58, label %54
54: ; preds = %51
%55 = add nsw i32 %22, 3
%56 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %55)
%57 = call i32 @strcat(i8* %1, i8* %5)
br label %58
58: ; preds = %54, %51
%59 = add nsw i32 %22, 4
br label %60
60: ; preds = %58, %21
%61 = phi i32 [ %59, %58 ], [ %22, %21 ]
store i8 0, i8* %26
%62 = call i32 @strlen(i8* %14)
%63 = icmp eq i32 %62, 0
br i1 %63, label %64, label %21
64: ; preds = %60, %11, %3
%65 = phi i32 [ 0, %3 ], [ -1, %11 ], [ -1, %60 ]
ret i32 %65
}