#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 *, char *, ...);
int construct_chords_route(char *route, char *labels[], float readings[],
                           int nvars, int instrument_id, int write_key_enabled,
                           char *chords_write_key, int is_test) {
  sprintf(route, "%s%s", route, "measurements/url_create?");
  sprintf(route, "%sinstrument_id=%d", route, instrument_id);
  int i = 0u;
  for (i = 0; i < nvars; i++) {
    if (labels[i] && labels[i][0]) {
      sprintf(route, "%s&%s=%f", route, labels[i], readings[i]);
    }
  }
  if (write_key_enabled) {
    sprintf(route, "%s&key=%s", route, chords_write_key);
  }
  if (is_test) {
    sprintf(route, "%s&test", route);
  }
  return 1u;
}


x86 assembly (clang, -O0):
<construct_chords_route>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%rax
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8d,-0x20(%rbp)
mov    %r9d,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xebb(%rip),%rsi
lea    0xeb9(%rip),%rcx
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x20(%rbp),%ecx
lea    0xeb9(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    11f7 <construct_chords_route+0xe7>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
cmpq   $0x0,(%rax,%rcx,8)
je     11e4 <construct_chords_route+0xd4>
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11e4 <construct_chords_route+0xd4>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    -0x10(%rbp),%rax
movslq -0x28(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
mov    -0x18(%rbp),%rax
movslq -0x28(%rbp),%rsi
movss  (%rax,%rsi,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xe54(%rip),%rsi
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    11e9 <construct_chords_route+0xd9>
mov    -0x28(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x28(%rbp)
jmp    117a <construct_chords_route+0x6a>
cmpl   $0x0,-0x24(%rbp)
je     121b <construct_chords_route+0x10b>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    0x10(%rbp),%rcx
lea    0xe26(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
cmpl   $0x0,0x18(%rbp)
je     123b <construct_chords_route+0x12b>
mov    -0x8(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1030 <sprintf@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<construct_chords_route>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r9d,0x4(%rsp)
mov    %r8d,%ebx
mov    %ecx,%r12d
mov    %rdx,%r15
mov    %rsi,%r13
mov    %rdi,%r14
lea    0xeca(%rip),%rsi
lea    0xec8(%rip),%rcx
mov    %rdi,%rdx
xor    %eax,%eax
call   1030 <sprintf@plt>
lea    0xed0(%rip),%rsi
mov    %r14,%rdi
mov    %r14,%rdx
mov    %ebx,%ecx
xor    %eax,%eax
call   1030 <sprintf@plt>
test   %r12d,%r12d
jle    11a4 <construct_chords_route+0x94>
mov    %r12d,%ebx
xor    %ebp,%ebp
lea    0xec3(%rip),%r12
jmp    1179 <construct_chords_route+0x69>
add    $0x1,%rbp
cmp    %rbp,%rbx
je     11a4 <construct_chords_route+0x94>
mov    0x0(%r13,%rbp,8),%rcx
test   %rcx,%rcx
je     1170 <construct_chords_route+0x60>
cmpb   $0x0,(%rcx)
je     1170 <construct_chords_route+0x60>
movss  (%r15,%rbp,4),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r14,%rdx
mov    $0x1,%al
call   1030 <sprintf@plt>
jmp    1170 <construct_chords_route+0x60>
mov    0x48(%rsp),%ebx
cmpl   $0x0,0x4(%rsp)
je     11c8 <construct_chords_route+0xb8>
mov    0x40(%rsp),%rcx
lea    0xe7f(%rip),%rsi
mov    %r14,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <sprintf@plt>
test   %ebx,%ebx
je     11e0 <construct_chords_route+0xd0>
lea    0xe71(%rip),%rsi
mov    %r14,%rdi
mov    %r14,%rdx
xor    %eax,%eax
call   1030 <sprintf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [25 x i8] c"measurements/url_create?\00"
@.str.2 = [19 x i8] c"%sinstrument_id=%d\00"
@.str.3 = [9 x i8] c"%s&%s=%f\00"
@.str.4 = [10 x i8] c"%s&key=%s\00"
@.str.5 = [8 x i8] c"%s&test\00"
define i32 @construct_chords_route(i8* %0, i8** %1, float* %2, i32 %3, i32 %4, i32 %5, i8* %6, i32 %7) {
%9 = alloca i8*
%10 = alloca i8**
%11 = alloca float*
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
store i8* %0, i8** %9
store i8** %1, i8*** %10
store float* %2, float** %11
store i32 %3, i32* %12
store i32 %4, i32* %13
store i32 %5, i32* %14
store i8* %6, i8** %15
store i32 %7, i32* %16
%18 = load i8*, i8** %9
%19 = load i8*, i8** %9
%20 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %18, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%21 = load i8*, i8** %9
%22 = load i8*, i8** %9
%23 = load i32, i32* %13
%24 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %21, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %22, i32 %23)
store i32 0, i32* %17
store i32 0, i32* %17
br label %25
25: ; preds = %62, %8
%26 = load i32, i32* %17
%27 = load i32, i32* %12
%28 = icmp slt i32 %26, %27
br i1 %28, label %29, label %65
29: ; preds = %25
%30 = load i8**, i8*** %10
%31 = load i32, i32* %17
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %61
36: ; preds = %29
%37 = load i8**, i8*** %10
%38 = load i32, i32* %17
%39 = sext i32 %38 to i64
%40 = getelementptr inbounds i8*, i8** %37, i64 %39
%41 = load i8*, i8** %40
%42 = getelementptr inbounds i8, i8* %41, i64 0
%43 = load i8, i8* %42
%44 = sext i8 %43 to i32
%45 = icmp ne i32 %44, 0
br i1 %45, label %46, label %61
46: ; preds = %36
%47 = load i8*, i8** %9
%48 = load i8*, i8** %9
%49 = load i8**, i8*** %10
%50 = load i32, i32* %17
%51 = sext i32 %50 to i64
%52 = getelementptr inbounds i8*, i8** %49, i64 %51
%53 = load i8*, i8** %52
%54 = load float*, float** %11
%55 = load i32, i32* %17
%56 = sext i32 %55 to i64
%57 = getelementptr inbounds float, float* %54, i64 %56
%58 = load float, float* %57
%59 = fpext float %58 to double
%60 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %47, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %48, i8* %53, double %59)
br label %61
61: ; preds = %46, %36, %29
br label %62
62: ; preds = %61
%63 = load i32, i32* %17
%64 = add nsw i32 %63, 1
store i32 %64, i32* %17
br label %25
65: ; preds = %25
%66 = load i32, i32* %14
%67 = icmp ne i32 %66, 0
br i1 %67, label %68, label %73
68: ; preds = %65
%69 = load i8*, i8** %9
%70 = load i8*, i8** %9
%71 = load i8*, i8** %15
%72 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %69, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %70, i8* %71)
br label %73
73: ; preds = %68, %65
%74 = load i32, i32* %16
%75 = icmp ne i32 %74, 0
br i1 %75, label %76, label %80
76: ; preds = %73
%77 = load i8*, i8** %9
%78 = load i8*, i8** %9
%79 = call i32 (i8*, i8*, i8*, ...) @sprintf(i8* %77, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %76, %73
ret i32 1
}

LLVM IR (-O2):
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [25 x i8] c"measurements/url_create?\00"
@.str.2 = [19 x i8] c"%sinstrument_id=%d\00"
@.str.3 = [9 x i8] c"%s&%s=%f\00"
@.str.4 = [10 x i8] c"%s&key=%s\00"
@.str.5 = [8 x i8] c"%s&test\00"
define i32 @construct_chords_route(i8* %0, i8** nocapture %1, float* nocapture %2, i32 %3, i32 %4, i32 %5, i8* %6, i32 %7) {
%9 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0))
%10 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %0, i32 %4)
%11 = icmp sgt i32 %3, 0
br i1 %11, label %12, label %30
12: ; preds = %8
%13 = zext i32 %3 to i64
br label %14
14: ; preds = %12, %27
%15 = phi i64 [ 0, %12 ], [ %28, %27 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = icmp eq i8* %17, null
br i1 %18, label %27, label %19
19: ; preds = %14
%20 = load i8, i8* %17
%21 = icmp eq i8 %20, 0
br i1 %21, label %27, label %22
22: ; preds = %19
%23 = getelementptr inbounds float, float* %2, i64 %15
%24 = load float, float* %23
%25 = fpext float %24 to double
%26 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.3, i64 0, i64 0), i8* %0, i8* %17, double %25)
br label %27
27: ; preds = %14, %19, %22
%28 = add nuw nsw i64 %15, 1
%29 = icmp eq i64 %28, %13
br i1 %29, label %30, label %14
30: ; preds = %27, %8
%31 = icmp eq i32 %5, 0
br i1 %31, label %34, label %32
32: ; preds = %30
%33 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.4, i64 0, i64 0), i8* %0, i8* %6)
br label %34
34: ; preds = %32, %30
%35 = icmp eq i32 %7, 0
br i1 %35, label %38, label %36
36: ; preds = %34
%37 = tail call i32 (i8*, i8*, i8*, ...) @sprintf(i8* dereferenceable(1) %0, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str.5, i64 0, i64 0), i8* %0)
br label %38
38: ; preds = %36, %34
ret i32 1
}