#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(scalar_t__);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ sprintf(char *, char *, char *, char *);
scalar_t__ strlen(char *);
void SETCOOKIE(char *value, int valid) {
  char *cookie;
  cookie = malloc(13 + strlen(value) + (valid ? 0 : 11));
  sprintf(cookie, "Set-Cookie: %s%s", value, valid ? "" : "; Max-Age=0");
  puts(cookie);
}


x86 assembly (clang, -O0):
<SETCOOKIE>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0xd,%rdi
mov    -0xc(%rbp),%edx
mov    $0xb,%eax
xor    %ecx,%ecx
cmp    $0x0,%edx
cmovne %ecx,%eax
cltq
add    %rax,%rdi
call   1050 <malloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0xc(%rbp),%esi
lea    0xe82(%rip),%rcx
lea    0xe86(%rip),%rax
cmp    $0x0,%esi
cmovne %rax,%rcx
lea    0xe5c(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <puts@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SETCOOKIE>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
call   1040 <strlen@plt>
lea    0xd(%rax),%rdi
add    $0x18,%rax
test   %ebp,%ebp
cmove  %rax,%rdi
lea    0xeae(%rip),%rax
lea    0xeb2(%rip),%rbp
cmove  %rax,%rbp
call   1050 <malloc@plt>
mov    %rax,%rbx
lea    0xe83(%rip),%rsi
mov    %rax,%rdi
mov    %r14,%rdx
mov    %rbp,%rcx
call   1060 <sprintf@plt>
mov    %rbx,%rdi
pop    %rbx
pop    %r14
pop    %rbp
jmp    1030 <puts@plt>

LLVM IR (-O0):
@.str = [17 x i8] c"Set-Cookie: %s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [12 x i8] c"; Max-Age=0\00"
define void @SETCOOKIE(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i8*
store i8* %0, i8** %3
store i32 %1, i32* %4
%6 = load i8*, i8** %3
%7 = call i64 @strlen(i8* %6)
%8 = add nsw i64 13, %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 0
%11 = zext i1 %10 to i64
%12 = select i1 %10, i32 0, i32 11
%13 = sext i32 %12 to i64
%14 = add nsw i64 %8, %13
%15 = call i8* @malloc(i64 %14)
store i8* %15, i8** %5
%16 = load i8*, i8** %5
%17 = load i8*, i8** %3
%18 = load i32, i32* %4
%19 = icmp ne i32 %18, 0
%20 = zext i1 %19 to i64
%21 = select i1 %19, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0)
%22 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %21)
%23 = load i8*, i8** %5
%24 = call i32 @puts(i8* %23)
ret void
}

LLVM IR (-O2):
@.str = [17 x i8] c"Set-Cookie: %s%s\00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [12 x i8] c"; Max-Age=0\00"
define void @SETCOOKIE(i8* %0, i32 %1) {
%3 = tail call i64 @strlen(i8* dereferenceable(1) %0)
%4 = icmp eq i32 %1, 0
%5 = select i1 %4, i64 24, i64 13
%6 = add i64 %5, %3
%7 = tail call i8* @malloc(i64 %6)
%8 = select i1 %4, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0)
%9 = tail call i32 @sprintf(i8* dereferenceable(1) %7, i8* dereferenceable(1) getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %8)
%10 = tail call i32 @puts(i8* dereferenceable(1) %7)
ret void
}