#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*/ exit(int);
int /*<<< orphan*/ printf(char *);
char *strtok(char *, char *);
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int /*<<< orphan*/);
int stringlisttobytes(unsigned char *list, char *stringlist) {
  int bytesread = 0;
  char *singlebytestring;
  if (stringlist[0] == '\0') {
    printf("Got null string in stringlisttobytes, exiting\n");
    exit(1);
  }
  singlebytestring = strtok(stringlist, ",");
  while (singlebytestring != NULL) {
    list[bytesread++] = (unsigned char)strtol(singlebytestring, NULL, 0);
    singlebytestring = strtok(NULL, ",");
  }
  return (bytesread);
}


x86 assembly (clang, -O0):
<stringlisttobytes>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    117d <stringlisttobytes+0x3d>
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    $0x1,%edi
call   1060 <exit@plt>
mov    -0x10(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11db <stringlisttobytes+0x9b>
mov    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %al,%dl
mov    -0x8(%rbp),%rax
mov    -0x14(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x14(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe62(%rip),%rsi
call   1050 <strtok@plt>
mov    %rax,-0x20(%rbp)
jmp    1191 <stringlisttobytes+0x51>
mov    -0x14(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stringlisttobytes>:
push   %r15
push   %r14
push   %rbx
cmpb   $0x0,(%rsi)
je     119b <stringlisttobytes+0x5b>
mov    %rdi,%r14
lea    0xeac(%rip),%rax
mov    %rsi,%rdi
mov    %rax,%rsi
call   1050 <strtok@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1193 <stringlisttobytes+0x53>
lea    0xe93(%rip),%r15
nopl   (%rax)
mov    %rax,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1040 <strtol@plt>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1050 <strtok@plt>
test   %rax,%rax
jne    1170 <stringlisttobytes+0x30>
mov    %ebx,%eax
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [47 x i8] c"Got null string in stringlisttobytes, exiting\0A\00"
@.str.1 = [2 x i8] c",\00"
define i32 @stringlisttobytes(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%7 = load i8*, i8** %4
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = load i8*, i8** %4
%17 = call i8* @strtok(i8* %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %17, i8** %6
br label %18
18: ; preds = %21, %15
%19 = load i8*, i8** %6
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %31
21: ; preds = %18
%22 = load i8*, i8** %6
%23 = call i64 @strtol(i8* %22, i32* null, i32 0)
%24 = trunc i64 %23 to i8
%25 = load i8*, i8** %3
%26 = load i32, i32* %5
%27 = add nsw i32 %26, 1
store i32 %27, i32* %5
%28 = sext i32 %26 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
store i8 %24, i8* %29
%30 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %30, i8** %6
br label %18
31: ; preds = %18
%32 = load i32, i32* %5
ret i32 %32
}

LLVM IR (-O2):
@.str.1 = [2 x i8] c",\00"
@str = [46 x i8] c"Got null string in stringlisttobytes, exiting\00"
define i32 @stringlisttobytes(i8* nocapture writeonly %0, i8* %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%10 = icmp eq i8* %9, null
br i1 %10, label %22, label %11
11: ; preds = %8, %11
%12 = phi i64 [ %16, %11 ], [ 0, %8 ]
%13 = phi i8* [ %18, %11 ], [ %9, %8 ]
%14 = tail call i64 @strtol(i8* nocapture %13, i32* null, i32 0)
%15 = trunc i64 %14 to i8
%16 = add nuw i64 %12, 1
%17 = getelementptr inbounds i8, i8* %0, i64 %12
store i8 %15, i8* %17
%18 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %20, label %11
20: ; preds = %11
%21 = trunc i64 %16 to i32
br label %22
22: ; preds = %20, %8
%23 = phi i32 [ 0, %8 ], [ %21, %20 ]
ret i32 %23
}