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

/* Variables and functions */
int /*<<< orphan*/ assert(int);
scalar_t__ atoi(char *);
char *libmapping_strtok(char *, char *, char, int);
uint32_t to_vector(char *str, uint32_t *vec, uint32_t n) {
  char tok[32], *p;
  uint32_t i;
  p = str;
  p = libmapping_strtok(p, tok, ',', 32);
  i = 0;
  while (p != NULL) {
    assert(i < n);
    vec[i++] = atoi(tok);
    p = libmapping_strtok(p, tok, ',', 32);
  }
  return i;
}


x86 assembly (clang, -O0):
<to_vector>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x2c,%edx
mov    $0x20,%ecx
call   1030 <libmapping_strtok@plt>
mov    %rax,-0x48(%rbp)
movq   $0x0,-0x50(%rbp)
cmpq   $0x0,-0x48(%rbp)
je     11d2 <to_vector+0xa2>
mov    -0x50(%rbp),%rax
cmp    -0x18(%rbp),%rax
setl   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x40(%rbp),%rdi
call   1050 <atoi@plt>
mov    %rax,%rdx
mov    -0x10(%rbp),%rax
mov    -0x50(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x50(%rbp)
mov    %rdx,(%rax,%rcx,8)
mov    -0x48(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x2c,%edx
mov    $0x20,%ecx
call   1030 <libmapping_strtok@plt>
mov    %rax,-0x48(%rbp)
jmp    116f <to_vector+0x3f>
mov    -0x50(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<to_vector>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rsp,%rsi
mov    $0x2c,%edx
mov    $0x20,%ecx
call   1030 <libmapping_strtok@plt>
test   %rax,%rax
je     11ad <to_vector+0x7d>
mov    %rax,%r12
xor    %ebx,%ebx
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xor    %edi,%edi
cmp    %r14,%rbx
setl   %dil
call   1040 <assert@plt>
mov    %r13,%rdi
call   1050 <atoi@plt>
mov    %rax,(%r15,%rbx,8)
add    $0x1,%rbx
mov    %r12,%rdi
mov    %r13,%rsi
mov    $0x2c,%edx
mov    $0x20,%ecx
call   1030 <libmapping_strtok@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1170 <to_vector+0x40>
jmp    11af <to_vector+0x7f>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x20,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i64 @to_vector(i8* %0, i64* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i64*
%6 = alloca i64
%7 = alloca [32 x i8]
%8 = alloca i8*
%9 = alloca i64
store i8* %0, i8** %4
store i64* %1, i64** %5
store i64 %2, i64* %6
%10 = load i8*, i8** %4
store i8* %10, i8** %8
%11 = load i8*, i8** %8
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%13 = call i8* @libmapping_strtok(i8* %11, i8* %12, i8 signext 44, i32 32)
store i8* %13, i8** %8
store i64 0, i64* %9
br label %14
14: ; preds = %17, %3
%15 = load i8*, i8** %8
%16 = icmp ne i8* %15, null
br i1 %16, label %17, label %32
17: ; preds = %14
%18 = load i64, i64* %9
%19 = load i64, i64* %6
%20 = icmp slt i64 %18, %19
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%24 = call i64 @atoi(i8* %23)
%25 = load i64*, i64** %5
%26 = load i64, i64* %9
%27 = add nsw i64 %26, 1
store i64 %27, i64* %9
%28 = getelementptr inbounds i64, i64* %25, i64 %26
store i64 %24, i64* %28
%29 = load i8*, i8** %8
%30 = getelementptr inbounds [32 x i8], [32 x i8]* %7, i64 0, i64 0
%31 = call i8* @libmapping_strtok(i8* %29, i8* %30, i8 signext 44, i32 32)
store i8* %31, i8** %8
br label %14
32: ; preds = %14
%33 = load i64, i64* %9
ret i64 %33
}

LLVM IR (-O2):
define i64 @to_vector(i8* %0, i64* nocapture writeonly %1, i64 %2) {
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%6 = call i8* @libmapping_strtok(i8* %0, i8* %5, i8 signext 44, i32 32)
%7 = icmp eq i8* %6, null
br i1 %7, label %19, label %8
8: ; preds = %3, %8
%9 = phi i64 [ %15, %8 ], [ 0, %3 ]
%10 = phi i8* [ %17, %8 ], [ %6, %3 ]
%11 = icmp slt i64 %9, %2
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = call i64 @atoi(i8* %5)
%15 = add nuw nsw i64 %9, 1
%16 = getelementptr inbounds i64, i64* %1, i64 %9
store i64 %14, i64* %16
%17 = call i8* @libmapping_strtok(i8* %10, i8* %5, i8 signext 44, i32 32)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %8
19: ; preds = %8, %3
%20 = phi i64 [ 0, %3 ], [ %15, %8 ]
ret i64 %20
}