#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 /*<<< orphan*/ sqlite3;

/* Variables and functions */
int SQLITE_OK;
int /*<<< orphan*/ free(char *);
char *malloc(int);
int snprintf(int /*<<< orphan*/ *, int /*<<< orphan*/, char const *, int, float,
             int);
int /*<<< orphan*/ sprintf(char *, char const *, int, float, int);
int sqlite3_exec(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *,
                 int /*<<< orphan*/, char **);
int /*<<< orphan*/ sqlite3_free(char *);
int addTemp(sqlite3 *db, int timestamp, float val, int sensor) {
  int rc;
  char *sql;
  char *zErrMsg = 0;
  const char *query = "INSERT INTO TEMPERATURE_HISTORY (TIMESTAMP,TEMPERATURE, "
                      "SENSOR) VALUES (%d, %f, %d);";
  int queryLen = snprintf(NULL, 0, query, timestamp, val, sensor);
  sql = malloc(queryLen + 1);
  sprintf(sql, query, timestamp, val, sensor);
  rc = sqlite3_exec(db, sql, NULL, 0, &zErrMsg);
  if (rc != SQLITE_OK) {
    sqlite3_free(zErrMsg);
    free(sql);
    return 0;
  }
  free(sql);
  return 1;
}


x86 assembly (clang, -O0):
<addTemp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
movss  %xmm0,-0x18(%rbp)
mov    %edx,-0x1c(%rbp)
movq   $0x0,-0x30(%rbp)
lea    0xe7a(%rip),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdx
mov    -0x14(%rbp),%ecx
movss  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%r8d
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <snprintf@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    -0x14(%rbp),%edx
movss  -0x18(%rbp),%xmm0
mov    -0x1c(%rbp),%ecx
call   1080 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
xor    %ecx,%ecx
lea    -0x30(%rbp),%r8
call   1040 <sqlite3_exec@plt>
mov    %eax,-0x20(%rbp)
mov    -0x20(%rbp),%eax
mov    0x2df5(%rip),%rcx
cmp    (%rcx),%eax
je     1219 <addTemp+0xb9>
mov    -0x30(%rbp),%rdi
call   1070 <sqlite3_free@plt>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1229 <addTemp+0xc9>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addTemp>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edx,%r15d
movss  %xmm0,0x4(%rsp)
mov    %esi,%ebp
mov    %rdi,%r14
movq   $0x0,0x8(%rsp)
lea    0xe76(%rip),%r12
xor    %edi,%edi
xor    %esi,%esi
mov    %r12,%rdx
mov    %ebp,%ecx
mov    %r15d,%r8d
call   1050 <snprintf@plt>
lea    0x1(%rax),%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
movss  0x4(%rsp),%xmm0
mov    %r15d,%ecx
call   1080 <sprintf@plt>
lea    0x8(%rsp),%r8
mov    %r14,%rdi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1040 <sqlite3_exec@plt>
mov    0x2e11(%rip),%rcx
mov    $0x1,%ebp
cmp    (%rcx),%eax
je     11ec <addTemp+0x8c>
mov    0x8(%rsp),%rdi
call   1070 <sqlite3_free@plt>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %ebp,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [85 x i8] c"INSERT INTO TEMPERATURE_HISTORY (TIMESTAMP,TEMPERATURE, SENSOR) VALUES (%d, %f, %d);\00"
@SQLITE_OK = global i32 0
define i32 @addTemp(i32* %0, i32 %1, float %2, i32 %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i32
%8 = alloca float
%9 = alloca i32
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i32
store i32* %0, i32** %6
store i32 %1, i32* %7
store float %2, float* %8
store i32 %3, i32* %9
store i8* null, i8** %12
store i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0), i8** %13
%15 = load i8*, i8** %13
%16 = load i32, i32* %7
%17 = load float, float* %8
%18 = load i32, i32* %9
%19 = call i32 @snprintf(i32* null, i32 0, i8* %15, i32 %16, float %17, i32 %18)
store i32 %19, i32* %14
%20 = load i32, i32* %14
%21 = add nsw i32 %20, 1
%22 = call i8* @malloc(i32 %21)
store i8* %22, i8** %11
%23 = load i8*, i8** %11
%24 = load i8*, i8** %13
%25 = load i32, i32* %7
%26 = load float, float* %8
%27 = load i32, i32* %9
%28 = call i32 @sprintf(i8* %23, i8* %24, i32 %25, float %26, i32 %27)
%29 = load i32*, i32** %6
%30 = load i8*, i8** %11
%31 = call i32 @sqlite3_exec(i32* %29, i8* %30, i32* null, i32 0, i8** %12)
store i32 %31, i32* %10
%32 = load i32, i32* %10
%33 = load i32, i32* @SQLITE_OK
%34 = icmp ne i32 %32, %33
br i1 %34, label %35, label %40
35: ; preds = %4
%36 = load i8*, i8** %12
%37 = call i32 @sqlite3_free(i8* %36)
%38 = load i8*, i8** %11
%39 = call i32 @free(i8* %38)
store i32 0, i32* %5
br label %43
40: ; preds = %4
%41 = load i8*, i8** %11
%42 = call i32 @free(i8* %41)
store i32 1, i32* %5
br label %43
43: ; preds = %40, %35
%44 = load i32, i32* %5
ret i32 %44
}

LLVM IR (-O2):
@.str = [85 x i8] c"INSERT INTO TEMPERATURE_HISTORY (TIMESTAMP,TEMPERATURE, SENSOR) VALUES (%d, %f, %d);\00"
@SQLITE_OK = global i32 0
define i32 @addTemp(i32* %0, i32 %1, float %2, i32 %3) {
%5 = alloca i8*
%6 = bitcast i8** %5 to i8*
store i8* null, i8** %5
%7 = tail call i32 @snprintf(i32* null, i32 0, i8* getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0), i32 %1, float %2, i32 %3)
%8 = add nsw i32 %7, 1
%9 = tail call i8* @malloc(i32 %8)
%10 = tail call i32 @sprintf(i8* dereferenceable(1) %9, i8* dereferenceable(1) getelementptr inbounds ([85 x i8], [85 x i8]* @.str, i64 0, i64 0), i32 %1, float %2, i32 %3)
%11 = call i32 @sqlite3_exec(i32* %0, i8* %9, i32* null, i32 0, i8** %5)
%12 = load i32, i32* @SQLITE_OK
%13 = icmp eq i32 %11, %12
br i1 %13, label %17, label %14
14: ; preds = %4
%15 = load i8*, i8** %5
%16 = call i32 @sqlite3_free(i8* %15)
br label %17
17: ; preds = %4, %14
%18 = phi i32 [ 0, %14 ], [ 1, %4 ]
%19 = call i32 @free(i8* %9)
ret i32 %18
}