#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 atoi(char *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, int);
int /*<<< orphan*/ mw100_enable_power_dump(char *);
int /*<<< orphan*/ mw100_recorder_init(char *, int, double, int);
int /*<<< orphan*/ mw100_recorder_start(int /*<<< orphan*/);
int /*<<< orphan*/ mw100_recorder_stop(int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ *stdout;
int main(int argc, char *argv[]) {
  int total_time;
  FILE *p_out;
  if (argc <= 1 || argc > 3) {
    perror("[-] Usage: powerdump <total_time> [out_file]\n");
    exit(1);
  }
  total_time = atoi(argv[1]);
  if (argc == 3) {
    p_out = fopen(argv[2], "w");
    if (!p_out) {
      perror("[-] Couldn't open file.");
      exit(1);
    }
    fprintf(p_out, "%d\n", total_time);
    fclose(p_out);
  } else
    fprintf(stdout, "%d\n", total_time);
  mw100_recorder_init("200.18.98.206", 34318, 0.5, 9);
  if (argc == 3)
    mw100_enable_power_dump(argv[2]);
  else
    mw100_enable_power_dump("");
  mw100_recorder_start(0);
  sleep(total_time);
  mw100_recorder_stop(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11da <main+0x2a>
cmpl   $0x3,-0x8(%rbp)
jle    11f0 <main+0x40>
lea    0xe27(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   10b0 <atoi@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x3,-0x8(%rbp)
jne    1264 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe1d(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1243 <main+0x93>
lea    0xe04(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xdff(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    127d <main+0xcd>
mov    0x2d75(%rip),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%edx
lea    0xdd8(%rip),%rsi
call   1050 <fprintf@plt>
lea    0xdd0(%rip),%rdi
mov    $0x860e,%esi
movsd  0xd6f(%rip),%xmm0
mov    $0x9,%edx
call   1090 <mw100_recorder_init@plt>
cmpl   $0x3,-0x8(%rbp)
jne    12b7 <main+0x107>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1060 <mw100_enable_power_dump@plt>
jmp    12c3 <main+0x113>
lea    0xd77(%rip),%rdi
call   1060 <mw100_enable_power_dump@plt>
xor    %edi,%edi
call   1040 <mw100_recorder_start@plt>
mov    -0x14(%rbp),%edi
call   10d0 <sleep@plt>
xor    %edi,%edi
call   10a0 <mw100_recorder_stop@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    %edi,%ebp
lea    -0x4(%rbp),%eax
cmp    $0xfffffffd,%eax
jbe    1290 <main+0xe0>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
call   10b0 <atoi@plt>
mov    %eax,%r14d
cmp    $0x3,%ebp
jne    1230 <main+0x80>
mov    0x10(%rbx),%rdi
lea    0xe55(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     1299 <main+0xe9>
mov    %rax,%rbp
lea    0xe57(%rip),%rsi
mov    %rax,%rdi
mov    %r14d,%edx
call   1050 <fprintf@plt>
mov    %rbp,%rdi
call   1030 <fclose@plt>
lea    0xe41(%rip),%rdi
movsd  0xde5(%rip),%xmm0
mov    $0x860e,%esi
mov    $0x9,%edx
call   1090 <mw100_recorder_init@plt>
mov    0x10(%rbx),%rdi
jmp    126e <main+0xbe>
mov    0x2da9(%rip),%rax
mov    (%rax),%rdi
lea    0xe0f(%rip),%rsi
mov    %r14d,%edx
call   1050 <fprintf@plt>
lea    0xe04(%rip),%rdi
movsd  0xda8(%rip),%xmm0
mov    $0x860e,%esi
mov    $0x9,%edx
call   1090 <mw100_recorder_init@plt>
lea    0xdc7(%rip),%rdi
call   1060 <mw100_enable_power_dump@plt>
xor    %edi,%edi
call   1040 <mw100_recorder_start@plt>
mov    %r14d,%edi
call   10d0 <sleep@plt>
xor    %edi,%edi
call   10a0 <mw100_recorder_stop@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xd71(%rip),%rdi
jmp    12a0 <main+0xf0>
lea    0xd98(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [46 x i8] c"[-] Usage: powerdump <total_time> [out_file]\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [24 x i8] c"[-] Couldn't open file.\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@stdout = global i32* null
@.str.4 = [14 x i8] c"200.18.98.206\00"
@.str.5 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %2
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 3
br i1 %12, label %13, label %16
13: ; preds = %10, %2
%14 = call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%15 = call i32 @exit(i32 1)
unreachable
16: ; preds = %10
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @atoi(i8* %19)
store i32 %20, i32* %6
%21 = load i32, i32* %4
%22 = icmp eq i32 %21, 3
br i1 %22, label %23, label %39
23: ; preds = %16
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %27, i32** %7
%28 = load i32*, i32** %7
%29 = icmp ne i32* %28, null
br i1 %29, label %33, label %30
30: ; preds = %23
%31 = call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%32 = call i32 @exit(i32 1)
unreachable
33: ; preds = %23
%34 = load i32*, i32** %7
%35 = load i32, i32* %6
%36 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = load i32*, i32** %7
%38 = call i32 @fclose(i32* %37)
br label %43
39: ; preds = %16
%40 = load i32*, i32** @stdout
%41 = load i32, i32* %6
%42 = call i32 @fprintf(i32* %40, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %41)
br label %43
43: ; preds = %39, %33
%44 = call i32 @mw100_recorder_init(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 34318, double 5.000000e-01, i32 9)
%45 = load i32, i32* %4
%46 = icmp eq i32 %45, 3
br i1 %46, label %47, label %52
47: ; preds = %43
%48 = load i8**, i8*** %5
%49 = getelementptr inbounds i8*, i8** %48, i64 2
%50 = load i8*, i8** %49
%51 = call i32 @mw100_enable_power_dump(i8* %50)
br label %54
52: ; preds = %43
%53 = call i32 @mw100_enable_power_dump(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0))
br label %54
54: ; preds = %52, %47
%55 = call i32 @mw100_recorder_start(i32 0)
%56 = load i32, i32* %6
%57 = call i32 @sleep(i32 %56)
%58 = call i32 @mw100_recorder_stop(i32 0)
ret i32 0
}

LLVM IR (-O2):
@.str = [46 x i8] c"[-] Usage: powerdump <total_time> [out_file]\0A\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [24 x i8] c"[-] Couldn't open file.\00"
@.str.3 = [4 x i8] c"%d\0A\00"
@stdout = global i32* null
@.str.4 = [14 x i8] c"200.18.98.206\00"
@.str.5 = [1 x i8] zeroinitializer
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = add i32 %0, -4
%4 = icmp ult i32 %3, -2
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0))
%7 = tail call i32 @exit(i32 1)
unreachable
8: ; preds = %2
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
%11 = tail call i32 @atoi(i8* %10)
%12 = icmp eq i32 %0, 3
br i1 %12, label %13, label %26
13: ; preds = %8
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = tail call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%17 = icmp eq i32* %16, null
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = tail call i32 @perror(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%20 = tail call i32 @exit(i32 1)
unreachable
21: ; preds = %13
%22 = tail call i32 @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%23 = tail call i32 @fclose(i32* %16)
%24 = tail call i32 @mw100_recorder_init(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 34318, double 5.000000e-01, i32 9)
%25 = load i8*, i8** %14
br label %30
26: ; preds = %8
%27 = load i32*, i32** @stdout
%28 = tail call i32 @fprintf(i32* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %11)
%29 = tail call i32 @mw100_recorder_init(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 34318, double 5.000000e-01, i32 9)
br label %30
30: ; preds = %26, %21
%31 = phi i8* [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.5, i64 0, i64 0), %26 ], [ %25, %21 ]
%32 = tail call i32 @mw100_enable_power_dump(i8* %31)
%33 = tail call i32 @mw100_recorder_start(i32 0)
%34 = tail call i32 @sleep(i32 %11)
%35 = tail call i32 @mw100_recorder_stop(i32 0)
ret i32 0
}