#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 *malloc(int);
int /*<<< orphan*/ memcpy(char *, char *, int);
char *strstr(char *, char *);
char *get_header_token(char *response) {
  char *t_header = strstr(response, "x-kahoot-session-token:");
  if (t_header == NULL) {
    return NULL;
  } else {
    t_header = t_header + 24;
    char *token = malloc(129);
    memcpy(token, t_header, 128);
    token[128] = '\0';
    return token;
  }
}


x86 assembly (clang, -O0):
<get_header_token>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xeb9(%rip),%rsi
call   1050 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1168 <get_header_token+0x38>
movq   $0x0,-0x8(%rbp)
jmp    11a7 <get_header_token+0x77>
mov    -0x18(%rbp),%rax
add    $0x18,%rax
mov    %rax,-0x18(%rbp)
mov    $0x81,%edi
call   1040 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x80,%edx
call   1030 <memcpy@plt>
mov    -0x20(%rbp),%rax
movb   $0x0,0x80(%rax)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_header_token>:
push   %r14
push   %rbx
push   %rax
lea    0xec5(%rip),%rsi
call   1050 <strstr@plt>
test   %rax,%rax
je     1173 <get_header_token+0x43>
mov    %rax,%rbx
add    $0x18,%rbx
mov    $0x81,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
mov    %rax,%rdi
mov    %rbx,%rsi
mov    $0x80,%edx
call   1030 <memcpy@plt>
movb   $0x0,0x80(%r14)
jmp    1176 <get_header_token+0x46>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

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

LLVM IR (-O2):
@.str = [24 x i8] c"x-kahoot-session-token:\00"
define i8* @get_header_token(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %9, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 24
%6 = tail call dereferenceable_or_null(129) i8* @malloc(i32 129)
%7 = tail call i32 @memcpy(i8* %6, i8* %5, i32 128)
%8 = getelementptr inbounds i8, i8* %6, i64 128
store i8 0, i8* %8
br label %9
9: ; preds = %1, %4
%10 = phi i8* [ %6, %4 ], [ null, %1 ]
ret i8* %10
}