#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 sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
int prepare_request(char *buffer, int buflen, const char *host, int port,
                    const char *path, int temp) {
  char line[128];
  sprintf(buffer, "POST %s HTTP/1.1\r\n", path);
  sprintf(line, "Host: %s:%d\r\n", host, port);
  strcat(buffer, line);
  strcat(buffer, "User-Agent: CC3220\r\n"
                 "Accept: */*\r\n"
                 "Content-Type: application/x-www-form-urlencoded\r\n");
  sprintf(line, "Content-Length: %d\r\n", sprintf(line, "temp=%d", temp));
  strcat(buffer, line);
  strcat(buffer, "\r\n");
  sprintf(line, "temp=%d", temp);
  strcat(buffer, line);
  return strlen(buffer);
}


x86 assembly (clang, -O0):
<prepare_request>:
push   %rbp
mov    %rsp,%rbp
sub    $0xc0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xea0(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
lea    0xe97(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcat@plt>
lea    -0xb0(%rbp),%rax
mov    %rax,-0xb8(%rbp)
lea    -0xb0(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xec7(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0xb8(%rbp),%rdi
mov    %eax,%edx
lea    0xe9b(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe15(%rip),%rsi
call   1040 <strcat@plt>
lea    -0xb0(%rbp),%rdi
mov    -0x2c(%rbp),%edx
lea    0xe78(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0xb0(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0xc0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_request>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %r9d,%r14d
mov    %ecx,%r15d
mov    %rdx,%r12
mov    %rdi,%rbx
lea    0xeae(%rip),%rsi
mov    %r8,%rdx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xeb0(%rip),%rsi
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    %r12,%rdx
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcat@plt>
lea    0xe99(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
lea    0xef2(%rip),%r15
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xec6(%rip),%rsi
mov    %rbp,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcat@plt>
lea    0xe44(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %r14d,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1040 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"POST %s HTTP/1.1\0D\0A\00"
@.str.1 = [14 x i8] c"Host: %s:%d\0D\0A\00"
@.str.2 = [83 x i8] c"User-Agent: CC3220\0D\0AAccept: */*\0D\0AContent-Type: application/x-www-form-urlencoded\0D\0A\00"
@.str.3 = [21 x i8] c"Content-Length: %d\0D\0A\00"
@.str.4 = [8 x i8] c"temp=%d\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
define i32 @prepare_request(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32
%13 = alloca [128 x i8]
store i8* %0, i8** %7
store i32 %1, i32* %8
store i8* %2, i8** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i32 %5, i32* %12
%14 = load i8*, i8** %7
%15 = load i8*, i8** %11
%16 = call i32 (i8*, i8*, ...) @sprintf(i8* %14, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %15)
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%18 = load i8*, i8** %9
%19 = load i32, i32* %10
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %18, i32 %19)
%21 = load i8*, i8** %7
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = load i8*, i8** %7
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.2, i64 0, i64 0))
%26 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%27 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%28 = load i32, i32* %12
%29 = call i32 (i8*, i8*, ...) @sprintf(i8* %27, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %28)
%30 = call i32 (i8*, i8*, ...) @sprintf(i8* %26, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %29)
%31 = load i8*, i8** %7
%32 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%33 = call i32 @strcat(i8* %31, i8* %32)
%34 = load i8*, i8** %7
%35 = call i32 @strcat(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%36 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%37 = load i32, i32* %12
%38 = call i32 (i8*, i8*, ...) @sprintf(i8* %36, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %37)
%39 = load i8*, i8** %7
%40 = getelementptr inbounds [128 x i8], [128 x i8]* %13, i64 0, i64 0
%41 = call i32 @strcat(i8* %39, i8* %40)
%42 = load i8*, i8** %7
%43 = call i32 @strlen(i8* %42)
ret i32 %43
}

LLVM IR (-O2):
@.str = [19 x i8] c"POST %s HTTP/1.1\0D\0A\00"
@.str.1 = [14 x i8] c"Host: %s:%d\0D\0A\00"
@.str.2 = [83 x i8] c"User-Agent: CC3220\0D\0AAccept: */*\0D\0AContent-Type: application/x-www-form-urlencoded\0D\0A\00"
@.str.3 = [21 x i8] c"Content-Length: %d\0D\0A\00"
@.str.4 = [8 x i8] c"temp=%d\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
define i32 @prepare_request(i8* %0, i32 %1, i8* %2, i32 %3, i8* %4, i32 %5) {
%7 = alloca [128 x i8]
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%9 = tail call i32 (i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), i8* %4)
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i8* %2, i32 %3)
%11 = call i32 @strcat(i8* %0, i8* %8)
%12 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([83 x i8], [83 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %5)
%14 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.3, i64 0, i64 0), i32 %13)
%15 = call i32 @strcat(i8* %0, i8* %8)
%16 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%17 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0), i32 %5)
%18 = call i32 @strcat(i8* %0, i8* %8)
%19 = call i32 @strlen(i8* %0)
ret i32 %19
}