#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*/ fatal_error(char *, char *);
int /*<<< orphan*/ free(struct local_struct *);
scalar_t__ malloc(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int f_count(int mode, unsigned char **sec, float *data, unsigned int ndata,
            char *inv_out, void **local) {
  struct local_struct {
    int count;
  };
  struct local_struct *save;
  if (mode == -1) {
    *local = save = (struct local_struct *)malloc(sizeof(struct local_struct));
    if (save == NULL)
      fatal_error("f_count memory allocation ", "");
    save->count = 0;
  } else if (mode >= 0) {
    save = (struct local_struct *)*local;
    save->count += 1;
  } else if (mode == -2) {
    save = (struct local_struct *)*local;
    sprintf(inv_out, "number of records: %d", save->count);
    free(save);
  }
  return 0;
}


x86 assembly (clang, -O0):
<f_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    %r8,-0x28(%rbp)
mov    %r9,-0x30(%rbp)
cmpl   $0xffffffff,-0x4(%rbp)
jne    11ad <f_count+0x6d>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    %rcx,-0x38(%rbp)
mov    -0x30(%rbp),%rax
mov    %rcx,(%rax)
cmpq   $0x0,-0x38(%rbp)
jne    119e <f_count+0x5e>
lea    0xe6e(%rip),%rdi
lea    0xe81(%rip),%rsi
call   1040 <fatal_error@plt>
mov    -0x38(%rbp),%rax
movl   $0x0,(%rax)
jmp    1210 <f_count+0xd0>
cmpl   $0x0,-0x4(%rbp)
jl     11d2 <f_count+0x92>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    (%rax),%ecx
add    $0x1,%ecx
mov    %ecx,(%rax)
jmp    120b <f_count+0xcb>
cmpl   $0xfffffffe,-0x4(%rbp)
jne    1206 <f_count+0xc6>
mov    -0x30(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x38(%rbp),%rax
mov    (%rax),%edx
lea    0xe23(%rip),%rsi
call   1060 <sprintf@plt>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
jmp    120b <f_count+0xcb>
jmp    1210 <f_count+0xd0>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<f_count>:
push   %r14
push   %rbx
push   %rax
mov    %r9,%rbx
cmp    $0xffffffff,%edi
je     1158 <f_count+0x18>
test   %edi,%edi
js     1189 <f_count+0x49>
mov    (%rbx),%rax
addl   $0x1,(%rax)
jmp    11aa <f_count+0x6a>
mov    $0x4,%edi
call   1050 <malloc@plt>
mov    %rax,%r14
mov    %rax,(%rbx)
test   %rax,%rax
jne    1180 <f_count+0x40>
lea    0xe8c(%rip),%rdi
lea    0xe9f(%rip),%rsi
call   1040 <fatal_error@plt>
movl   $0x0,(%r14)
jmp    11aa <f_count+0x6a>
cmp    $0xfffffffe,%edi
jne    11aa <f_count+0x6a>
mov    (%rbx),%rbx
mov    (%rbx),%edx
lea    0xe81(%rip),%rsi
mov    %r8,%rdi
call   1060 <sprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.local_struct = type { i32 }
%struct.local_struct.0 = type opaque
@.str = [27 x i8] c"f_count memory allocation \00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [22 x i8] c"number of records: %d\00"
define i32 @f_count(i32 %0, i8** %1, float* %2, i32 %3, i8* %4, i8** %5) {
%7 = alloca i32
%8 = alloca i8**
%9 = alloca float*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i8**
%13 = alloca %struct.local_struct*
store i32 %0, i32* %7
store i8** %1, i8*** %8
store float* %2, float** %9
store i32 %3, i32* %10
store i8* %4, i8** %11
store i8** %5, i8*** %12
%14 = load i32, i32* %7
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %28
16: ; preds = %6
%17 = call i64 @malloc(i32 4)
%18 = inttoptr i64 %17 to %struct.local_struct*
store %struct.local_struct* %18, %struct.local_struct** %13
%19 = bitcast %struct.local_struct* %18 to i8*
%20 = load i8**, i8*** %12
store i8* %19, i8** %20
%21 = load %struct.local_struct*, %struct.local_struct** %13
%22 = icmp eq %struct.local_struct* %21, null
br i1 %22, label %23, label %25
23: ; preds = %16
%24 = call i32 @fatal_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %25
25: ; preds = %23, %16
%26 = load %struct.local_struct*, %struct.local_struct** %13
%27 = getelementptr inbounds %struct.local_struct, %struct.local_struct* %26, i32 0, i32 0
store i32 0, i32* %27
br label %56
28: ; preds = %6
%29 = load i32, i32* %7
%30 = icmp sge i32 %29, 0
br i1 %30, label %31, label %39
31: ; preds = %28
%32 = load i8**, i8*** %12
%33 = load i8*, i8** %32
%34 = bitcast i8* %33 to %struct.local_struct*
store %struct.local_struct* %34, %struct.local_struct** %13
%35 = load %struct.local_struct*, %struct.local_struct** %13
%36 = getelementptr inbounds %struct.local_struct, %struct.local_struct* %35, i32 0, i32 0
%37 = load i32, i32* %36
%38 = add nsw i32 %37, 1
store i32 %38, i32* %36
br label %55
39: ; preds = %28
%40 = load i32, i32* %7
%41 = icmp eq i32 %40, -2
br i1 %41, label %42, label %54
42: ; preds = %39
%43 = load i8**, i8*** %12
%44 = load i8*, i8** %43
%45 = bitcast i8* %44 to %struct.local_struct*
store %struct.local_struct* %45, %struct.local_struct** %13
%46 = load i8*, i8** %11
%47 = load %struct.local_struct*, %struct.local_struct** %13
%48 = getelementptr inbounds %struct.local_struct, %struct.local_struct* %47, i32 0, i32 0
%49 = load i32, i32* %48
%50 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %49)
%51 = load %struct.local_struct*, %struct.local_struct** %13
%52 = bitcast %struct.local_struct* %51 to %struct.local_struct.0*
%53 = call i32 @free(%struct.local_struct.0* %52)
br label %54
54: ; preds = %42, %39
br label %55
55: ; preds = %54, %31
br label %56
56: ; preds = %55, %25
ret i32 0
}

LLVM IR (-O2):
%struct.local_struct = type { i32 }
%struct.local_struct.0 = type opaque
@.str = [27 x i8] c"f_count memory allocation \00"
@.str.1 = [1 x i8] zeroinitializer
@.str.2 = [22 x i8] c"number of records: %d\00"
define i32 @f_count(i32 %0, i8** nocapture readnone %1, float* nocapture readnone %2, i32 %3, i8* nocapture writeonly %4, i8** nocapture %5) {
%7 = icmp eq i32 %0, -1
br i1 %7, label %8, label %17
8: ; preds = %6
%9 = tail call i64 @malloc(i32 4)
%10 = inttoptr i64 %9 to %struct.local_struct*
%11 = inttoptr i64 %9 to i8*
store i8* %11, i8** %5
%12 = icmp eq i64 %9, 0
br i1 %12, label %13, label %15
13: ; preds = %8
%14 = tail call i32 @fatal_error(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0))
br label %15
15: ; preds = %13, %8
%16 = getelementptr inbounds %struct.local_struct, %struct.local_struct* %10, i64 0, i32 0
store i32 0, i32* %16
br label %35
17: ; preds = %6
%18 = icmp sgt i32 %0, -1
br i1 %18, label %19, label %25
19: ; preds = %17
%20 = bitcast i8** %5 to %struct.local_struct**
%21 = load %struct.local_struct*, %struct.local_struct** %20
%22 = getelementptr inbounds %struct.local_struct, %struct.local_struct* %21, i64 0, i32 0
%23 = load i32, i32* %22
%24 = add nsw i32 %23, 1
store i32 %24, i32* %22
br label %35
25: ; preds = %17
%26 = icmp eq i32 %0, -2
br i1 %26, label %27, label %35
27: ; preds = %25
%28 = bitcast i8** %5 to %struct.local_struct**
%29 = load %struct.local_struct*, %struct.local_struct** %28
%30 = getelementptr inbounds %struct.local_struct, %struct.local_struct* %29, i64 0, i32 0
%31 = load i32, i32* %30
%32 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i32 %31)
%33 = bitcast %struct.local_struct* %29 to %struct.local_struct.0*
%34 = tail call i32 @free(%struct.local_struct.0* %33)
br label %35
35: ; preds = %19, %27, %25, %15
ret i32 0
}