#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*/ sprintf(char *, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
void db_generate_statement_insert(char *sql_statement, int obd_data_elements) {
  sprintf(sql_statement, "INSERT INTO OBD VALUES (NULL");
  strcat(sql_statement, ", @col1, @col2, @col3, @col4, @col5, @col6");
  for (int i = 0; i < obd_data_elements; i++) {
    char tmp_string[255] = {0};
    sprintf(tmp_string, ", @col%d", 7 + i);
    strcat(sql_statement, tmp_string);
  }
  strcat(sql_statement, ");");
  return;
}


x86 assembly (clang, -O0):
<db_generate_statement_insert>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xeb3(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    0xebe(%rip),%rsi
call   1040 <strcat@plt>
movl   $0x0,-0x10(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    11c3 <db_generate_statement_insert+0x93>
lea    -0x110(%rbp),%rdi
xor    %esi,%esi
mov    $0xff,%edx
call   1030 <memset@plt>
lea    -0x110(%rbp),%rdi
mov    -0x10(%rbp),%edx
add    $0x7,%edx
lea    0xeaa(%rip),%rsi
mov    $0x0,%al
call   1050 <sprintf@plt>
mov    -0x8(%rbp),%rdi
lea    -0x110(%rbp),%rsi
call   1040 <strcat@plt>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    116b <db_generate_statement_insert+0x3b>
mov    -0x8(%rbp),%rdi
lea    0xe83(%rip),%rsi
call   1040 <strcat@plt>
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<db_generate_statement_insert>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x100,%rsp
mov    %esi,%r14d
mov    %rdi,%r15
movups 0xed0(%rip),%xmm0
movups %xmm0,0xd(%rdi)
movups 0xeb8(%rip),%xmm0
movups %xmm0,(%rdi)
lea    0xecb(%rip),%rsi
call   1030 <strcat@plt>
test   %r14d,%r14d
jle    121b <db_generate_statement_insert+0xfb>
neg    %r14d
mov    $0x7,%ebx
lea    0xed9(%rip),%r12
mov    %rsp,%r13
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
xorps  %xmm0,%xmm0
movups %xmm0,0xef(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
movaps %xmm0,0x10(%rsp)
movaps %xmm0,(%rsp)
mov    %r13,%rdi
mov    %r12,%rsi
mov    %ebx,%edx
xor    %eax,%eax
call   1040 <sprintf@plt>
mov    %r15,%rdi
mov    %r13,%rsi
call   1030 <strcat@plt>
lea    (%r14,%rbx,1),%eax
add    $0x1,%eax
mov    %ebx,%ecx
add    $0x1,%ecx
mov    %ecx,%ebx
cmp    $0x7,%eax
jne    1180 <db_generate_statement_insert+0x60>
lea    0xe2f(%rip),%rsi
mov    %r15,%rdi
call   1030 <strcat@plt>
add    $0x100,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [29 x i8] c"INSERT INTO OBD VALUES (NULL\00"
@.str.1 = [43 x i8] c", @col1, @col2, @col3, @col4, @col5, @col6\00"
@.str.2 = [9 x i8] c", @col%d\00"
@.str.3 = [3 x i8] c");\00"
define void @db_generate_statement_insert(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
%6 = alloca [255 x i8]
store i8* %0, i8** %3
store i32 %1, i32* %4
%7 = load i8*, i8** %3
%8 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0))
%9 = load i8*, i8** %3
%10 = call i32 @strcat(i8* %9, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %5
br label %11
11: ; preds = %24, %2
%12 = load i32, i32* %5
%13 = load i32, i32* %4
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %27
15: ; preds = %11
%16 = bitcast [255 x i8]* %6 to i8*
%17 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* %5
%19 = add nsw i32 7, %18
%20 = call i32 (i8*, i8*, ...) @sprintf(i8* %17, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %3
%22 = getelementptr inbounds [255 x i8], [255 x i8]* %6, i64 0, i64 0
%23 = call i32 @strcat(i8* %21, i8* %22)
br label %24
24: ; preds = %15
%25 = load i32, i32* %5
%26 = add nsw i32 %25, 1
store i32 %26, i32* %5
br label %11
27: ; preds = %11
%28 = load i8*, i8** %3
%29 = call i32 @strcat(i8* %28, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
}

LLVM IR (-O2):
@.str = [29 x i8] c"INSERT INTO OBD VALUES (NULL\00"
@.str.1 = [43 x i8] c", @col1, @col2, @col3, @col4, @col5, @col6\00"
@.str.2 = [9 x i8] c", @col%d\00"
@.str.3 = [3 x i8] c");\00"
define void @db_generate_statement_insert(i8* %0, i32 %1) {
%3 = alloca [255 x i8]
tail call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 1 dereferenceable(29) %0, i8* align 1 dereferenceable(29) getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i64 29, i1 false)
%4 = tail call i32 @strcat(i8* %0, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp sgt i32 %1, 0
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = getelementptr inbounds [255 x i8], [255 x i8]* %3, i64 0, i64 0
br label %10
8: ; preds = %10, %2
%9 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
ret void
10: ; preds = %6, %10
%11 = phi i32 [ 0, %6 ], [ %15, %10 ]
%12 = add nuw nsw i32 %11, 7
%13 = call i32 (i8*, i8*, ...) @sprintf(i8* %7, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = call i32 @strcat(i8* %0, i8* %7)
%15 = add nuw nsw i32 %11, 1
%16 = icmp eq i32 %15, %1
br i1 %16, label %8, label %10
}