#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*/ free(char *);
char *strchr(char *, char);
char *strdup(char *);
char *strstr(char *, char *);
char *getlcookie(char *cookie) {
  char *tmp;
  char *tmpend;
  char *login_cookie = NULL;
  tmpend = strstr(cookie, "n=");
  if (tmpend) {
    tmp = strdup(tmpend + 2);
    tmpend = strchr(tmp, '&');
    if (tmpend)
      *tmpend = '\0';
    login_cookie = strdup(tmp);
    if (tmp) {
      free(tmp);
      tmp = NULL;
    };
  }
  return login_cookie;
}


x86 assembly (clang, -O0):
<getlcookie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea1(%rip),%rsi
call   1060 <strstr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11d6 <getlcookie+0x96>
mov    -0x18(%rbp),%rdi
add    $0x2,%rdi
call   1050 <strdup@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    $0x26,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11a8 <getlcookie+0x68>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
call   1050 <strdup@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11d1 <getlcookie+0x91>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x10(%rbp)
jmp    11d6 <getlcookie+0x96>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getlcookie>:
push   %r14
push   %rbx
push   %rax
lea    0xeb5(%rip),%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1193 <getlcookie+0x53>
add    $0x2,%rax
mov    %rax,%rdi
call   1050 <strdup@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x26,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     1179 <getlcookie+0x39>
movb   $0x0,(%rax)
mov    %rbx,%rdi
call   1050 <strdup@plt>
mov    %rax,%r14
test   %rbx,%rbx
je     1196 <getlcookie+0x56>
mov    %rbx,%rdi
call   1030 <free@plt>
jmp    1196 <getlcookie+0x56>
xor    %r14d,%r14d
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"n=\00"
define i8* @getlcookie(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %5
%6 = load i8*, i8** %2
%7 = call i8* @strstr(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %7, i8** %4
%8 = load i8*, i8** %4
%9 = icmp ne i8* %8, null
br i1 %9, label %10, label %29
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = getelementptr inbounds i8, i8* %11, i64 2
%13 = call i8* @strdup(i8* %12)
store i8* %13, i8** %3
%14 = load i8*, i8** %3
%15 = call i8* @strchr(i8* %14, i8 signext 38)
store i8* %15, i8** %4
%16 = load i8*, i8** %4
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = load i8*, i8** %4
store i8 0, i8* %19
br label %20
20: ; preds = %18, %10
%21 = load i8*, i8** %3
%22 = call i8* @strdup(i8* %21)
store i8* %22, i8** %5
%23 = load i8*, i8** %3
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %28
25: ; preds = %20
%26 = load i8*, i8** %3
%27 = call i32 @free(i8* %26)
store i8* null, i8** %3
br label %28
28: ; preds = %25, %20
br label %29
29: ; preds = %28, %1
%30 = load i8*, i8** %5
ret i8* %30
}

LLVM IR (-O2):
@.str = [3 x i8] c"n=\00"
define noalias i8* @getlcookie(i8* %0) {
%2 = tail call i8* @strstr(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i8* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1
%5 = getelementptr inbounds i8, i8* %2, i64 2
%6 = tail call i8* @strdup(i8* %5)
%7 = tail call i8* @strchr(i8* dereferenceable(1) %6, i8 signext 38)
%8 = icmp eq i8* %7, null
br i1 %8, label %10, label %9
9: ; preds = %4
store i8 0, i8* %7
br label %10
10: ; preds = %9, %4
%11 = tail call i8* @strdup(i8* %6)
%12 = icmp eq i8* %6, null
br i1 %12, label %15, label %13
13: ; preds = %10
%14 = tail call i32 @free(i8* %6)
br label %15
15: ; preds = %10, %13, %1
%16 = phi i8* [ %11, %13 ], [ %11, %10 ], [ null, %1 ]
ret i8* %16
}