#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 *cgiurlencode(char const *);
int /*<<< orphan*/ free(char *);
char *getenv(char *);
int /*<<< orphan*/ printf(char *, char const *, char const *, char const *);
void cgi_setcookie(const char *name, const char *value) {
  char *p;
  const char *sn;
  p = cgiurlencode(value);
  sn = getenv("SCRIPT_NAME");
  if (!sn || !*sn)
    sn = "/";
  printf("Set-Cookie: %s=%s; path=%s\n", name, value, sn);
  free(p);
}


x86 assembly (clang, -O0):
<cgi_setcookie>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <cgiurlencode@plt>
mov    %rax,-0x18(%rbp)
lea    0xe9c(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1185 <cgi_setcookie+0x45>
mov    -0x20(%rbp),%rax
cmpb   $0x0,(%rax)
jne    1190 <cgi_setcookie+0x50>
lea    0xe80(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rdx
mov    -0x20(%rbp),%rcx
lea    0xe6b(%rip),%rdi
call   1060 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <free@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cgi_setcookie>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r15
mov    %rsi,%rdi
call   1050 <cgiurlencode@plt>
mov    %rax,%r14
lea    0xea3(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     116c <cgi_setcookie+0x2c>
cmpb   $0x0,(%rax)
jne    1173 <cgi_setcookie+0x33>
lea    0xe99(%rip),%rax
lea    0xe94(%rip),%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
mov    %rax,%rcx
call   1060 <printf@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <free@plt>

LLVM IR (-O0):
@.str = [12 x i8] c"SCRIPT_NAME\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [28 x i8] c"Set-Cookie: %s=%s; path=%s\0A\00"
define void @cgi_setcookie(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %4
%8 = call i8* @cgiurlencode(i8* %7)
store i8* %8, i8** %5
%9 = call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i8* %9, i8** %6
%10 = load i8*, i8** %6
%11 = icmp ne i8* %10, null
br i1 %11, label %12, label %16
12: ; preds = %2
%13 = load i8*, i8** %6
%14 = load i8, i8* %13
%15 = icmp ne i8 %14, 0
br i1 %15, label %17, label %16
16: ; preds = %12, %2
store i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %6
br label %17
17: ; preds = %16, %12
%18 = load i8*, i8** %3
%19 = load i8*, i8** %4
%20 = load i8*, i8** %6
%21 = call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %19, i8* %20)
%22 = load i8*, i8** %5
%23 = call i32 @free(i8* %22)
ret void
}

LLVM IR (-O2):
@.str = [12 x i8] c"SCRIPT_NAME\00"
@.str.1 = [2 x i8] c"/\00"
@.str.2 = [28 x i8] c"Set-Cookie: %s=%s; path=%s\0A\00"
define void @cgi_setcookie(i8* %0, i8* %1) {
%3 = tail call i8* @cgiurlencode(i8* %1)
%4 = tail call i8* @getenv(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i8* %4, null
br i1 %5, label %9, label %6
6: ; preds = %2
%7 = load i8, i8* %4
%8 = icmp eq i8 %7, 0
br i1 %8, label %9, label %10
9: ; preds = %6, %2
br label %10
10: ; preds = %9, %6
%11 = phi i8* [ %4, %6 ], [ getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), %9 ]
%12 = tail call i32 @printf(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* %1, i8* %11)
%13 = tail call i32 @free(i8* %3)
ret void
}