#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*/ ProcessCSV(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                              char *, char *, char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ *stderr;
int main(int argc, char *argv[]) {
  FILE *fpout, *fpin1, *fpin2;
  if (argc != 4) {
    fprintf(stderr,
            "Usage: csv2antenna <outfile> <elevation gains> <azimuth gains>\n");
    exit(2);
  }
  fpin1 = fopen(argv[2], "r");
  if (!fpin1) {
    perror("Could not open input file");
    exit(2);
  }
  fpin2 = fopen(argv[3], "r");
  if (!fpin2) {
    perror("Could not open input file");
    exit(2);
  }
  fpout = fopen(argv[1], "w");
  if (!fpout) {
    perror("Could not open input file");
    exit(2);
  }
  fprintf(fpout, "<antenna>\n<elevation>\n");
  ProcessCSV(fpin1, fpout, "gainsample", "angle", "gain");
  fprintf(fpout, "</elevation>\n<azimuth>\n");
  ProcessCSV(fpin2, fpout, "gainsample", "angle", "gain");
  fprintf(fpout, "</azimuth>\n</antenna>\n");
  fclose(fpin1);
  fclose(fpin2);
  fclose(fpout);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x4,-0x4(%rbp)
je     1199 <main+0x39>
mov    0x2e60(%rip),%rax
mov    (%rax),%rdi
lea    0xe76(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <main+0x72>
lea    0xe7f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
lea    0xe5f(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    120b <main+0xab>
lea    0xe46(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe42(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1244 <main+0xe4>
lea    0xe0d(%rip),%rdi
call   1070 <perror@plt>
mov    $0x2,%edi
call   1080 <exit@plt>
mov    -0x18(%rbp),%rdi
lea    0xe0f(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xe12(%rip),%rdx
lea    0xe16(%rip),%rcx
lea    0xe15(%rip),%r8
call   1040 <ProcessCSV@plt>
mov    -0x18(%rbp),%rdi
lea    0xe0a(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x28(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    0xde0(%rip),%rdx
lea    0xde4(%rip),%rcx
lea    0xde3(%rip),%r8
call   1040 <ProcessCSV@plt>
mov    -0x18(%rbp),%rdi
lea    0xdf0(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x4,%edi
jne    1292 <main+0x132>
mov    %rsi,%rbx
mov    0x10(%rsi),%rdi
lea    0xebe(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     127c <main+0x11c>
mov    %rax,%r14
mov    0x18(%rbx),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     127c <main+0x11c>
mov    %rax,%r15
mov    0x8(%rbx),%rdi
lea    0xea2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     127c <main+0x11c>
mov    %rax,%rbx
lea    0xe8c(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1080 <fwrite@plt>
lea    0xe8a(%rip),%r12
lea    0xe8e(%rip),%r13
lea    0xe8d(%rip),%rbp
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1040 <ProcessCSV@plt>
lea    0xe77(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    %r13,%rcx
mov    %rbp,%r8
call   1040 <ProcessCSV@plt>
lea    0xe62(%rip),%rdi
mov    $0x16,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1080 <fwrite@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdbf(%rip),%rdi
call   1060 <perror@plt>
mov    $0x2,%edi
call   1070 <exit@plt>
mov    0x2d47(%rip),%rax
mov    (%rax),%rcx
lea    0xd5d(%rip),%rdi
mov    $0x3f,%esi
mov    $0x1,%edx
call   1080 <fwrite@plt>
mov    $0x2,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32* null
@.str = [64 x i8] c"Usage: csv2antenna <outfile> <elevation gains> <azimuth gains>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Could not open input file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [23 x i8] c"<antenna>\0A<elevation>\0A\00"
@.str.5 = [11 x i8] c"gainsample\00"
@.str.6 = [6 x i8] c"angle\00"
@.str.7 = [5 x i8] c"gain\00"
@.str.8 = [24 x i8] c"</elevation>\0A<azimuth>\0A\00"
@.str.9 = [23 x i8] c"</azimuth>\0A</antenna>\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32*
store i32 %0, i32* %3
store i8** %1, i8*** %4
%8 = load i32, i32* %3
%9 = icmp ne i32 %8, 4
br i1 %9, label %10, label %14
10: ; preds = %2
%11 = load i32*, i32** @stderr
%12 = call i32 @fprintf(i32* %11, i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @exit(i32 2)
unreachable
14: ; preds = %2
%15 = load i8**, i8*** %4
%16 = getelementptr inbounds i8*, i8** %15, i64 2
%17 = load i8*, i8** %16
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %18, i32** %6
%19 = load i32*, i32** %6
%20 = icmp ne i32* %19, null
br i1 %20, label %24, label %21
21: ; preds = %14
%22 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%23 = call i32 @exit(i32 2)
unreachable
24: ; preds = %14
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = call i32* @fopen(i8* %27, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %28, i32** %7
%29 = load i32*, i32** %7
%30 = icmp ne i32* %29, null
br i1 %30, label %34, label %31
31: ; preds = %24
%32 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%33 = call i32 @exit(i32 2)
unreachable
34: ; preds = %24
%35 = load i8**, i8*** %4
%36 = getelementptr inbounds i8*, i8** %35, i64 1
%37 = load i8*, i8** %36
%38 = call i32* @fopen(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %38, i32** %5
%39 = load i32*, i32** %5
%40 = icmp ne i32* %39, null
br i1 %40, label %44, label %41
41: ; preds = %34
%42 = call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%43 = call i32 @exit(i32 2)
unreachable
44: ; preds = %34
%45 = load i32*, i32** %5
%46 = call i32 @fprintf(i32* %45, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0))
%47 = load i32*, i32** %6
%48 = load i32*, i32** %5
%49 = call i32 @ProcessCSV(i32* %47, i32* %48, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%50 = load i32*, i32** %5
%51 = call i32 @fprintf(i32* %50, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0))
%52 = load i32*, i32** %7
%53 = load i32*, i32** %5
%54 = call i32 @ProcessCSV(i32* %52, i32* %53, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%55 = load i32*, i32** %5
%56 = call i32 @fprintf(i32* %55, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0))
%57 = load i32*, i32** %6
%58 = call i32 @fclose(i32* %57)
%59 = load i32*, i32** %7
%60 = call i32 @fclose(i32* %59)
%61 = load i32*, i32** %5
%62 = call i32 @fclose(i32* %61)
ret i32 0
}

LLVM IR (-O2):
@stderr = global i32* null
@.str = [64 x i8] c"Usage: csv2antenna <outfile> <elevation gains> <azimuth gains>\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [26 x i8] c"Could not open input file\00"
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [23 x i8] c"<antenna>\0A<elevation>\0A\00"
@.str.5 = [11 x i8] c"gainsample\00"
@.str.6 = [6 x i8] c"angle\00"
@.str.7 = [5 x i8] c"gain\00"
@.str.8 = [24 x i8] c"</elevation>\0A<azimuth>\0A\00"
@.str.9 = [23 x i8] c"</azimuth>\0A</antenna>\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 4
br i1 %3, label %8, label %4
4: ; preds = %2
%5 = load i32*, i32** @stderr
%6 = tail call i64 @fwrite(i8* getelementptr inbounds ([64 x i8], [64 x i8]* @.str, i64 0, i64 0), i64 63, i64 1, i32* %5)
%7 = tail call i32 @exit(i32 2)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 2
%10 = load i8*, i8** %9
%11 = tail call i32* @fopen(i8* %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %8
%14 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 2)
unreachable
16: ; preds = %8
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = tail call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp eq i32* %19, null
br i1 %20, label %21, label %24
21: ; preds = %16
%22 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%23 = tail call i32 @exit(i32 2)
unreachable
24: ; preds = %16
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = tail call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %32
29: ; preds = %24
%30 = tail call i32 @perror(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%31 = tail call i32 @exit(i32 2)
unreachable
32: ; preds = %24
%33 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.4, i64 0, i64 0), i64 22, i64 1, i32* %27)
%34 = tail call i32 @ProcessCSV(i32* %11, i32* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%35 = tail call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.8, i64 0, i64 0), i64 23, i64 1, i32* %27)
%36 = tail call i32 @ProcessCSV(i32* %19, i32* %27, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0))
%37 = tail call i64 @fwrite(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.9, i64 0, i64 0), i64 22, i64 1, i32* %27)
%38 = tail call i32 @fclose(i32* %11)
%39 = tail call i32 @fclose(i32* %19)
%40 = tail call i32 @fclose(i32* %27)
ret i32 0
}