#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 */
scalar_t__ strcmp(char *, char *);
char *strtok(char *, char *);
char *sessionFromHeader(char *header_str) {
  char *ret;
  char *delim = " =";
  ret = strtok(header_str, delim);
  while (ret != NULL) {
    if (strcmp(ret, "eserv_session") == 0) {
      ret = strtok(NULL, delim);
      break;
    }
    ret = strtok(NULL, delim);
  }
  return ret;
}


x86 assembly (clang, -O0):
<sessionFromHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    0xecd(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1199 <sessionFromHeader+0x79>
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1030 <strcmp@plt>
cmp    $0x0,%rax
jne    1183 <sessionFromHeader+0x63>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
jmp    1199 <sessionFromHeader+0x79>
mov    -0x18(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
call   1040 <strtok@plt>
mov    %rax,-0x10(%rbp)
jmp    1148 <sessionFromHeader+0x28>
mov    -0x10(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sessionFromHeader>:
push   %r15
push   %r14
push   %rbx
lea    0xed4(%rip),%rsi
call   1040 <strtok@plt>
test   %rax,%rax
je     1172 <sessionFromHeader+0x52>
lea    0xec6(%rip),%r14
lea    0xebc(%rip),%r15
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rax,%rdi
mov    %r14,%rsi
call   1030 <strcmp@plt>
mov    %rax,%rbx
xor    %edi,%edi
mov    %r15,%rsi
call   1040 <strtok@plt>
test   %rbx,%rbx
je     1174 <sessionFromHeader+0x54>
test   %rax,%rax
jne    1150 <sessionFromHeader+0x30>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c" =\00"
@.str.1 = [14 x i8] c"eserv_session\00"
define i8* @sessionFromHeader(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %2
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = load i8*, i8** %2
%6 = load i8*, i8** %4
%7 = call i8* @strtok(i8* %5, i8* %6)
store i8* %7, i8** %3
br label %8
8: ; preds = %18, %1
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i8*, i8** %3
%13 = call i64 @strcmp(i8* %12, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i8*, i8** %4
%17 = call i8* @strtok(i8* null, i8* %16)
store i8* %17, i8** %3
br label %21
18: ; preds = %11
%19 = load i8*, i8** %4
%20 = call i8* @strtok(i8* null, i8* %19)
store i8* %20, i8** %3
br label %8
21: ; preds = %15, %8
%22 = load i8*, i8** %3
ret i8* %22
}

LLVM IR (-O2):
@.str = [3 x i8] c" =\00"
@.str.1 = [14 x i8] c"eserv_session\00"
define i8* @sessionFromHeader(i8* %0) {
%2 = tail call i8* @strtok(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %11, label %4
4: ; preds = %1, %9
%5 = phi i8* [ %8, %9 ], [ %2, %1 ]
%6 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%7 = icmp eq i64 %6, 0
%8 = tail call i8* @strtok(i8* null, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
br i1 %7, label %11, label %9
9: ; preds = %4
%10 = icmp eq i8* %8, null
br i1 %10, label %11, label %4
11: ; preds = %9, %4, %1
%12 = phi i8* [ null, %1 ], [ %8, %4 ], [ null, %9 ]
ret i8* %12
}