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

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
double strtod(char *, char **);
int strtol(char *, char **, int);
int read_trigger_from_trigfile(FILE *triggerfile, float sfreq,
                               long *trigpoint) {
  char buffer[80];
  int code = 0;
  do {
    if (fgets(buffer, 80, triggerfile) != NULL) {
      char *inbuffer = buffer;
      double trigpos;
      if (*buffer == '#' || *buffer == '\n')
        continue;
      trigpos = strtod(inbuffer, &inbuffer);
      switch (*inbuffer) {
      case 'm':
        trigpos /= 1000.0;
        inbuffer++;
      case 's':
        trigpos *= sfreq;
        inbuffer++;
      default:
        *trigpoint = (long)trigpos;
        break;
      }
      code = strtol(inbuffer, &inbuffer, 10);
    }
    break;
  } while (1);
  return code;
}


x86 assembly (clang, -O0):
<read_trigger_from_trigfile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    %rdi,-0x8(%rbp)
movss  %xmm0,-0xc(%rbp)
mov    %rsi,-0x18(%rbp)
movl   $0x0,-0x74(%rbp)
lea    -0x70(%rbp),%rdi
mov    -0x8(%rbp),%rdx
mov    $0x50,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1248 <read_trigger_from_trigfile+0x118>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
movsbl -0x70(%rbp),%eax
cmp    $0x23,%eax
je     118d <read_trigger_from_trigfile+0x5d>
movsbl -0x70(%rbp),%eax
cmp    $0xa,%eax
jne    1192 <read_trigger_from_trigfile+0x62>
jmp    124d <read_trigger_from_trigfile+0x11d>
mov    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
call   1030 <strtod@plt>
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x80(%rbp),%rax
movsbl (%rax),%eax
mov    %eax,-0x8c(%rbp)
sub    $0x6d,%eax
je     11d6 <read_trigger_from_trigfile+0xa6>
jmp    11c2 <read_trigger_from_trigfile+0x92>
mov    -0x8c(%rbp),%eax
sub    $0x73,%eax
je     11fe <read_trigger_from_trigfile+0xce>
jmp    1223 <read_trigger_from_trigfile+0xf3>
movsd  -0x88(%rbp),%xmm0
ff
movsd  0xe1a(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
movss  -0xc(%rbp),%xmm0
cvtss2sd %xmm0,%xmm0
mulsd  -0x88(%rbp),%xmm0
ff
movsd  %xmm0,-0x88(%rbp)
ff
mov    -0x80(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x80(%rbp)
cvttsd2si -0x88(%rbp),%rcx
ff ff
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x80(%rbp),%rdi
lea    -0x80(%rbp),%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,-0x74(%rbp)
jmp    125c <read_trigger_from_trigfile+0x12c>
mov    $0x1,%al
test   $0x1,%al
jne    114f <read_trigger_from_trigfile+0x1f>
jmp    125c <read_trigger_from_trigfile+0x12c>
mov    -0x74(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_trigger_from_trigfile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    %rsi,%r14
movss  %xmm0,0xc(%rsp)
mov    %rdi,%rbx
lea    0x10(%rsp),%rbp
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
xor    %r15d,%r15d
jmp    1170 <read_trigger_from_trigfile+0x40>
mov    %rbp,%rdi
mov    $0x50,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11de <read_trigger_from_trigfile+0xae>
mov    %rbp,(%rsp)
movzbl 0x10(%rsp),%eax
cmp    $0xa,%al
je     1160 <read_trigger_from_trigfile+0x30>
cmp    $0x23,%al
je     1160 <read_trigger_from_trigfile+0x30>
lea    0x10(%rsp),%rdi
mov    %rsp,%rsi
call   1030 <strtod@plt>
mov    (%rsp),%rdi
movsbl (%rdi),%eax
cmp    $0x73,%eax
je     11b0 <read_trigger_from_trigfile+0x80>
cmp    $0x6d,%eax
jne    11c6 <read_trigger_from_trigfile+0x96>
divsd  0xe54(%rip),%xmm0
add    $0x1,%rdi
movss  0xc(%rsp),%xmm1
cvtss2sd %xmm1,%xmm1
mulsd  %xmm1,%xmm0
add    $0x1,%rdi
mov    %rdi,(%rsp)
cvttsd2si %xmm0,%rax
mov    %rax,(%r14)
mov    %rsp,%rsi
mov    $0xa,%edx
call   1050 <strtol@plt>
mov    %eax,%r15d
mov    %r15d,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @read_trigger_from_trigfile(i32* %0, float %1, i64* %2) {
%4 = alloca i32*
%5 = alloca float
%6 = alloca i64*
%7 = alloca [80 x i8]
%8 = alloca i32
%9 = alloca i8*
%10 = alloca double
store i32* %0, i32** %4
store float %1, float* %5
store i64* %2, i64** %6
store i32 0, i32* %8
br label %11
11: ; preds = %54, %3
%12 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%13 = load i32*, i32** %4
%14 = call i32* @fgets(i8* %12, i32 80, i32* %13)
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %53
16: ; preds = %11
%17 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
store i8* %17, i8** %9
%18 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%19 = load i8, i8* %18
%20 = sext i8 %19 to i32
%21 = icmp eq i32 %20, 35
br i1 %21, label %27, label %22
22: ; preds = %16
%23 = getelementptr inbounds [80 x i8], [80 x i8]* %7, i64 0, i64 0
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = icmp eq i32 %25, 10
br i1 %26, label %27, label %28
27: ; preds = %22, %16
br label %54
28: ; preds = %22
%29 = load i8*, i8** %9
%30 = call double @strtod(i8* %29, i8** %9)
store double %30, double* %10
%31 = load i8*, i8** %9
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
switch i32 %33, label %46 [
i32 109, label %34
i32 115, label %39
]
34: ; preds = %28
%35 = load double, double* %10
%36 = fdiv double %35, 1.000000e+03
store double %36, double* %10
%37 = load i8*, i8** %9
%38 = getelementptr inbounds i8, i8* %37, i32 1
store i8* %38, i8** %9
br label %39
39: ; preds = %28, %34
%40 = load float, float* %5
%41 = fpext float %40 to double
%42 = load double, double* %10
%43 = fmul double %42, %41
store double %43, double* %10
%44 = load i8*, i8** %9
%45 = getelementptr inbounds i8, i8* %44, i32 1
store i8* %45, i8** %9
br label %46
46: ; preds = %28, %39
%47 = load double, double* %10
%48 = fptosi double %47 to i64
%49 = load i64*, i64** %6
store i64 %48, i64* %49
br label %50
50: ; preds = %46
%51 = load i8*, i8** %9
%52 = call i32 @strtol(i8* %51, i8** %9, i32 10)
store i32 %52, i32* %8
br label %53
53: ; preds = %50, %11
br label %55
54: ; preds = %27
br i1 true, label %11, label %55
55: ; preds = %54, %53
%56 = load i32, i32* %8
ret i32 %56
}

LLVM IR (-O2):
define i32 @read_trigger_from_trigfile(i32* nocapture %0, float %1, i64* nocapture writeonly %2) {
%4 = alloca [80 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [80 x i8], [80 x i8]* %4, i64 0, i64 0
%7 = call i32* @fgets(i8* %6, i32 80, i32* %0)
%8 = icmp eq i32* %7, null
br i1 %8, label %35, label %9
9: ; preds = %3
%10 = bitcast i8** %5 to i8*
br label %11
11: ; preds = %9, %32
store i8* %6, i8** %5
%12 = load i8, i8* %6
switch i8 %12, label %13 [
i8 35, label %32
i8 10, label %32
]
13: ; preds = %11
%14 = call double @strtod(i8* %6, i8** %5)
%15 = load i8*, i8** %5
%16 = load i8, i8* %15
%17 = sext i8 %16 to i32
switch i32 %17, label %27 [
i32 109, label %18
i32 115, label %21
]
18: ; preds = %13
%19 = fdiv double %14, 1.000000e+03
%20 = getelementptr inbounds i8, i8* %15, i64 1
br label %21
21: ; preds = %13, %18
%22 = phi i8* [ %15, %13 ], [ %20, %18 ]
%23 = phi double [ %14, %13 ], [ %19, %18 ]
%24 = fpext float %1 to double
%25 = fmul double %23, %24
%26 = getelementptr inbounds i8, i8* %22, i64 1
store i8* %26, i8** %5
br label %27
27: ; preds = %21, %13
%28 = phi i8* [ %15, %13 ], [ %26, %21 ]
%29 = phi double [ %14, %13 ], [ %25, %21 ]
%30 = fptosi double %29 to i64
store i64 %30, i64* %2
%31 = call i32 @strtol(i8* %28, i8** %5, i32 10)
br label %35
32: ; preds = %11, %11
%33 = call i32* @fgets(i8* %6, i32 80, i32* %0)
%34 = icmp eq i32* %33, null
br i1 %34, label %35, label %11
35: ; preds = %32, %3, %27
%36 = phi i32 [ %31, %27 ], [ 0, %3 ], [ 0, %32 ]
ret i32 %36
}