#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*/ dont_report(int, char *, ...);
char *strtok(char *, char *);
int get_args(char **argv, char *str, int max_args) {
  char *delimiters = " \n\0";
  char *item;
  int i = 0;
  if (!argv)
    return -1;
  if (!str)
    return 0;
  if (max_args < 1)
    return 0;
  dont_report(5, "get_args(%i): string=%s", max_args, str);
  for (item = strtok(str, delimiters); item; item = strtok(NULL, delimiters)) {
    dont_report(5, "get_args: item=%s", item);
    if (i < max_args) {
      argv[i] = item;
      i++;
    } else
      return i;
  }
  return i;
}


x86 assembly (clang, -O0):
<get_args>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
lea    0xec6(%rip),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    115c <get_args+0x3c>
movl   $0xffffffff,-0x4(%rbp)
jmp    122c <get_args+0x10c>
cmpq   $0x0,-0x18(%rbp)
jne    1173 <get_args+0x53>
movl   $0x0,-0x4(%rbp)
jmp    122c <get_args+0x10c>
cmpl   $0x1,-0x1c(%rbp)
jge    1189 <get_args+0x69>
movl   $0x0,-0x4(%rbp)
jmp    122c <get_args+0x10c>
mov    -0x1c(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x5,%edi
lea    0xe68(%rip),%rsi
mov    $0x0,%al
call   1030 <dont_report@plt>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1226 <get_args+0x106>
mov    -0x30(%rbp),%rdx
mov    $0x5,%edi
lea    0xe4d(%rip),%rsi
mov    $0x0,%al
call   1030 <dont_report@plt>
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1200 <get_args+0xe0>
mov    -0x30(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    120b <get_args+0xeb>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    122c <get_args+0x10c>
jmp    1210 <get_args+0xf0>
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
jmp    11b4 <get_args+0x94>
mov    -0x34(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_args>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
test   %rdi,%rdi
je     11d3 <get_args+0xb3>
mov    %rsi,%rbp
xor    %ebx,%ebx
test   %rsi,%rsi
je     11dd <get_args+0xbd>
mov    %edx,%r15d
test   %edx,%edx
jle    11dd <get_args+0xbd>
mov    %rdi,%r14
lea    0xead(%rip),%rsi
xor    %ebx,%ebx
mov    $0x5,%edi
mov    %r15d,%edx
mov    %rbp,%rcx
xor    %eax,%eax
call   1030 <dont_report@plt>
lea    0xe8e(%rip),%rsi
mov    %rbp,%rdi
call   1040 <strtok@plt>
test   %rax,%rax
je     11dd <get_args+0xbd>
mov    %rax,%rbp
mov    %r15d,%r13d
lea    0xe90(%rip),%r15
lea    0xe6d(%rip),%r12
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
mov    $0x5,%edi
mov    %r15,%rsi
mov    %rbp,%rdx
xor    %eax,%eax
call   1030 <dont_report@plt>
cmp    %rbx,%r13
je     11da <get_args+0xba>
mov    %rbp,(%r14,%rbx,8)
add    $0x1,%rbx
xor    %edi,%edi
mov    %r12,%rsi
call   1040 <strtok@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11a0 <get_args+0x80>
jmp    11dd <get_args+0xbd>
mov    $0xffffffff,%ebx
jmp    11dd <get_args+0xbd>
mov    %r13d,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" \0A\00\00"
@.str.1 = [24 x i8] c"get_args(%i): string=%s\00"
@.str.2 = [18 x i8] c"get_args: item=%s\00"
define i32 @get_args(i8** %0, i8* %1, i32 %2) {
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32
store i8** %0, i8*** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %8
store i32 0, i32* %10
%11 = load i8**, i8*** %5
%12 = icmp ne i8** %11, null
br i1 %12, label %14, label %13
13: ; preds = %3
store i32 -1, i32* %4
br label %54
14: ; preds = %3
%15 = load i8*, i8** %6
%16 = icmp ne i8* %15, null
br i1 %16, label %18, label %17
17: ; preds = %14
store i32 0, i32* %4
br label %54
18: ; preds = %14
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %18
store i32 0, i32* %4
br label %54
22: ; preds = %18
%23 = load i32, i32* %7
%24 = load i8*, i8** %6
%25 = call i32 (i32, i8*, ...) @dont_report(i32 5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %23, i8* %24)
%26 = load i8*, i8** %6
%27 = load i8*, i8** %8
%28 = call i8* @strtok(i8* %26, i8* %27)
store i8* %28, i8** %9
br label %29
29: ; preds = %49, %22
%30 = load i8*, i8** %9
%31 = icmp ne i8* %30, null
br i1 %31, label %32, label %52
32: ; preds = %29
%33 = load i8*, i8** %9
%34 = call i32 (i32, i8*, ...) @dont_report(i32 5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i32, i32* %10
%36 = load i32, i32* %7
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %46
38: ; preds = %32
%39 = load i8*, i8** %9
%40 = load i8**, i8*** %5
%41 = load i32, i32* %10
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
store i8* %39, i8** %43
%44 = load i32, i32* %10
%45 = add nsw i32 %44, 1
store i32 %45, i32* %10
br label %48
46: ; preds = %32
%47 = load i32, i32* %10
store i32 %47, i32* %4
br label %54
48: ; preds = %38
br label %49
49: ; preds = %48
%50 = load i8*, i8** %8
%51 = call i8* @strtok(i8* null, i8* %50)
store i8* %51, i8** %9
br label %29
52: ; preds = %29
%53 = load i32, i32* %10
store i32 %53, i32* %4
br label %54
54: ; preds = %52, %46, %21, %17, %13
%55 = load i32, i32* %4
ret i32 %55
}

LLVM IR (-O2):
@.str = [4 x i8] c" \0A\00\00"
@.str.1 = [24 x i8] c"get_args(%i): string=%s\00"
@.str.2 = [18 x i8] c"get_args: item=%s\00"
define i32 @get_args(i8** writeonly %0, i8* %1, i32 %2) {
%4 = icmp eq i8** %0, null
br i1 %4, label %27, label %5
5: ; preds = %3
%6 = icmp eq i8* %1, null
%7 = icmp slt i32 %2, 1
%8 = or i1 %6, %7
br i1 %8, label %27, label %9
9: ; preds = %5
%10 = tail call i32 (i32, i8*, ...) @dont_report(i32 5, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i32 %2, i8* %1)
%11 = tail call i8* @strtok(i8* %1, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %27, label %13
13: ; preds = %9
%14 = zext i32 %2 to i64
br label %15
15: ; preds = %13, %20
%16 = phi i64 [ 0, %13 ], [ %22, %20 ]
%17 = phi i8* [ %11, %13 ], [ %23, %20 ]
%18 = tail call i32 (i32, i8*, ...) @dont_report(i32 5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %17)
%19 = icmp eq i64 %16, %14
br i1 %19, label %27, label %20
20: ; preds = %15
%21 = getelementptr inbounds i8*, i8** %0, i64 %16
store i8* %17, i8** %21
%22 = add nuw nsw i64 %16, 1
%23 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %25, label %15
25: ; preds = %20
%26 = trunc i64 %22 to i32
br label %27
27: ; preds = %15, %25, %9, %5, %3
%28 = phi i32 [ -1, %3 ], [ 0, %5 ], [ 0, %9 ], [ %26, %25 ], [ %2, %15 ]
ret i32 %28
}