#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 EDOM;
double atof(char *);
int atoi(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char const *, char *);
int rapl_pkg_limit_test(double, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strlen(char *);
int /*<<< orphan*/ strncmp(char *, char *, int /*<<< orphan*/);
int main(int argc, char **argv) {
  const char *usage = "%s package_limit_watts [num_rep]\n"
                      "    default num_rep=10\n";
  int err = 0;
  double power_limit = 0.0;
  int num_rep = 10;
  if (argc < 2 || !strncmp(argv[1], "--help", strlen("--help")) ||
      !strncmp(argv[1], "-h", strlen("-h"))) {
    fprintf(stderr, usage, argv[0]);
    err = -1;
  }
  if (!err) {
    power_limit = atof(argv[1]);
    if (power_limit <= 0.0) {
      err = EDOM;
    }
  }
  if (!err) {
    if (argc == 3) {
      num_rep = atoi(argv[2]);
      if (num_rep <= 0) {
        err = EDOM;
      }
    }
  }
  if (!err) {
    err = rapl_pkg_limit_test(power_limit, num_rep);
  }
  return err;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0xa,-0x2c(%rbp)
cmpl   $0x2,-0x8(%rbp)
jl     1207 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
lea    0xe85(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x38(%rbp),%rdi
mov    %eax,%edx
lea    0xe73(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
je     1207 <main+0xa7>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x40(%rbp)
lea    0xe59(%rip),%rdi
call   1050 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    %eax,%edx
lea    0xe47(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%eax
jne    1227 <main+0xc7>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rsi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jne    1262 <main+0x102>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <atof@plt>
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x28(%rbp),%xmm0
jb     125d <main+0xfd>
mov    0x2d90(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    1262 <main+0x102>
cmpl   $0x0,-0x1c(%rbp)
jne    12a6 <main+0x146>
cmpl   $0x3,-0x8(%rbp)
jne    12a1 <main+0x141>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jg     129c <main+0x13c>
mov    0x2d51(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
jmp    12a1 <main+0x141>
jmp    12a6 <main+0x146>
cmpl   $0x0,-0x1c(%rbp)
jne    12c0 <main+0x160>
movsd  -0x28(%rbp),%xmm0
mov    -0x2c(%rbp),%edi
call   1060 <rapl_pkg_limit_test@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     121e <main+0xbe>
mov    %edi,%r14d
mov    0x8(%rbx),%rbp
lea    0xeb8(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     121e <main+0xbe>
mov    0x8(%rbx),%rbp
lea    0xe97(%rip),%r15
mov    %r15,%rdi
call   1050 <strlen@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %eax,%eax
je     121e <main+0xbe>
mov    0x8(%rbx),%rdi
call   1040 <atof@plt>
xor    %eax,%eax
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%ebp
cmovae %ebp,%eax
mov    $0xa,%edi
cmp    $0x3,%r14d
jne    120b <main+0xab>
test   %eax,%eax
jne    120b <main+0xab>
mov    0x10(%rbx),%rdi
movsd  %xmm0,(%rsp)
call   1080 <atoi@plt>
movsd  (%rsp),%xmm0
mov    %eax,%edi
mov    %ebp,%eax
test   %edi,%edi
jg     120f <main+0xaf>
test   %eax,%eax
jne    123b <main+0xdb>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1060 <rapl_pkg_limit_test@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdcf(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [57 x i8] c"%s package_limit_watts [num_rep]\0A default num_rep=10\0A\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [3 x i8] c"-h\00"
@stderr = global i32 0
@EDOM = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca double
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 0, i32* %7
store double 0.000000e+00, double* %8
store i32 10, i32* %9
%10 = load i32, i32* %4
%11 = icmp slt i32 %10, 2
br i1 %11, label %26, label %12
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @strncmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %26
19: ; preds = %12
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = call i32 @strncmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = icmp ne i32 %24, 0
br i1 %25, label %33, label %26
26: ; preds = %19, %12, %2
%27 = load i32, i32* @stderr
%28 = load i8*, i8** %6
%29 = load i8**, i8*** %5
%30 = getelementptr inbounds i8*, i8** %29, i64 0
%31 = load i8*, i8** %30
%32 = call i32 @fprintf(i32 %27, i8* %28, i8* %31)
store i32 -1, i32* %7
br label %33
33: ; preds = %26, %19
%34 = load i32, i32* %7
%35 = icmp ne i32 %34, 0
br i1 %35, label %46, label %36
36: ; preds = %33
%37 = load i8**, i8*** %5
%38 = getelementptr inbounds i8*, i8** %37, i64 1
%39 = load i8*, i8** %38
%40 = call double @atof(i8* %39)
store double %40, double* %8
%41 = load double, double* %8
%42 = fcmp ole double %41, 0.000000e+00
br i1 %42, label %43, label %45
43: ; preds = %36
%44 = load i32, i32* @EDOM
store i32 %44, i32* %7
br label %45
45: ; preds = %43, %36
br label %46
46: ; preds = %45, %33
%47 = load i32, i32* %7
%48 = icmp ne i32 %47, 0
br i1 %48, label %63, label %49
49: ; preds = %46
%50 = load i32, i32* %4
%51 = icmp eq i32 %50, 3
br i1 %51, label %52, label %62
52: ; preds = %49
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 2
%55 = load i8*, i8** %54
%56 = call i32 @atoi(i8* %55)
store i32 %56, i32* %9
%57 = load i32, i32* %9
%58 = icmp sle i32 %57, 0
br i1 %58, label %59, label %61
59: ; preds = %52
%60 = load i32, i32* @EDOM
store i32 %60, i32* %7
br label %61
61: ; preds = %59, %52
br label %62
62: ; preds = %61, %49
br label %63
63: ; preds = %62, %46
%64 = load i32, i32* %7
%65 = icmp ne i32 %64, 0
br i1 %65, label %70, label %66
66: ; preds = %63
%67 = load double, double* %8
%68 = load i32, i32* %9
%69 = call i32 @rapl_pkg_limit_test(double %67, i32 %68)
store i32 %69, i32* %7
br label %70
70: ; preds = %66, %63
%71 = load i32, i32* %7
ret i32 %71
}

LLVM IR (-O2):
@.str = [57 x i8] c"%s package_limit_watts [num_rep]\0A default num_rep=10\0A\00"
@.str.1 = [7 x i8] c"--help\00"
@.str.2 = [3 x i8] c"-h\00"
@stderr = global i32 0
@EDOM = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %15, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%8 = tail call i32 @strncmp(i8* %6, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, 0
br i1 %9, label %15, label %10
10: ; preds = %4
%11 = load i8*, i8** %5
%12 = tail call i32 @strlen(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%13 = tail call i32 @strncmp(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = icmp eq i32 %13, 0
br i1 %14, label %15, label %19
15: ; preds = %10, %4, %2
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %1
%18 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %40
19: ; preds = %10
%20 = load i8*, i8** %5
%21 = tail call double @atof(i8* %20)
%22 = fcmp ugt double %21, 0.000000e+00
%23 = load i32, i32* @EDOM
%24 = select i1 %22, i32 0, i32 %23
%25 = icmp eq i32 %24, 0
%26 = icmp eq i32 %0, 3
%27 = and i1 %26, %25
br i1 %27, label %28, label %33
28: ; preds = %19
%29 = getelementptr inbounds i8*, i8** %1, i64 2
%30 = load i8*, i8** %29
%31 = tail call i32 @atoi(i8* %30)
%32 = icmp slt i32 %31, 1
br i1 %32, label %33, label %37
33: ; preds = %28, %19
%34 = phi i32 [ %24, %19 ], [ %23, %28 ]
%35 = phi i32 [ 10, %19 ], [ %31, %28 ]
%36 = icmp eq i32 %34, 0
br i1 %36, label %37, label %40
37: ; preds = %28, %33
%38 = phi i32 [ %35, %33 ], [ %31, %28 ]
%39 = tail call i32 @rapl_pkg_limit_test(double %21, i32 %38)
br label %40
40: ; preds = %15, %37, %33
%41 = phi i32 [ %34, %33 ], [ %39, %37 ], [ -1, %15 ]
ret i32 %41
}