#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 /*<<< orphan*/);
int /*<<< orphan*/ strcpy(char *, char *);
int /*<<< orphan*/ strlen(char *);
char *strtok(char *, char *);
int parse_server_cmd_arg(char *optarg, char *servers[]) {
  int i = 0;
  char *ptr;
  if (optarg != NULL) {
    ptr = strtok(optarg, ",");
    while (ptr != NULL) {
      servers[i] = malloc(strlen(ptr));
      strcpy(servers[i], ptr);
      i++;
      ptr = strtok(NULL, ",");
    }
    return 0;
  } else {
    return -1;
  }
}


x86 assembly (clang, -O0):
<parse_server_cmd_arg>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11e3 <parse_server_cmd_arg+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xe93(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d7 <parse_server_cmd_arg+0x97>
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe37(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x28(%rbp)
jmp    1176 <parse_server_cmd_arg+0x36>
movl   $0x0,-0x4(%rbp)
jmp    11ea <parse_server_cmd_arg+0xaa>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<parse_server_cmd_arg>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11a8 <parse_server_cmd_arg+0x68>
mov    %rsi,%r15
lea    0xea9(%rip),%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     11b0 <parse_server_cmd_arg+0x70>
mov    %rax,%rbx
lea    0xe95(%rip),%r14
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1040 <strlen@plt>
mov    %eax,%edi
call   1050 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    %rbx,%rsi
call   1030 <strcpy@plt>
xor    %r12d,%r12d
xor    %edi,%edi
mov    %r14,%rsi
call   1060 <strtok@plt>
mov    %rax,%rbx
add    $0x8,%r15
test   %rax,%rax
jne    1170 <parse_server_cmd_arg+0x30>
jmp    11b3 <parse_server_cmd_arg+0x73>
mov    $0xffffffff,%r12d
jmp    11b3 <parse_server_cmd_arg+0x73>
xor    %r12d,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c",\00"
define i32 @parse_server_cmd_arg(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
store i8* %0, i8** %4
store i8** %1, i8*** %5
store i32 0, i32* %6
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %35
10: ; preds = %2
%11 = load i8*, i8** %4
%12 = call i8* @strtok(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %12, i8** %7
br label %13
13: ; preds = %16, %10
%14 = load i8*, i8** %7
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %34
16: ; preds = %13
%17 = load i8*, i8** %7
%18 = call i32 @strlen(i8* %17)
%19 = call i8* @malloc(i32 %18)
%20 = load i8**, i8*** %5
%21 = load i32, i32* %6
%22 = sext i32 %21 to i64
%23 = getelementptr inbounds i8*, i8** %20, i64 %22
store i8* %19, i8** %23
%24 = load i8**, i8*** %5
%25 = load i32, i32* %6
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds i8*, i8** %24, i64 %26
%28 = load i8*, i8** %27
%29 = load i8*, i8** %7
%30 = call i32 @strcpy(i8* %28, i8* %29)
%31 = load i32, i32* %6
%32 = add nsw i32 %31, 1
store i32 %32, i32* %6
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %33, i8** %7
br label %13
34: ; preds = %13
store i32 0, i32* %3
br label %36
35: ; preds = %2
store i32 -1, i32* %3
br label %36
36: ; preds = %35, %34
%37 = load i32, i32* %3
ret i32 %37
}

LLVM IR (-O2):
@.str = [2 x i8] c",\00"
define i32 @parse_server_cmd_arg(i8* %0, i8** nocapture writeonly %1) {
%3 = icmp eq i8* %0, null
br i1 %3, label %17, label %4
4: ; preds = %2
%5 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i8* %5, null
br i1 %6, label %17, label %7
7: ; preds = %4, %7
%8 = phi i64 [ %14, %7 ], [ 0, %4 ]
%9 = phi i8* [ %15, %7 ], [ %5, %4 ]
%10 = tail call i32 @strlen(i8* %9)
%11 = tail call i8* @malloc(i32 %10)
%12 = getelementptr inbounds i8*, i8** %1, i64 %8
store i8* %11, i8** %12
%13 = tail call i32 @strcpy(i8* %11, i8* %9)
%14 = add nuw i64 %8, 1
%15 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %7
17: ; preds = %7, %4, %2
%18 = phi i32 [ -1, %2 ], [ 0, %4 ], [ 0, %7 ]
ret i32 %18
}