#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*/ time_t;
typedef size_t ssize_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
int /*<<< orphan*/ perror(char const *);
int sigproc_save_data(size_t nSamples, time_t timeStamp, size_t adcSdmCycRatio,
                      const char *adcFName, const float *adcData, size_t nAdcCh,
                      const char *sdmFName, const char *sdmData,
                      size_t nSdmCh) {
  FILE *fpa, *fps;
  ssize_t i, j;
  if ((fpa = fopen(adcFName, "w")) == NULL) {
    perror(adcFName);
    return -1;
  }
  if ((fps = fopen(sdmFName, "w")) == NULL) {
    perror(sdmFName);
    return -1;
  }
  fprintf(fpa, "# TimeStamp: 0x%016lx 5Msps ADC\n", timeStamp);
  for (i = 0; i < nSamples; i++) {
    for (j = 0; j < nAdcCh; j++) {
      fprintf(fpa, " %9.6f", adcData[j * nSamples + i]);
    }
    fprintf(fpa, "\n");
  }
  fprintf(fps, "# TimeStamp: 0x%016lx 25Msps SDM\n", timeStamp);
  for (i = 0; i < nSamples * adcSdmCycRatio; i++) {
    for (j = 0; j < nSdmCh; j++) {
      fprintf(fps, " %1d", sdmData[j * nSamples * adcSdmCycRatio + i]);
    }
    fprintf(fps, "\n");
  }
  fclose(fpa);
  fclose(fps);
  return 0;
}


x86 assembly (clang, -O0):
<sigproc_save_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    0x20(%rbp),%rax
mov    0x18(%rbp),%rax
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x40(%rbp)
cmp    $0x0,%rax
jne    119e <sigproc_save_data+0x5e>
mov    -0x28(%rbp),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1334 <sigproc_save_data+0x1f4>
mov    0x10(%rbp),%rdi
lea    0xe57(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11d1 <sigproc_save_data+0x91>
mov    0x10(%rbp),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1334 <sigproc_save_data+0x1f4>
mov    -0x40(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe23(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
cmp    -0x10(%rbp),%rax
jae    1272 <sigproc_save_data+0x132>
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    -0x38(%rbp),%rax
jae    124f <sigproc_save_data+0x10f>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rax
mov    -0x58(%rbp),%rcx
imul   -0x10(%rbp),%rcx
add    -0x50(%rbp),%rcx
movss  (%rax,%rcx,4),%xmm0
cvtss2sd %xmm0,%xmm0
lea    0xdec(%rip),%rsi
mov    $0x1,%al
call   1040 <fprintf@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    1204 <sigproc_save_data+0xc4>
mov    -0x40(%rbp),%rdi
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    11ee <sigproc_save_data+0xae>
mov    -0x48(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdaa(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movq   $0x0,-0x50(%rbp)
mov    -0x50(%rbp),%rax
mov    -0x10(%rbp),%rcx
imul   -0x20(%rbp),%rcx
cmp    %rcx,%rax
jae    131b <sigproc_save_data+0x1db>
movq   $0x0,-0x58(%rbp)
mov    -0x58(%rbp),%rax
cmp    0x20(%rbp),%rax
jae    12f8 <sigproc_save_data+0x1b8>
mov    -0x48(%rbp),%rdi
mov    0x18(%rbp),%rax
mov    -0x58(%rbp),%rcx
imul   -0x10(%rbp),%rcx
imul   -0x20(%rbp),%rcx
add    -0x50(%rbp),%rcx
movsbl (%rax,%rcx,1),%edx
lea    0xd6c(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x58(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x58(%rbp)
jmp    12ad <sigproc_save_data+0x16d>
mov    -0x48(%rbp),%rdi
lea    0xd1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
mov    -0x50(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x50(%rbp)
jmp    128f <sigproc_save_data+0x14f>
mov    -0x40(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x48(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sigproc_save_data>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x38,%rsp
mov    %r9,0x28(%rsp)
mov    %r8,0x20(%rsp)
mov    %rcx,%rbx
mov    %rdx,%r14
mov    %esi,%r13d
mov    %rdi,(%rsp)
lea    0xe84(%rip),%rsi
mov    %rcx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1320 <sigproc_save_data+0x1d0>
mov    %rax,%rbp
mov    0x70(%rsp),%r12
lea    0xe64(%rip),%rsi
mov    %r12,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     1325 <sigproc_save_data+0x1d5>
mov    %rax,%r15
mov    %r14,0x30(%rsp)
lea    0xe46(%rip),%rsi
mov    %rbp,0x18(%rsp)
mov    %rbp,%rdi
mov    %r13d,0x14(%rsp)
mov    %r13d,%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
cmpq   $0x0,(%rsp)
je     1262 <sigproc_save_data+0x112>
mov    (%rsp),%rax
lea    0x0(,%rax,4),%rbp
xor    %eax,%eax
lea    0xe30(%rip),%r12
mov    0x18(%rsp),%rbx
jmp    1222 <sigproc_save_data+0xd2>
nopw   0x0(%rax,%rax,1)
mov    $0xa,%edi
mov    %rbx,%rsi
call   1040 <fputc@plt>
mov    0x8(%rsp),%rax
add    $0x1,%rax
addq   $0x4,0x20(%rsp)
cmp    (%rsp),%rax
je     1262 <sigproc_save_data+0x112>
mov    %rax,0x8(%rsp)
cmpq   $0x0,0x28(%rsp)
je     1200 <sigproc_save_data+0xb0>
mov    0x20(%rsp),%r13
mov    0x28(%rsp),%r14
nopl   0x0(%rax)
movss  0x0(%r13),%xmm0
cvtss2sd %xmm0,%xmm0
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%al
call   1050 <fprintf@plt>
add    %rbp,%r13
add    $0xffffffffffffffff,%r14
jne    1240 <sigproc_save_data+0xf0>
jmp    1200 <sigproc_save_data+0xb0>
lea    0xdc1(%rip),%rsi
mov    %r15,%rdi
mov    0x14(%rsp),%edx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    0x30(%rsp),%rbp
imul   (%rsp),%rbp
test   %rbp,%rbp
je     12fd <sigproc_save_data+0x1ad>
mov    0x78(%rsp),%rax
mov    %rax,0x8(%rsp)
lea    0xdb5(%rip),%r14
xor    %r13d,%r13d
jmp    12bc <sigproc_save_data+0x16c>
nopl   0x0(%rax)
mov    $0xa,%edi
mov    %r15,%rsi
call   1040 <fputc@plt>
add    $0x1,%r13
addq   $0x1,0x8(%rsp)
cmp    %rbp,%r13
je     12fd <sigproc_save_data+0x1ad>
cmpq   $0x0,0x80(%rsp)
je     12a0 <sigproc_save_data+0x150>
mov    0x8(%rsp),%r12
mov    0x80(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
movsbl (%r12),%edx
mov    %r15,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
add    %rbp,%r12
add    $0xffffffffffffffff,%rbx
jne    12e0 <sigproc_save_data+0x190>
jmp    12a0 <sigproc_save_data+0x150>
mov    0x18(%rsp),%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rbx,%rdi
jmp    1328 <sigproc_save_data+0x1d8>
mov    %r12,%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    1311 <sigproc_save_data+0x1c1>

LLVM IR (-O0):
@.str = [2 x i8] c"w\00"
@.str.1 = [33 x i8] c"# TimeStamp: 0x%016lx 5Msps ADC\0A\00"
@.str.2 = [7 x i8] c" %9.6f\00"
@.str.3 = [2 x i8] c"\0A\00"
@.str.4 = [34 x i8] c"# TimeStamp: 0x%016lx 25Msps SDM\0A\00"
@.str.5 = [5 x i8] c" %1d\00"
define i32 @sigproc_save_data(i64 %0, i32 %1, i64 %2, i8* %3, float* %4, i64 %5, i8* %6, i8* %7, i64 %8) {
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i64
%14 = alloca i8*
%15 = alloca float*
%16 = alloca i64
%17 = alloca i8*
%18 = alloca i8*
%19 = alloca i64
%20 = alloca i32*
%21 = alloca i32*
%22 = alloca i64
%23 = alloca i64
store i64 %0, i64* %11
store i32 %1, i32* %12
store i64 %2, i64* %13
store i8* %3, i8** %14
store float* %4, float** %15
store i64 %5, i64* %16
store i8* %6, i8** %17
store i8* %7, i8** %18
store i64 %8, i64* %19
%24 = load i8*, i8** %14
%25 = call i32* @fopen(i8* %24, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %25, i32** %20
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %30
27: ; preds = %9
%28 = load i8*, i8** %14
%29 = call i32 @perror(i8* %28)
store i32 -1, i32* %10
br label %114
30: ; preds = %9
%31 = load i8*, i8** %17
%32 = call i32* @fopen(i8* %31, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %32, i32** %21
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %30
%35 = load i8*, i8** %17
%36 = call i32 @perror(i8* %35)
store i32 -1, i32* %10
br label %114
37: ; preds = %30
%38 = load i32*, i32** %20
%39 = load i32, i32* %12
%40 = call i32 (i32*, i8*, ...) @fprintf(i32* %38, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %39)
store i64 0, i64* %22
br label %41
41: ; preds = %68, %37
%42 = load i64, i64* %22
%43 = load i64, i64* %11
%44 = icmp ult i64 %42, %43
br i1 %44, label %45, label %71
45: ; preds = %41
store i64 0, i64* %23
br label %46
46: ; preds = %62, %45
%47 = load i64, i64* %23
%48 = load i64, i64* %16
%49 = icmp ult i64 %47, %48
br i1 %49, label %50, label %65
50: ; preds = %46
%51 = load i32*, i32** %20
%52 = load float*, float** %15
%53 = load i64, i64* %23
%54 = load i64, i64* %11
%55 = mul i64 %53, %54
%56 = load i64, i64* %22
%57 = add i64 %55, %56
%58 = getelementptr inbounds float, float* %52, i64 %57
%59 = load float, float* %58
%60 = fpext float %59 to double
%61 = call i32 (i32*, i8*, ...) @fprintf(i32* %51, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %60)
br label %62
62: ; preds = %50
%63 = load i64, i64* %23
%64 = add i64 %63, 1
store i64 %64, i64* %23
br label %46
65: ; preds = %46
%66 = load i32*, i32** %20
%67 = call i32 (i32*, i8*, ...) @fprintf(i32* %66, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %68
68: ; preds = %65
%69 = load i64, i64* %22
%70 = add i64 %69, 1
store i64 %70, i64* %22
br label %41
71: ; preds = %41
%72 = load i32*, i32** %21
%73 = load i32, i32* %12
%74 = call i32 (i32*, i8*, ...) @fprintf(i32* %72, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %73)
store i64 0, i64* %22
br label %75
75: ; preds = %106, %71
%76 = load i64, i64* %22
%77 = load i64, i64* %11
%78 = load i64, i64* %13
%79 = mul i64 %77, %78
%80 = icmp ult i64 %76, %79
br i1 %80, label %81, label %109
81: ; preds = %75
store i64 0, i64* %23
br label %82
82: ; preds = %100, %81
%83 = load i64, i64* %23
%84 = load i64, i64* %19
%85 = icmp ult i64 %83, %84
br i1 %85, label %86, label %103
86: ; preds = %82
%87 = load i32*, i32** %21
%88 = load i8*, i8** %18
%89 = load i64, i64* %23
%90 = load i64, i64* %11
%91 = mul i64 %89, %90
%92 = load i64, i64* %13
%93 = mul i64 %91, %92
%94 = load i64, i64* %22
%95 = add i64 %93, %94
%96 = getelementptr inbounds i8, i8* %88, i64 %95
%97 = load i8, i8* %96
%98 = sext i8 %97 to i32
%99 = call i32 (i32*, i8*, ...) @fprintf(i32* %87, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %98)
br label %100
100: ; preds = %86
%101 = load i64, i64* %23
%102 = add i64 %101, 1
store i64 %102, i64* %23
br label %82
103: ; preds = %82
%104 = load i32*, i32** %21
%105 = call i32 (i32*, i8*, ...) @fprintf(i32* %104, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %106
106: ; preds = %103
%107 = load i64, i64* %22
%108 = add i64 %107, 1
store i64 %108, i64* %22
br label %75
109: ; preds = %75
%110 = load i32*, i32** %20
%111 = call i32 @fclose(i32* %110)
%112 = load i32*, i32** %21
%113 = call i32 @fclose(i32* %112)
store i32 0, i32* %10
br label %114
114: ; preds = %109, %34, %27
%115 = load i32, i32* %10
ret i32 %115
}

LLVM IR (-O2):
@.str = [2 x i8] c"w\00"
@.str.1 = [33 x i8] c"# TimeStamp: 0x%016lx 5Msps ADC\0A\00"
@.str.2 = [7 x i8] c" %9.6f\00"
@.str.4 = [34 x i8] c"# TimeStamp: 0x%016lx 25Msps SDM\0A\00"
@.str.5 = [5 x i8] c" %1d\00"
define i32 @sigproc_save_data(i64 %0, i32 %1, i64 %2, i8* nocapture %3, float* nocapture %4, i64 %5, i8* nocapture %6, i8* nocapture %7, i64 %8) {
%10 = tail call i32* @fopen(i8* %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %14
12: ; preds = %9
%13 = tail call i32 @perror(i8* %3)
br label %65
14: ; preds = %9
%15 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%16 = icmp eq i32* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = tail call i32 @perror(i8* %6)
br label %65
19: ; preds = %14
%20 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%21 = icmp eq i64 %0, 0
br i1 %21, label %40, label %22
22: ; preds = %19
%23 = icmp eq i64 %5, 0
br label %24
24: ; preds = %22, %36
%25 = phi i64 [ 0, %22 ], [ %38, %36 ]
br i1 %23, label %36, label %26
26: ; preds = %24, %26
%27 = phi i64 [ %34, %26 ], [ 0, %24 ]
%28 = mul i64 %27, %0
%29 = add i64 %28, %25
%30 = getelementptr inbounds float, float* %4, i64 %29
%31 = load float, float* %30
%32 = fpext float %31 to double
%33 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %10, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), double %32)
%34 = add nuw i64 %27, 1
%35 = icmp eq i64 %34, %5
br i1 %35, label %36, label %26
36: ; preds = %26, %24
%37 = tail call i32 @fputc(i32 10, i32* %10)
%38 = add nuw i64 %25, 1
%39 = icmp eq i64 %38, %0
br i1 %39, label %40, label %24
40: ; preds = %36, %19
%41 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i32 %1)
%42 = mul i64 %2, %0
%43 = icmp eq i64 %42, 0
br i1 %43, label %62, label %44
44: ; preds = %40
%45 = icmp eq i64 %8, 0
br label %46
46: ; preds = %44, %58
%47 = phi i64 [ 0, %44 ], [ %60, %58 ]
br i1 %45, label %58, label %48
48: ; preds = %46, %48
%49 = phi i64 [ %56, %48 ], [ 0, %46 ]
%50 = mul i64 %42, %49
%51 = add i64 %50, %47
%52 = getelementptr inbounds i8, i8* %7, i64 %51
%53 = load i8, i8* %52
%54 = sext i8 %53 to i32
%55 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i32 %54)
%56 = add nuw i64 %49, 1
%57 = icmp eq i64 %56, %8
br i1 %57, label %58, label %48
58: ; preds = %48, %46
%59 = tail call i32 @fputc(i32 10, i32* %15)
%60 = add nuw i64 %47, 1
%61 = icmp eq i64 %60, %42
br i1 %61, label %62, label %46
62: ; preds = %58, %40
%63 = tail call i32 @fclose(i32* %10)
%64 = tail call i32 @fclose(i32* %15)
br label %65
65: ; preds = %62, %17, %12
%66 = phi i32 [ -1, %12 ], [ -1, %17 ], [ 0, %62 ]
ret i32 %66
}