#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*/ debugPrint(char *);
int /*<<< orphan*/ debugPrintStr(char *, char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, int, char *);
int strlen(char *);
char *generateHTTPAuthHeader(char *page, char *host, int port,
                             char *authProperty) {
  char *request = 0;
  char *reqHeader = "GET %s HTTP/1.0\r\nUser-Agent:EKRClient\r\nHost: "
                    "%s:%d\r\nAuthorization: %s\r\n\r\n";
  int memSize = strlen(reqHeader) + strlen(page) + strlen(host) + 6 +
                strlen(authProperty);
  if (!(request = (char *)malloc(memSize))) {
    debugPrint(
        "connection : generateHTTPAuthHeader : memory allocation error ");
  }
  memset(request, 0, memSize);
  snprintf(request, memSize, reqHeader, page, host, port, authProperty);
  debugPrintStr("connection : generateHTTPHeader : header : ", request);
  return request;
}


x86 assembly (clang, -O0):
<generateHTTPAuthHeader>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %rcx,-0x20(%rbp)
movq   $0x0,-0x28(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x40(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x3c(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x3c(%rbp),%eax
add    %ecx,%eax
add    $0x6,%eax
mov    %eax,-0x38(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
add    %ecx,%eax
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
cmp    $0x0,%rax
jne    11f4 <generateHTTPAuthHeader+0x94>
lea    0xe5b(%rip),%rdi
call   1080 <debugPrint@plt>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x28(%rbp),%rdi
mov    -0x34(%rbp),%esi
mov    -0x30(%rbp),%rdx
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%r8
mov    -0x14(%rbp),%r9d
mov    -0x20(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <snprintf@plt>
mov    -0x28(%rbp),%rsi
lea    0xe58(%rip),%rdi
call   1030 <debugPrintStr@plt>
mov    -0x28(%rbp),%rax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<generateHTTPAuthHeader>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r13
mov    %edx,0x14(%rsp)
mov    %rsi,%r15
mov    %rdi,%r12
lea    0xe7e(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r12,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%r14d
mov    %r13,%rdi
call   1040 <strlen@plt>
add    %ebx,%ebp
add    %r14d,%ebp
lea    (%rax,%rbp,1),%ebx
add    $0x6,%ebx
mov    %ebx,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11cc <generateHTTPAuthHeader+0x6c>
lea    0xe83(%rip),%rdi
call   1080 <debugPrint@plt>
mov    %rbp,%rdi
xor    %esi,%esi
mov    %ebx,%edx
call   1060 <memset@plt>
mov    %r13,(%rsp)
lea    0xe1d(%rip),%rdx
mov    %rbp,%rdi
mov    %ebx,%esi
mov    %r12,%rcx
mov    %r15,%r8
mov    0x14(%rsp),%r9d
call   1050 <snprintf@plt>
lea    0xe8a(%rip),%rdi
mov    %rbp,%rsi
call   1030 <debugPrintStr@plt>
mov    %rbp,%rax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [74 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent:EKRClient\0D\0AHost: %s:%d\0D\0AAuthorization: %s\0D\0A\0D\0A\00"
@.str.1 = [63 x i8] c"connection : generateHTTPAuthHeader : memory allocation error \00"
@.str.2 = [44 x i8] c"connection : generateHTTPHeader : header : \00"
define i8* @generateHTTPAuthHeader(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32 %2, i32* %7
store i8* %3, i8** %8
store i8* null, i8** %9
store i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i8** %10
%12 = load i8*, i8** %10
%13 = call i32 @strlen(i8* %12)
%14 = load i8*, i8** %5
%15 = call i32 @strlen(i8* %14)
%16 = add nsw i32 %13, %15
%17 = load i8*, i8** %6
%18 = call i32 @strlen(i8* %17)
%19 = add nsw i32 %16, %18
%20 = add nsw i32 %19, 6
%21 = load i8*, i8** %8
%22 = call i32 @strlen(i8* %21)
%23 = add nsw i32 %20, %22
store i32 %23, i32* %11
%24 = load i32, i32* %11
%25 = call i64 @malloc(i32 %24)
%26 = inttoptr i64 %25 to i8*
store i8* %26, i8** %9
%27 = icmp ne i8* %26, null
br i1 %27, label %30, label %28
28: ; preds = %4
%29 = call i32 @debugPrint(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
br label %30
30: ; preds = %28, %4
%31 = load i8*, i8** %9
%32 = load i32, i32* %11
%33 = call i32 @memset(i8* %31, i32 0, i32 %32)
%34 = load i8*, i8** %9
%35 = load i32, i32* %11
%36 = load i8*, i8** %10
%37 = load i8*, i8** %5
%38 = load i8*, i8** %6
%39 = load i32, i32* %7
%40 = load i8*, i8** %8
%41 = call i32 @snprintf(i8* %34, i32 %35, i8* %36, i8* %37, i8* %38, i32 %39, i8* %40)
%42 = load i8*, i8** %9
%43 = call i32 @debugPrintStr(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %42)
%44 = load i8*, i8** %9
ret i8* %44
}

LLVM IR (-O2):
@.str = [74 x i8] c"GET %s HTTP/1.0\0D\0AUser-Agent:EKRClient\0D\0AHost: %s:%d\0D\0AAuthorization: %s\0D\0A\0D\0A\00"
@.str.1 = [63 x i8] c"connection : generateHTTPAuthHeader : memory allocation error \00"
@.str.2 = [44 x i8] c"connection : generateHTTPHeader : header : \00"
define i8* @generateHTTPAuthHeader(i8* %0, i8* %1, i32 %2, i8* %3) {
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @strlen(i8* %0)
%7 = tail call i32 @strlen(i8* %1)
%8 = tail call i32 @strlen(i8* %3)
%9 = add i32 %5, 6
%10 = add i32 %9, %6
%11 = add i32 %10, %7
%12 = add i32 %11, %8
%13 = tail call i64 @malloc(i32 %12)
%14 = inttoptr i64 %13 to i8*
%15 = icmp eq i64 %13, 0
br i1 %15, label %16, label %18
16: ; preds = %4
%17 = tail call i32 @debugPrint(i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.1, i64 0, i64 0))
br label %18
18: ; preds = %16, %4
%19 = tail call i32 @memset(i8* %14, i32 0, i32 %12)
%20 = tail call i32 @snprintf(i8* %14, i32 %12, i8* getelementptr inbounds ([74 x i8], [74 x i8]* @.str, i64 0, i64 0), i8* %0, i8* %1, i32 %2, i8* %3)
%21 = tail call i32 @debugPrintStr(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.2, i64 0, i64 0), i8* %14)
ret i8* %14
}