#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*/ strncpy(char *, char *, int);
char *strtok_r(char *, char *, char **);
int httpParser_GetRequestLines(char *message, char linesBuffer[][(8192)],
                               const size_t linesBufferLen, char **saveState) {
  char *result = NULL;
  int linesParsed = 0;
  result = strtok_r(message, "\n", saveState);
  if (result) {
    do {
      if (linesParsed >= linesBufferLen) {
        break;
      }
      strncpy(linesBuffer[linesParsed], result, (8192));
      ++linesParsed;
      result = strtok_r(NULL, "\n", saveState);
    } while (result);
  }
  return linesParsed;
}


x86 assembly (clang, -O0):
<httpParser_GetRequestLines>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x20(%rbp),%rdx
lea    0xeaa(%rip),%rsi
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     11d0 <httpParser_GetRequestLines+0xb0>
jmp    116f <httpParser_GetRequestLines+0x4f>
movslq -0x2c(%rbp),%rax
cmp    -0x18(%rbp),%rax
jb     1182 <httpParser_GetRequestLines+0x62>
jmp    11cb <httpParser_GetRequestLines+0xab>
mov    -0x10(%rbp),%rdi
movslq -0x2c(%rbp),%rax
shl    $0xd,%rax
add    %rax,%rdi
mov    -0x28(%rbp),%rsi
mov    $0x2000,%edx
call   1030 <strncpy@plt>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
lea    0xe49(%rip),%rsi
call   1040 <strtok_r@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    116f <httpParser_GetRequestLines+0x4f>
jmp    11d0 <httpParser_GetRequestLines+0xb0>
mov    -0x2c(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<httpParser_GetRequestLines>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%r12
lea    0xec7(%rip),%rsi
mov    %rcx,%rdx
call   1040 <strtok_r@plt>
xor    %ebx,%ebx
test   %rax,%rax
je     1187 <httpParser_GetRequestLines+0x67>
lea    0xeb1(%rip),%r13
nop
cmp    %rbx,%r14
je     1184 <httpParser_GetRequestLines+0x64>
mov    %r12,%rdi
mov    %rax,%rsi
mov    $0x2000,%edx
call   1030 <strncpy@plt>
add    $0x1,%rbx
xor    %edi,%edi
mov    %r13,%rsi
mov    %r15,%rdx
call   1040 <strtok_r@plt>
add    $0x2000,%r12
test   %rax,%rax
jne    1150 <httpParser_GetRequestLines+0x30>
jmp    1187 <httpParser_GetRequestLines+0x67>
mov    %r14,%rbx
mov    %ebx,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"\0A\00"
define i32 @httpParser_GetRequestLines(i8* %0, [8192 x i8]* %1, i64 %2, i8** %3) {
%5 = tail call i8* @strtok_r(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %20, label %7
7: ; preds = %4, %11
%8 = phi i64 [ %14, %11 ], [ 0, %4 ]
%9 = phi i8* [ %15, %11 ], [ %5, %4 ]
%10 = icmp eq i64 %8, %2
br i1 %10, label %17, label %11
11: ; preds = %7
%12 = getelementptr inbounds [8192 x i8], [8192 x i8]* %1, i64 %8, i64 0
%13 = tail call i32 @strncpy(i8* %12, i8* %9, i32 8192)
%14 = add nuw i64 %8, 1
%15 = tail call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i8** %3)
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %7
17: ; preds = %7, %11
%18 = phi i64 [ %2, %7 ], [ %14, %11 ]
%19 = trunc i64 %18 to i32
br label %20
20: ; preds = %17, %4
%21 = phi i32 [ 0, %4 ], [ %19, %17 ]
ret i32 %21
}