#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*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stdout;
char *strtok(char *, char *);
int getargs(char *line, char *args[], int max) {
  char *inptr;
  int i;
  inptr = line;
  for (i = 0; i <= max; i++) {
    if ((args[i] = strtok(inptr, " \t\n")) == NULL)
      break;
    inptr = NULL;
  }
  if (i > max) {
    fprintf(stdout, "Too many args\n");
    return (0);
  }
  return (i);
}


x86 assembly (clang, -O0):
<getargs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jg     118f <getargs+0x6f>
mov    -0x28(%rbp),%rdi
lea    0xea7(%rip),%rsi
call   1040 <strtok@plt>
mov    -0x18(%rbp),%rcx
movslq -0x2c(%rbp),%rdx
mov    %rax,(%rcx,%rdx,8)
cmp    $0x0,%rax
jne    1179 <getargs+0x59>
jmp    118f <getargs+0x6f>
movq   $0x0,-0x28(%rbp)
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    1142 <getargs+0x22>
mov    -0x2c(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jle    11bc <getargs+0x9c>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
lea    0xe59(%rip),%rsi
call   1030 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    11c2 <getargs+0xa2>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getargs>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
test   %edx,%edx
js     115f <getargs+0x3f>
mov    %edx,%r15d
mov    %rsi,%r14
add    $0x1,%r15d
xor    %ebx,%ebx
lea    0xec1(%rip),%r12
nop
mov    %r12,%rsi
call   1040 <strtok@plt>
mov    %rax,(%r14,%rbx,8)
test   %rax,%rax
je     1176 <getargs+0x56>
add    $0x1,%rbx
mov    $0x0,%edi
cmp    %rbx,%r15
jne    1140 <getargs+0x20>
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
lea    0xe95(%rip),%rsi
call   1030 <fprintf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [4 x i8] c" \09\0A\00"
@stdout = global i32 0
@.str.1 = [15 x i8] c"Too many args\0A\00"
define i32 @getargs(i8* %0, i8** nocapture writeonly %1, i32 %2) {
%4 = icmp slt i32 %2, 0
br i1 %4, label %17, label %5
5: ; preds = %3
%6 = add nuw i32 %2, 1
%7 = zext i32 %6 to i64
br label %8
8: ; preds = %5, %14
%9 = phi i64 [ 0, %5 ], [ %15, %14 ]
%10 = phi i8* [ %0, %5 ], [ null, %14 ]
%11 = tail call i8* @strtok(i8* %10, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%12 = getelementptr inbounds i8*, i8** %1, i64 %9
store i8* %11, i8** %12
%13 = icmp eq i8* %11, null
br i1 %13, label %20, label %14
14: ; preds = %8
%15 = add nuw nsw i64 %9, 1
%16 = icmp eq i64 %15, %7
br i1 %16, label %17, label %8
17: ; preds = %14, %3
%18 = load i32, i32* @stdout
%19 = tail call i32 @fprintf(i32 %18, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %22
20: ; preds = %8
%21 = trunc i64 %9 to i32
br label %22
22: ; preds = %20, %17
%23 = phi i32 [ 0, %17 ], [ %21, %20 ]
ret i32 %23
}