#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*/ snprintf(char *, int, char *, ...);
scalar_t__ strchr(char *, char);
int strlen(char *);
char *strtok(char *, char *);
char *build_params(char *line, char *call, char *grid, char *version,
                   char *mode, int rqrg, int date, int time) {
  static char params[300];
  char srqrg[20], *sig, *dt, *freq, *tcall, *tgrid, *pwr, *drift;
  rqrg += 1500;
  snprintf(srqrg, 20, "%d.%06d", rqrg / 1000000, rqrg % 1000000);
  dt = strtok(line, " ");
  do {
    if (strchr(dt, '.'))
      break;
    sig = dt;
  } while ((dt = strtok(NULL, " ")));
  if (!dt)
    return NULL;
  freq = strtok(NULL, " ");
  tcall = strtok(NULL, " ");
  tgrid = strtok(NULL, " ");
  pwr = strtok(NULL, " ");
  drift = strtok(NULL, " ");
  if (strlen(tgrid) == 2) {
    drift = pwr;
    pwr = tgrid;
    tgrid = "";
  }
  snprintf(
      params, 300,
      "function=wspr&rcall=%s&rgrid=%s&rqrg=%s&date=%06d&time=%04d&sig=%s&dt=%s"
      "&drift=%s&tqrg=%s&tcall=%s&tgrid=%s&dbm=%s&version=%s&mode=%s",
      call, grid, srqrg, date, time, sig, dt, drift, freq, tcall, tgrid, pwr,
      version, mode);
  return params;
}


x86 assembly (clang, -O0):
<build_params>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xf8,%rsp
mov    0x18(%rbp),%eax
mov    0x10(%rbp),%eax
mov    %rdi,-0x38(%rbp)
mov    %rsi,-0x40(%rbp)
mov    %rdx,-0x48(%rbp)
mov    %rcx,-0x50(%rbp)
mov    %r8,-0x58(%rbp)
mov    %r9d,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x5dc,%eax
mov    %eax,-0x5c(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x5c(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x5c(%rbp),%eax
mov    $0xf4240,%esi
cltd
idiv   %esi
mov    %edx,%r8d
mov    $0x14,%esi
lea    0xe58(%rip),%rdx
mov    $0x0,%al
call   1050 <snprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xe4e(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x80(%rbp)
mov    -0x80(%rbp),%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
cmp    $0x0,%rax
je     11e0 <build_params+0xa0>
jmp    1206 <build_params+0xc6>
mov    -0x80(%rbp),%rax
mov    %rax,-0x78(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xe15(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x80(%rbp)
cmp    $0x0,%rax
jne    11c3 <build_params+0x83>
cmpq   $0x0,-0x80(%rbp)
jne    121e <build_params+0xde>
movq   $0x0,-0x30(%rbp)
jmp    1396 <build_params+0x256>
xor    %eax,%eax
mov    %eax,%edi
lea    0xddf(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x88(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdc8(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x90(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xdb1(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0x98(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd9a(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xa0(%rbp)
xor    %eax,%eax
mov    %eax,%edi
lea    0xd83(%rip),%rsi
call   1060 <strtok@plt>
mov    %rax,-0xa8(%rbp)
mov    -0x98(%rbp),%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
jne    12d0 <build_params+0x190>
mov    -0xa0(%rbp),%rax
mov    %rax,-0xa8(%rbp)
mov    -0x98(%rbp),%rax
mov    %rax,-0xa0(%rbp)
lea    0xd40(%rip),%rax
mov    %rax,-0x98(%rbp)
mov    -0x40(%rbp),%rcx
mov    -0x48(%rbp),%r8
lea    -0x70(%rbp),%r9
mov    0x10(%rbp),%eax
mov    0x18(%rbp),%edx
mov    %edx,-0xbc(%rbp)
mov    -0x78(%rbp),%rdx
mov    %rdx,-0xb8(%rbp)
mov    -0x80(%rbp),%r13
mov    -0xa8(%rbp),%r12
mov    -0x88(%rbp),%r15
mov    -0x90(%rbp),%r14
mov    -0x98(%rbp),%rbx
mov    -0xa0(%rbp),%r11
mov    -0x50(%rbp),%r10
mov    -0x58(%rbp),%rdx
mov    %rdx,-0xb0(%rbp)
lea    0x2d20(%rip),%rdi
mov    $0x12c,%esi
lea    0xcce(%rip),%rdx
mov    %eax,(%rsp)
mov    -0xbc(%rbp),%eax
mov    %eax,0x8(%rsp)
mov    -0xb8(%rbp),%rax
mov    %rax,0x10(%rsp)
mov    -0xb0(%rbp),%rax
mov    %r13,0x18(%rsp)
mov    %r12,0x20(%rsp)
mov    %r15,0x28(%rsp)
mov    %r14,0x30(%rsp)
mov    %rbx,0x38(%rsp)
mov    %r11,0x40(%rsp)
mov    %r10,0x48(%rsp)
mov    %rax,0x50(%rsp)
mov    $0x0,%al
call   1050 <snprintf@plt>
lea    0x2cbe(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
add    $0xf8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

x86 assembly (clang, -O2):
<build_params>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x48,%rsp
mov    %r8,%r13
mov    %rcx,%r12
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%rbx
add    $0x5dc,%r9d
movslq %r9d,%r8
imul   $0x431bde83,%r8,%rcx
mov    %rcx,%rax
shr    $0x3f,%rax
sar    $0x32,%rcx
add    %eax,%ecx
imul   $0xf4240,%ecx,%eax
sub    %eax,%r8d
lea    0xe75(%rip),%rdx
lea    0x30(%rsp),%rdi
mov    $0x14,%esi
xor    %eax,%eax
call   1050 <snprintf@plt>
lea    0xe65(%rip),%rsi
mov    %rbx,%rdi
call   1060 <strtok@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
mov    %r14,0x28(%rsp)
mov    %rbp,0x20(%rsp)
je     11d7 <build_params+0x97>
test   %rbx,%rbx
jne    121b <build_params+0xdb>
xor    %r14d,%r14d
jmp    12ed <build_params+0x1ad>
lea    0xe2a(%rip),%rbp
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %rbx,%r15
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
test   %rax,%rax
je     12ed <build_params+0x1ad>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x2e,%esi
call   1040 <strchr@plt>
test   %rax,%rax
je     11f0 <build_params+0xb0>
lea    0xde6(%rip),%rbp
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    %rax,0x18(%rsp)
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    %rax,0x10(%rsp)
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    %r12,0x8(%rsp)
mov    %rax,%r12
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    %rax,%r14
xor    %edi,%edi
mov    %rbp,%rsi
call   1060 <strtok@plt>
mov    %r13,(%rsp)
mov    %rax,%r13
mov    %r12,%rdi
call   1030 <strlen@plt>
cmp    $0x2,%eax
lea    0xd87(%rip),%rbp
cmovne %r12,%rbp
cmovne %r14,%r12
cmove  %r14,%r13
sub    $0x8,%rsp
lea    0x2db7(%rip),%r14
lea    0xd6a(%rip),%rdx
lea    0x38(%rsp),%r9
mov    %r14,%rdi
mov    $0x12c,%esi
mov    0x28(%rsp),%rcx
mov    0x30(%rsp),%r8
mov    $0x0,%eax
push   0x8(%rsp)
push   0x18(%rsp)
push   %r12
push   %rbp
push   0x38(%rsp)
push   0x48(%rsp)
push   %r13
push   %rbx
push   %r15
mov    0xd8(%rsp),%ebp
push   %rbp
mov    0xd8(%rsp),%ebp
push   %rbp
call   1050 <snprintf@plt>
add    $0x60,%rsp
mov    %r14,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@build_params.params = internal global [300 x i8] zeroinitializer
@.str = [8 x i8] c"%d.%06d\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [134 x i8] c"function=wspr&rcall=%s&rgrid=%s&rqrg=%s&date=%06d&time=%04d&sig=%s&dt=%s&drift=%s&tqrg=%s&tcall=%s&tgrid=%s&dbm=%s&version=%s&mode=%s\00"
define i8* @build_params(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i8*
%15 = alloca i32
%16 = alloca i32
%17 = alloca i32
%18 = alloca [20 x i8]
%19 = alloca i8*
%20 = alloca i8*
%21 = alloca i8*
%22 = alloca i8*
%23 = alloca i8*
%24 = alloca i8*
%25 = alloca i8*
store i8* %0, i8** %10
store i8* %1, i8** %11
store i8* %2, i8** %12
store i8* %3, i8** %13
store i8* %4, i8** %14
store i32 %5, i32* %15
store i32 %6, i32* %16
store i32 %7, i32* %17
%26 = load i32, i32* %15
%27 = add nsw i32 %26, 1500
store i32 %27, i32* %15
%28 = getelementptr inbounds [20 x i8], [20 x i8]* %18, i64 0, i64 0
%29 = load i32, i32* %15
%30 = sdiv i32 %29, 1000000
%31 = load i32, i32* %15
%32 = srem i32 %31, 1000000
%33 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %28, i32 20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %30, i32 %32)
%34 = load i8*, i8** %10
%35 = call i8* @strtok(i8* %34, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %35, i8** %20
br label %36
36: ; preds = %43, %8
%37 = load i8*, i8** %20
%38 = call i64 @strchr(i8* %37, i8 signext 46)
%39 = icmp ne i64 %38, 0
br i1 %39, label %40, label %41
40: ; preds = %36
br label %46
41: ; preds = %36
%42 = load i8*, i8** %20
store i8* %42, i8** %19
br label %43
43: ; preds = %41
%44 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %44, i8** %20
%45 = icmp ne i8* %44, null
br i1 %45, label %36, label %46
46: ; preds = %43, %40
%47 = load i8*, i8** %20
%48 = icmp ne i8* %47, null
br i1 %48, label %50, label %49
49: ; preds = %46
store i8* null, i8** %9
br label %78
50: ; preds = %46
%51 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %51, i8** %21
%52 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %52, i8** %22
%53 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %53, i8** %23
%54 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %54, i8** %24
%55 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i8* %55, i8** %25
%56 = load i8*, i8** %23
%57 = call i32 @strlen(i8* %56)
%58 = icmp eq i32 %57, 2
br i1 %58, label %59, label %62
59: ; preds = %50
%60 = load i8*, i8** %24
store i8* %60, i8** %25
%61 = load i8*, i8** %23
store i8* %61, i8** %24
store i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8** %23
br label %62
62: ; preds = %59, %50
%63 = load i8*, i8** %11
%64 = load i8*, i8** %12
%65 = getelementptr inbounds [20 x i8], [20 x i8]* %18, i64 0, i64 0
%66 = load i32, i32* %16
%67 = load i32, i32* %17
%68 = load i8*, i8** %19
%69 = load i8*, i8** %20
%70 = load i8*, i8** %25
%71 = load i8*, i8** %21
%72 = load i8*, i8** %22
%73 = load i8*, i8** %23
%74 = load i8*, i8** %24
%75 = load i8*, i8** %13
%76 = load i8*, i8** %14
%77 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([300 x i8], [300 x i8]* @build_params.params, i64 0, i64 0), i32 300, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.3, i64 0, i64 0), i8* %63, i8* %64, i8* %65, i32 %66, i32 %67, i8* %68, i8* %69, i8* %70, i8* %71, i8* %72, i8* %73, i8* %74, i8* %75, i8* %76)
store i8* getelementptr inbounds ([300 x i8], [300 x i8]* @build_params.params, i64 0, i64 0), i8** %9
br label %78
78: ; preds = %62, %49
%79 = load i8*, i8** %9
ret i8* %79
}

LLVM IR (-O2):
@build_params.params = internal global [300 x i8] zeroinitializer
@.str = [8 x i8] c"%d.%06d\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [1 x i8] zeroinitializer
@.str.3 = [134 x i8] c"function=wspr&rcall=%s&rgrid=%s&rqrg=%s&date=%06d&time=%04d&sig=%s&dt=%s&drift=%s&tqrg=%s&tcall=%s&tgrid=%s&dbm=%s&version=%s&mode=%s\00"
define i8* @build_params(i8* %0, i8* %1, i8* %2, i8* %3, i8* %4, i32 %5, i32 %6, i32 %7) {
%9 = alloca [20 x i8]
%10 = getelementptr inbounds [20 x i8], [20 x i8]* %9, i64 0, i64 0
%11 = add nsw i32 %5, 1500
%12 = sdiv i32 %11, 1000000
%13 = srem i32 %11, 1000000
%14 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %10, i32 20, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12, i32 %13)
%15 = call i8* @strtok(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%16 = call i64 @strchr(i8* %15, i8 signext 46)
%17 = icmp eq i64 %16, 0
br i1 %17, label %21, label %25
18: ; preds = %21
%19 = call i64 @strchr(i8* %23, i8 signext 46)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %8, %18
%22 = phi i8* [ %23, %18 ], [ %15, %8 ]
%23 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i8* %23, null
br i1 %24, label %41, label %18
25: ; preds = %8
%26 = icmp eq i8* %15, null
br i1 %26, label %41, label %27
27: ; preds = %18, %25
%28 = phi i8* [ undef, %25 ], [ %22, %18 ]
%29 = phi i8* [ %15, %25 ], [ %23, %18 ]
%30 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%32 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%33 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = call i8* @strtok(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%35 = call i32 @strlen(i8* %32)
%36 = icmp eq i32 %35, 2
%37 = select i1 %36, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.2, i64 0, i64 0), i8* %32
%38 = select i1 %36, i8* %32, i8* %33
%39 = select i1 %36, i8* %33, i8* %34
%40 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* getelementptr inbounds ([300 x i8], [300 x i8]* @build_params.params, i64 0, i64 0), i32 300, i8* getelementptr inbounds ([134 x i8], [134 x i8]* @.str.3, i64 0, i64 0), i8* %1, i8* %2, i8* %10, i32 %6, i32 %7, i8* %28, i8* %29, i8* %39, i8* %30, i8* %31, i8* %37, i8* %38, i8* %3, i8* %4)
br label %41
41: ; preds = %21, %25, %27
%42 = phi i8* [ getelementptr inbounds ([300 x i8], [300 x i8]* @build_params.params, i64 0, i64 0), %27 ], [ null, %25 ], [ null, %21 ]
ret i8* %42
}