#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 */
typedef int uint32_t;

/* Variables and functions */
int /*<<< orphan*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
uint32_t HTTP_PostPkt(char *pkt, char *key, char *devid, char *dsid,
                      char *val) {
  char dataBuf[100] = {0};
  char lenBuf[10] = {0};
  *pkt = 0;
  sprintf(dataBuf, ",;%s,%s", dsid, val);
  sprintf(lenBuf, "%d", strlen(dataBuf));
  strcat(pkt, "POST /devices/");
  strcat(pkt, devid);
  strcat(pkt, "/datapoints?type=5 HTTP/1.1\r\n");
  strcat(pkt, "api-key:");
  strcat(pkt, key);
  strcat(pkt, "\r\n");
  strcat(pkt, "Host:api.heclouds.com\r\n");
  strcat(pkt, "Content-Length:");
  strcat(pkt, lenBuf);
  strcat(pkt, "\r\n\r\n");
  strcat(pkt, dataBuf);
  return strlen(pkt);
}


x86 assembly (clang, -O0):
<HTTP_PostPkt>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    %r8,-0x28(%rbp)
lea    -0x90(%rbp),%rdi
xor    %esi,%esi
mov    $0x64,%edx
call   1040 <memset@plt>
lea    -0x9a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    -0x8(%rbp),%rax
movb   $0x0,(%rax)
lea    -0x90(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    -0x28(%rbp),%rcx
lea    0xe5e(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
lea    -0x9a(%rbp),%rax
mov    %rax,-0xa8(%rbp)
lea    -0x90(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0xa8(%rbp),%rdi
mov    %eax,%edx
lea    0xe35(%rip),%rsi
mov    $0x0,%al
call   1060 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe18(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe26(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe02(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x9a(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    0xdfa(%rip),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x90(%rbp),%rsi
call   1050 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1030 <strlen@plt>
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<HTTP_PostPkt>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x80,%rsp
mov    %rdx,%r13
mov    %rsi,%r15
mov    %rdi,%rbx
xorps  %xmm0,%xmm0
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movl   $0x0,0x70(%rsp)
movw   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
movb   $0x0,(%rdi)
lea    0xe75(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %rcx,%rdx
mov    %r8,%rcx
xor    %eax,%eax
call   1050 <sprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
lea    0xe59(%rip),%rsi
mov    %rsp,%r12
mov    %r12,%rdi
mov    %eax,%edx
xor    %eax,%eax
call   1050 <sprintf@plt>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1040 <strcat@plt>
lea    0xe3b(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
lea    0xe4a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   1040 <strcat@plt>
lea    0xe63(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
lea    0xe2a(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
lea    0xe33(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1040 <strcat@plt>
lea    0xe29(%rip),%rsi
mov    %rbx,%rdi
call   1040 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <strcat@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
add    $0x80,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c",;%s,%s\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [15 x i8] c"POST /devices/\00"
@.str.3 = [30 x i8] c"/datapoints?type=5 HTTP/1.1\0D\0A\00"
@.str.4 = [9 x i8] c"api-key:\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@.str.6 = [24 x i8] c"Host:api.heclouds.com\0D\0A\00"
@.str.7 = [16 x i8] c"Content-Length:\00"
@.str.8 = [5 x i8] c"\0D\0A\0D\0A\00"
define i32 @HTTP_PostPkt(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca [100 x i8]
%12 = alloca [10 x i8]
store i8* %0, i8** %6
store i8* %1, i8** %7
store i8* %2, i8** %8
store i8* %3, i8** %9
store i8* %4, i8** %10
%13 = bitcast [100 x i8]* %11 to i8*
%14 = bitcast [10 x i8]* %12 to i8*
%15 = load i8*, i8** %6
store i8 0, i8* %15
%16 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%17 = load i8*, i8** %9
%18 = load i8*, i8** %10
%19 = call i32 (i8*, i8*, ...) @sprintf(i8* %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %17, i8* %18)
%20 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%22 = call i32 @strlen(i8* %21)
%23 = call i32 (i8*, i8*, ...) @sprintf(i8* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %22)
%24 = load i8*, i8** %6
%25 = call i32 @strcat(i8* %24, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%26 = load i8*, i8** %6
%27 = load i8*, i8** %8
%28 = call i32 @strcat(i8* %26, i8* %27)
%29 = load i8*, i8** %6
%30 = call i32 @strcat(i8* %29, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%31 = load i8*, i8** %6
%32 = call i32 @strcat(i8* %31, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%33 = load i8*, i8** %6
%34 = load i8*, i8** %7
%35 = call i32 @strcat(i8* %33, i8* %34)
%36 = load i8*, i8** %6
%37 = call i32 @strcat(i8* %36, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%38 = load i8*, i8** %6
%39 = call i32 @strcat(i8* %38, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%40 = load i8*, i8** %6
%41 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%42 = load i8*, i8** %6
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %12, i64 0, i64 0
%44 = call i32 @strcat(i8* %42, i8* %43)
%45 = load i8*, i8** %6
%46 = call i32 @strcat(i8* %45, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%47 = load i8*, i8** %6
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %11, i64 0, i64 0
%49 = call i32 @strcat(i8* %47, i8* %48)
%50 = load i8*, i8** %6
%51 = call i32 @strlen(i8* %50)
ret i32 %51
}

LLVM IR (-O2):
@.str = [8 x i8] c",;%s,%s\00"
@.str.1 = [3 x i8] c"%d\00"
@.str.2 = [15 x i8] c"POST /devices/\00"
@.str.3 = [30 x i8] c"/datapoints?type=5 HTTP/1.1\0D\0A\00"
@.str.4 = [9 x i8] c"api-key:\00"
@.str.5 = [3 x i8] c"\0D\0A\00"
@.str.6 = [24 x i8] c"Host:api.heclouds.com\0D\0A\00"
@.str.7 = [16 x i8] c"Content-Length:\00"
@.str.8 = [5 x i8] c"\0D\0A\0D\0A\00"
define i32 @HTTP_PostPkt(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4) {
%6 = alloca [100 x i8]
%7 = alloca [10 x i8]
%8 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
store i8 0, i8* %0
%10 = call i32 (i8*, i8*, ...) @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %3, i8* %4)
%11 = call i32 @strlen(i8* %8)
%12 = call i32 (i8*, i8*, ...) @sprintf(i8* %9, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %11)
%13 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%14 = call i32 @strcat(i8* %0, i8* %2)
%15 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.3, i64 0, i64 0))
%16 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.4, i64 0, i64 0))
%17 = call i32 @strcat(i8* %0, i8* %1)
%18 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.5, i64 0, i64 0))
%19 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.6, i64 0, i64 0))
%20 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.7, i64 0, i64 0))
%21 = call i32 @strcat(i8* %0, i8* %9)
%22 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.8, i64 0, i64 0))
%23 = call i32 @strcat(i8* %0, i8* %8)
%24 = call i32 @strlen(i8* %0)
ret i32 %24
}