#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 */
struct RadarParm {
  int dummy;
};
struct FitData {
  int dummy;
};
struct DataMap {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ DataMapFree(struct DataMap *);
struct DataMap *DataMapMake();
int DataMapSize(struct DataMap *);
int DataMapWrite(int, struct DataMap *);
int FitEncode(struct DataMap *, struct RadarParm *, struct FitData *);
int RadarParmEncode(struct DataMap *, struct RadarParm *);
int FitWrite(int fid, struct RadarParm *prm, struct FitData *fit) {
  int s;
  struct DataMap *ptr = NULL;
  ptr = DataMapMake();
  if (ptr == NULL)
    return -1;
  s = RadarParmEncode(ptr, prm);
  if (s == 0)
    s = FitEncode(ptr, prm, fit);
  if (s == 0) {
    if (fid != -1)
      s = DataMapWrite(fid, ptr);
    else
      s = DataMapSize(ptr);
  }
  DataMapFree(ptr);
  return s;
}


x86 assembly (clang, -O0):
<FitWrite>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movq   $0x0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <DataMapMake@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    119d <FitWrite+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    1213 <FitWrite+0xb3>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <RadarParmEncode@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    11cb <FitWrite+0x6b>
mov    -0x28(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1060 <FitEncode@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1204 <FitWrite+0xa4>
cmpl   $0xffffffff,-0x8(%rbp)
je     11f3 <FitWrite+0x93>
mov    -0x8(%rbp),%edi
mov    -0x28(%rbp),%rsi
call   1070 <DataMapWrite@plt>
mov    %eax,-0x1c(%rbp)
jmp    11ff <FitWrite+0x9f>
mov    -0x28(%rbp),%rdi
call   1080 <DataMapSize@plt>
mov    %eax,-0x1c(%rbp)
jmp    1204 <FitWrite+0xa4>
mov    -0x28(%rbp),%rdi
call   1040 <DataMapFree@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<FitWrite>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdx,%r15
mov    %rsi,%r12
mov    %edi,%r14d
xor    %eax,%eax
call   1030 <DataMapMake@plt>
test   %rax,%rax
je     11b8 <FitWrite+0x58>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r12,%rsi
call   1050 <RadarParmEncode@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11c9 <FitWrite+0x69>
mov    %rbx,%rdi
mov    %r12,%rsi
mov    %r15,%rdx
call   1060 <FitEncode@plt>
mov    %eax,%ebp
test   %eax,%eax
jne    11c9 <FitWrite+0x69>
cmp    $0xffffffff,%r14d
je     11bf <FitWrite+0x5f>
mov    %r14d,%edi
mov    %rbx,%rsi
call   1070 <DataMapWrite@plt>
jmp    11c7 <FitWrite+0x67>
mov    $0xffffffff,%ebp
jmp    11d1 <FitWrite+0x71>
mov    %rbx,%rdi
call   1080 <DataMapSize@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <DataMapFree@plt>
mov    %ebp,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.RadarParm = type { i32 }
%struct.FitData = type { i32 }
%struct.DataMap = type { i32 }
define i32 @FitWrite(i32 %0, %struct.RadarParm* %1, %struct.FitData* %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca %struct.RadarParm*
%7 = alloca %struct.FitData*
%8 = alloca i32
%9 = alloca %struct.DataMap*
store i32 %0, i32* %5
store %struct.RadarParm* %1, %struct.RadarParm** %6
store %struct.FitData* %2, %struct.FitData** %7
store %struct.DataMap* null, %struct.DataMap** %9
%10 = call %struct.DataMap* (...) @DataMapMake()
store %struct.DataMap* %10, %struct.DataMap** %9
%11 = load %struct.DataMap*, %struct.DataMap** %9
%12 = icmp eq %struct.DataMap* %11, null
br i1 %12, label %13, label %14
13: ; preds = %3
store i32 -1, i32* %4
br label %43
14: ; preds = %3
%15 = load %struct.DataMap*, %struct.DataMap** %9
%16 = load %struct.RadarParm*, %struct.RadarParm** %6
%17 = call i32 @RadarParmEncode(%struct.DataMap* %15, %struct.RadarParm* %16)
store i32 %17, i32* %8
%18 = load i32, i32* %8
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %25
20: ; preds = %14
%21 = load %struct.DataMap*, %struct.DataMap** %9
%22 = load %struct.RadarParm*, %struct.RadarParm** %6
%23 = load %struct.FitData*, %struct.FitData** %7
%24 = call i32 @FitEncode(%struct.DataMap* %21, %struct.RadarParm* %22, %struct.FitData* %23)
store i32 %24, i32* %8
br label %25
25: ; preds = %20, %14
%26 = load i32, i32* %8
%27 = icmp eq i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %25
%29 = load i32, i32* %5
%30 = icmp ne i32 %29, -1
br i1 %30, label %31, label %35
31: ; preds = %28
%32 = load i32, i32* %5
%33 = load %struct.DataMap*, %struct.DataMap** %9
%34 = call i32 @DataMapWrite(i32 %32, %struct.DataMap* %33)
store i32 %34, i32* %8
br label %38
35: ; preds = %28
%36 = load %struct.DataMap*, %struct.DataMap** %9
%37 = call i32 @DataMapSize(%struct.DataMap* %36)
store i32 %37, i32* %8
br label %38
38: ; preds = %35, %31
br label %39
39: ; preds = %38, %25
%40 = load %struct.DataMap*, %struct.DataMap** %9
%41 = call i32 @DataMapFree(%struct.DataMap* %40)
%42 = load i32, i32* %8
store i32 %42, i32* %4
br label %43
43: ; preds = %39, %13
%44 = load i32, i32* %4
ret i32 %44
}

LLVM IR (-O2):
%struct.RadarParm = type { i32 }
%struct.FitData = type { i32 }
%struct.DataMap = type { i32 }
define i32 @FitWrite(i32 %0, %struct.RadarParm* %1, %struct.FitData* %2) {
%4 = tail call %struct.DataMap* (...) @DataMapMake()
%5 = icmp eq %struct.DataMap* %4, null
br i1 %5, label %21, label %6
6: ; preds = %3
%7 = tail call i32 @RadarParmEncode(%struct.DataMap* %4, %struct.RadarParm* %1)
%8 = icmp eq i32 %7, 0
br i1 %8, label %9, label %18
9: ; preds = %6
%10 = tail call i32 @FitEncode(%struct.DataMap* %4, %struct.RadarParm* %1, %struct.FitData* %2)
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %18
12: ; preds = %9
%13 = icmp eq i32 %0, -1
br i1 %13, label %16, label %14
14: ; preds = %12
%15 = tail call i32 @DataMapWrite(i32 %0, %struct.DataMap* %4)
br label %18
16: ; preds = %12
%17 = tail call i32 @DataMapSize(%struct.DataMap* %4)
br label %18
18: ; preds = %6, %14, %16, %9
%19 = phi i32 [ %15, %14 ], [ %17, %16 ], [ %10, %9 ], [ %7, %6 ]
%20 = tail call i32 @DataMapFree(%struct.DataMap* %4)
br label %21
21: ; preds = %3, %18
%22 = phi i32 [ %19, %18 ], [ -1, %3 ]
ret i32 %22
}