#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*/ strcpy(char *, char *);
char *strtok(char *, char *);
int get_token_n(char *s1, char *delims, int n, char *retval) {
  char *p;
  int i;
  static char tempstr[(4 * 8192)];
  strcpy(tempstr, s1);
  p = strtok(tempstr, delims);
  i = 0;
  while (p != NULL) {
    if (i == n) {
      strcpy(retval, p);
      return (1);
    }
    p = strtok(NULL, delims);
    i++;
  }
  return (0);
}


x86 assembly (clang, -O0):
<get_token_n>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
mov    %rcx,-0x28(%rbp)
mov    -0x10(%rbp),%rsi
lea    0x2efe(%rip),%rdi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rsi
lea    0x2eee(%rip),%rdi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
cmpq   $0x0,-0x30(%rbp)
je     11b1 <get_token_n+0x91>
mov    -0x34(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    1192 <get_token_n+0x72>
mov    -0x28(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <strcpy@plt>
movl   $0x1,-0x4(%rbp)
jmp    11b8 <get_token_n+0x98>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x30(%rbp)
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1162 <get_token_n+0x42>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_token_n>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r14
mov    %edx,%ebp
mov    %rsi,%r15
mov    %rdi,%rsi
lea    0x2f07(%rip),%rbx
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1188 <get_token_n+0x68>
test   %ebp,%ebp
je     1176 <get_token_n+0x56>
cs nopw 0x0(%rax,%rax,1)
nop
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     118a <get_token_n+0x6a>
add    $0xffffffff,%ebp
jne    1160 <get_token_n+0x40>
mov    %r14,%rdi
mov    %rax,%rsi
call   1030 <strcpy@plt>
mov    $0x1,%ebx
jmp    118a <get_token_n+0x6a>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@get_token_n.tempstr = internal global [32768 x i8] zeroinitializer
define i32 @get_token_n(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %6
store i8* %1, i8** %7
store i32 %2, i32* %8
store i8* %3, i8** %9
%12 = load i8*, i8** %6
%13 = call i32 @strcpy(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @get_token_n.tempstr, i64 0, i64 0), i8* %12)
%14 = load i8*, i8** %7
%15 = call i8* @strtok(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @get_token_n.tempstr, i64 0, i64 0), i8* %14)
store i8* %15, i8** %10
store i32 0, i32* %11
br label %16
16: ; preds = %27, %4
%17 = load i8*, i8** %10
%18 = icmp ne i8* %17, null
br i1 %18, label %19, label %32
19: ; preds = %16
%20 = load i32, i32* %11
%21 = load i32, i32* %8
%22 = icmp eq i32 %20, %21
br i1 %22, label %23, label %27
23: ; preds = %19
%24 = load i8*, i8** %9
%25 = load i8*, i8** %10
%26 = call i32 @strcpy(i8* %24, i8* %25)
store i32 1, i32* %5
br label %33
27: ; preds = %19
%28 = load i8*, i8** %7
%29 = call i8* @strtok(i8* null, i8* %28)
store i8* %29, i8** %10
%30 = load i32, i32* %11
%31 = add nsw i32 %30, 1
store i32 %31, i32* %11
br label %16
32: ; preds = %16
store i32 0, i32* %5
br label %33
33: ; preds = %32, %23
%34 = load i32, i32* %5
ret i32 %34
}

LLVM IR (-O2):
@get_token_n.tempstr = internal global [32768 x i8] zeroinitializer
define i32 @get_token_n(i8* %0, i8* nocapture %1, i32 %2, i8* %3) {
%5 = tail call i32 @strcpy(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @get_token_n.tempstr, i64 0, i64 0), i8* %0)
%6 = tail call i8* @strtok(i8* getelementptr inbounds ([32768 x i8], [32768 x i8]* @get_token_n.tempstr, i64 0, i64 0), i8* %1)
%7 = icmp eq i8* %6, null
br i1 %7, label %20, label %8
8: ; preds = %4
%9 = icmp eq i32 %2, 0
br i1 %9, label %12, label %15
10: ; preds = %15
%11 = icmp eq i32 %18, %2
br i1 %11, label %12, label %15
12: ; preds = %10, %8
%13 = phi i8* [ %6, %8 ], [ %17, %10 ]
%14 = tail call i32 @strcpy(i8* %3, i8* %13)
br label %20
15: ; preds = %8, %10
%16 = phi i32 [ %18, %10 ], [ 0, %8 ]
%17 = tail call i8* @strtok(i8* null, i8* %1)
%18 = add nuw nsw i32 %16, 1
%19 = icmp eq i8* %17, null
br i1 %19, label %20, label %10
20: ; preds = %15, %4, %12
%21 = phi i32 [ 1, %12 ], [ 0, %4 ], [ 0, %15 ]
ret i32 %21
}