#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 *str_get_token_info(char *, unsigned int, char, unsigned int *);
int /*<<< orphan*/ strncpy(char *, char *, unsigned int);
char *str_get_token(char *src, unsigned int token_no, char token_separator,
                    char *buf, int buf_size) {
  int unsigned token_len;
  char *token = str_get_token_info(src, token_no, token_separator, &token_len);
  if (buf_size < token_len)
    token_len = buf_size;
  if (token) {
    strncpy(buf, token, token_len);
    buf[token_len] = 0;
    return buf;
  } else {
    buf[0] = 0;
    return NULL;
  }
}


x86 assembly (clang, -O0):
<str_get_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %dl,%al
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %al,-0x15(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8d,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
lea    -0x28(%rbp),%rcx
movsbl -0x15(%rbp),%edx
call   1040 <str_get_token_info@plt>
mov    %rax,-0x30(%rbp)
mov    -0x24(%rbp),%eax
cmp    -0x28(%rbp),%eax
jae    1166 <str_get_token+0x46>
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     1199 <str_get_token+0x79>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rsi
mov    -0x28(%rbp),%edx
call   1030 <strncpy@plt>
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%ecx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    11a8 <str_get_token+0x88>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<str_get_token>:
push   %rbp
push   %rbx
push   %rax
mov    %r8d,%ebp
mov    %rcx,%rbx
lea    0x4(%rsp),%rcx
call   1040 <str_get_token_info@plt>
mov    0x4(%rsp),%edx
cmp    %ebp,%edx
jbe    1141 <str_get_token+0x21>
mov    %ebp,0x4(%rsp)
mov    %ebp,%edx
test   %rax,%rax
je     115a <str_get_token+0x3a>
mov    %rbx,%rdi
mov    %rax,%rsi
call   1030 <strncpy@plt>
mov    0x4(%rsp),%eax
add    %rbx,%rax
jmp    115f <str_get_token+0x3f>
mov    %rbx,%rax
xor    %ebx,%ebx
movb   $0x0,(%rax)
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
define i8* @str_get_token(i8* %0, i32 %1, i8 signext %2, i8* %3, i32 %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8 %2, i8* %9
store i8* %3, i8** %10
store i32 %4, i32* %11
%14 = load i8*, i8** %7
%15 = load i32, i32* %8
%16 = load i8, i8* %9
%17 = call i8* @str_get_token_info(i8* %14, i32 %15, i8 signext %16, i32* %12)
store i8* %17, i8** %13
%18 = load i32, i32* %11
%19 = load i32, i32* %12
%20 = icmp ult i32 %18, %19
br i1 %20, label %21, label %23
21: ; preds = %5
%22 = load i32, i32* %11
store i32 %22, i32* %12
br label %23
23: ; preds = %21, %5
%24 = load i8*, i8** %13
%25 = icmp ne i8* %24, null
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i8*, i8** %10
%28 = load i8*, i8** %13
%29 = load i32, i32* %12
%30 = call i32 @strncpy(i8* %27, i8* %28, i32 %29)
%31 = load i8*, i8** %10
%32 = load i32, i32* %12
%33 = zext i32 %32 to i64
%34 = getelementptr inbounds i8, i8* %31, i64 %33
store i8 0, i8* %34
%35 = load i8*, i8** %10
store i8* %35, i8** %6
br label %39
36: ; preds = %23
%37 = load i8*, i8** %10
%38 = getelementptr inbounds i8, i8* %37, i64 0
store i8 0, i8* %38
store i8* null, i8** %6
br label %39
39: ; preds = %36, %26
%40 = load i8*, i8** %6
ret i8* %40
}

LLVM IR (-O2):
define i8* @str_get_token(i8* %0, i32 %1, i8 signext %2, i8* %3, i32 %4) {
%6 = alloca i32
%7 = bitcast i32* %6 to i8*
%8 = call i8* @str_get_token_info(i8* %0, i32 %1, i8 signext %2, i32* %6)
%9 = load i32, i32* %6
%10 = icmp ugt i32 %9, %4
br i1 %10, label %11, label %12
11: ; preds = %5
store i32 %4, i32* %6
br label %12
12: ; preds = %11, %5
%13 = phi i32 [ %4, %11 ], [ %9, %5 ]
%14 = icmp eq i8* %8, null
br i1 %14, label %20, label %15
15: ; preds = %12
%16 = call i32 @strncpy(i8* %3, i8* %8, i32 %13)
%17 = load i32, i32* %6
%18 = zext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %3, i64 %18
br label %20
20: ; preds = %12, %15
%21 = phi i8* [ %19, %15 ], [ %3, %12 ]
%22 = phi i8* [ %3, %15 ], [ null, %12 ]
store i8 0, i8* %21
ret i8* %22
}