#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*/ real_path;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int atoi(char *);
int bat_info(char *, char *, int, int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int main(int argc, char *argv[]) {
  char *path = "/sys/class/power_supply/BAT%i/uevent";
  char *format = "%s %i";
  int index = 0;
  int interval = 3;
  bool snoop = false;
  bool emoji = false;
  bool quiet = false;
  int opt;
  while ((opt = getopt(argc, argv, "hseqf:i:p:n:")) != -1) {
    switch (opt) {
    case 'h':
      printf("battery [-h|-s|-e|-q|-f FORMAT|-i INTERVAL|-p PATH|-n INDEX]\n");
      exit(EXIT_SUCCESS);
      break;
    case 's':
      snoop = true;
      break;
    case 'f':
      format = optarg;
      break;
    case 'p':
      path = optarg;
      break;
    case 'i':
      interval = atoi(optarg);
      break;
    case 'n':
      index = atoi(optarg);
      break;
    case 'e':
      emoji = true;
      break;
    case 'q':
      quiet = true;
      break;
    }
  }
  char real_path[256] = {0};
  snprintf(real_path, sizeof(real_path), path, index);
  int exit_code;
  if (snoop)
    while ((exit_code = bat_info(real_path, format, emoji, quiet)) !=
           EXIT_FAILURE)
      sleep(interval);
  else
    exit_code = bat_info(real_path, format, emoji, quiet);
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x150,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe9c(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xeb6(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x3,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x0,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe87(%rip),%rdx
call   1070 <getopt@plt>
mov    %eax,-0x38(%rbp)
cmp    $0xffffffff,%eax
je     12b2 <main+0x132>
mov    -0x38(%rbp),%eax
add    $0xffffff9b,%eax
mov    %eax,%ecx
mov    %rcx,-0x150(%rbp)
sub    $0xe,%eax
ja     12ad <main+0x12d>
mov    -0x150(%rbp),%rax
lea    0xde9(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
mov    0x2d9d(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
movl   $0x1,-0x2c(%rbp)
jmp    12ad <main+0x12d>
mov    0x2dab(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    12ad <main+0x12d>
mov    0x2d98(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    12ad <main+0x12d>
mov    0x2d85(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    12ad <main+0x12d>
mov    0x2d6e(%rip),%rax
mov    (%rax),%rdi
call   1080 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    12ad <main+0x12d>
movl   $0x1,-0x30(%rbp)
jmp    12ad <main+0x12d>
movl   $0x1,-0x34(%rbp)
jmp    11d2 <main+0x52>
lea    -0x140(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x140(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x100,%esi
call   1040 <snprintf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     1329 <main+0x1a9>
jmp    12ec <main+0x16c>
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
call   1060 <bat_info@plt>
mov    %eax,-0x144(%rbp)
mov    0x2cc9(%rip),%rcx
cmp    (%rcx),%eax
je     1324 <main+0x1a4>
mov    -0x28(%rbp),%edi
call   10a0 <sleep@plt>
jmp    12ec <main+0x16c>
jmp    1345 <main+0x1c5>
lea    -0x140(%rbp),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%edx
mov    -0x34(%rbp),%ecx
call   1060 <bat_info@plt>
mov    %eax,-0x144(%rbp)
mov    -0x144(%rbp),%eax
add    $0x150,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x128,%rsp
mov    %rsi,%r12
mov    %edi,%r13d
lea    0xeae(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x3,(%rsp)
movl   $0x0,0x4(%rsp)
lea    0xeb8(%rip),%rax
mov    %rax,0x18(%rsp)
lea    0xeb2(%rip),%r14
lea    0xe44(%rip),%r15
mov    0x2e35(%rip),%rbx
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
xor    %ebp,%ebp
jmp    11e0 <main+0x70>
mov    $0x1,%ebp
nopl   0x0(%rax)
mov    %r13d,%edi
mov    %r12,%rsi
mov    %r14,%rdx
call   1060 <getopt@plt>
lea    -0x65(%rax),%ecx
cmp    $0xe,%ecx
ja     1242 <main+0xd2>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
movl   $0x1,0xc(%rsp)
jmp    11e0 <main+0x70>
mov    (%rbx),%rax
mov    %rax,0x18(%rsp)
jmp    11e0 <main+0x70>
mov    (%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,(%rsp)
jmp    11e0 <main+0x70>
mov    (%rbx),%rdi
call   1070 <atoi@plt>
mov    %eax,0x4(%rsp)
jmp    11e0 <main+0x70>
mov    (%rbx),%rax
mov    %rax,0x10(%rsp)
jmp    11e0 <main+0x70>
movl   $0x1,0x8(%rsp)
jmp    11e0 <main+0x70>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x70>
xorps  %xmm0,%xmm0
movaps %xmm0,0x110(%rsp)
movaps %xmm0,0x100(%rsp)
movaps %xmm0,0xf0(%rsp)
movaps %xmm0,0xe0(%rsp)
movaps %xmm0,0xd0(%rsp)
movaps %xmm0,0xc0(%rsp)
movaps %xmm0,0xb0(%rsp)
movaps %xmm0,0xa0(%rsp)
movaps %xmm0,0x90(%rsp)
movaps %xmm0,0x80(%rsp)
movaps %xmm0,0x70(%rsp)
movaps %xmm0,0x60(%rsp)
movaps %xmm0,0x50(%rsp)
movaps %xmm0,0x40(%rsp)
movaps %xmm0,0x30(%rsp)
movaps %xmm0,0x20(%rsp)
lea    0x20(%rsp),%r14
mov    %r14,%rdi
mov    $0x100,%esi
mov    0x10(%rsp),%rdx
mov    0x4(%rsp),%ecx
call   1040 <snprintf@plt>
mov    %r14,%rdi
mov    0x18(%rsp),%r12
mov    %r12,%rsi
mov    0xc(%rsp),%r13d
mov    %r13d,%edx
mov    %ebp,%ecx
call   1050 <bat_info@plt>
cmpl   $0x0,0x8(%rsp)
je     132c <main+0x1bc>
mov    0x2cdd(%rip),%r15
cmp    (%r15),%eax
je     132c <main+0x1bc>
lea    0x20(%rsp),%r14
mov    (%rsp),%ebx
nopl   0x0(%rax,%rax,1)
mov    %ebx,%edi
call   1090 <sleep@plt>
mov    %r14,%rdi
mov    %r12,%rsi
mov    %r13d,%edx
mov    %ebp,%ecx
call   1050 <bat_info@plt>
cmp    (%r15),%eax
jne    1310 <main+0x1a0>
add    $0x128,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xd2f(%rip),%rdi
call   1030 <puts@plt>
mov    0x2c7f(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [37 x i8] c"/sys/class/power_supply/BAT%i/uevent\00"
@.str.1 = [6 x i8] c"%s %i\00"
@.str.2 = [13 x i8] c"hseqf:i:p:n:\00"
@.str.3 = [62 x i8] c"battery [-h|-s|-e|-q|-f FORMAT|-i INTERVAL|-p PATH|-n INDEX]\0A\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [256 x i8]
%15 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8** %6
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %7
store i32 0, i32* %8
store i32 3, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 0, i32* %12
br label %16
16: ; preds = %40, %2
%17 = load i32, i32* %4
%18 = load i8**, i8*** %5
%19 = call i32 @getopt(i32 %17, i8** %18, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 %19, i32* %13
%20 = icmp ne i32 %19, -1
br i1 %20, label %21, label %41
21: ; preds = %16
%22 = load i32, i32* %13
switch i32 %22, label %40 [
i32 104, label %23
i32 115, label %27
i32 102, label %28
i32 112, label %30
i32 105, label %32
i32 110, label %35
i32 101, label %38
i32 113, label %39
]
23: ; preds = %21
%24 = call i32 @printf(i8* getelementptr inbounds ([62 x i8], [62 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
27: ; preds = %21
store i32 1, i32* %10
br label %40
28: ; preds = %21
%29 = load i8*, i8** @optarg
store i8* %29, i8** %7
br label %40
30: ; preds = %21
%31 = load i8*, i8** @optarg
store i8* %31, i8** %6
br label %40
32: ; preds = %21
%33 = load i8*, i8** @optarg
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %9
br label %40
35: ; preds = %21
%36 = load i8*, i8** @optarg
%37 = call i32 @atoi(i8* %36)
store i32 %37, i32* %8
br label %40
38: ; preds = %21
store i32 1, i32* %11
br label %40
39: ; preds = %21
store i32 1, i32* %12
br label %40
40: ; preds = %21, %39, %38, %35, %32, %30, %28, %27
br label %16
41: ; preds = %16
%42 = bitcast [256 x i8]* %14 to i8*
%43 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%44 = load i8*, i8** %6
%45 = load i32, i32* %8
%46 = call i32 @snprintf(i8* %43, i32 256, i8* %44, i32 %45)
%47 = load i32, i32* %10
%48 = icmp ne i32 %47, 0
br i1 %48, label %49, label %62
49: ; preds = %41
br label %50
50: ; preds = %58, %49
%51 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%52 = load i8*, i8** %7
%53 = load i32, i32* %11
%54 = load i32, i32* %12
%55 = call i32 @bat_info(i8* %51, i8* %52, i32 %53, i32 %54)
store i32 %55, i32* %15
%56 = load i32, i32* @EXIT_FAILURE
%57 = icmp ne i32 %55, %56
br i1 %57, label %58, label %61
58: ; preds = %50
%59 = load i32, i32* %9
%60 = call i32 @sleep(i32 %59)
br label %50
61: ; preds = %50
br label %68
62: ; preds = %41
%63 = getelementptr inbounds [256 x i8], [256 x i8]* %14, i64 0, i64 0
%64 = load i8*, i8** %7
%65 = load i32, i32* %11
%66 = load i32, i32* %12
%67 = call i32 @bat_info(i8* %63, i8* %64, i32 %65, i32 %66)
store i32 %67, i32* %15
br label %68
68: ; preds = %62, %61
%69 = load i32, i32* %15
ret i32 %69
}

LLVM IR (-O2):
@.str = [37 x i8] c"/sys/class/power_supply/BAT%i/uevent\00"
@.str.1 = [6 x i8] c"%s %i\00"
@.str.2 = [13 x i8] c"hseqf:i:p:n:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@str = [61 x i8] c"battery [-h|-s|-e|-q|-f FORMAT|-i INTERVAL|-p PATH|-n INDEX]\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [256 x i8]
br label %4
4: ; preds = %13, %2
%5 = phi i8* [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %2 ], [ %14, %13 ]
%6 = phi i32 [ 0, %2 ], [ %15, %13 ]
%7 = phi i32 [ 3, %2 ], [ %16, %13 ]
%8 = phi i32 [ 0, %2 ], [ %17, %13 ]
%9 = phi i32 [ 0, %2 ], [ %18, %13 ]
%10 = phi i32 [ 0, %2 ], [ %19, %13 ]
%11 = phi i8* [ getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), %2 ], [ %20, %13 ]
%12 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
switch i32 %12, label %13 [
i32 -1, label %38
i32 104, label %21
i32 115, label %25
i32 102, label %26
i32 112, label %28
i32 105, label %30
i32 110, label %33
i32 101, label %36
i32 113, label %37
]
13: ; preds = %4, %37, %36, %33, %30, %28, %26, %25
%14 = phi i8* [ %5, %37 ], [ %5, %36 ], [ %5, %33 ], [ %5, %30 ], [ %5, %28 ], [ %27, %26 ], [ %5, %25 ], [ %5, %4 ]
%15 = phi i32 [ %6, %37 ], [ %6, %36 ], [ %35, %33 ], [ %6, %30 ], [ %6, %28 ], [ %6, %26 ], [ %6, %25 ], [ %6, %4 ]
%16 = phi i32 [ %7, %37 ], [ %7, %36 ], [ %7, %33 ], [ %32, %30 ], [ %7, %28 ], [ %7, %26 ], [ %7, %25 ], [ %7, %4 ]
%17 = phi i32 [ %8, %37 ], [ %8, %36 ], [ %8, %33 ], [ %8, %30 ], [ %8, %28 ], [ %8, %26 ], [ 1, %25 ], [ %8, %4 ]
%18 = phi i32 [ %9, %37 ], [ 1, %36 ], [ %9, %33 ], [ %9, %30 ], [ %9, %28 ], [ %9, %26 ], [ %9, %25 ], [ %9, %4 ]
%19 = phi i32 [ 1, %37 ], [ %10, %36 ], [ %10, %33 ], [ %10, %30 ], [ %10, %28 ], [ %10, %26 ], [ %10, %25 ], [ %10, %4 ]
%20 = phi i8* [ %11, %37 ], [ %11, %36 ], [ %11, %33 ], [ %11, %30 ], [ %29, %28 ], [ %11, %26 ], [ %11, %25 ], [ %11, %4 ]
br label %4
21: ; preds = %4
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([61 x i8], [61 x i8]* @str, i64 0, i64 0))
%23 = load i32, i32* @EXIT_SUCCESS
%24 = tail call i32 @exit(i32 %23)
unreachable
25: ; preds = %4
br label %13
26: ; preds = %4
%27 = load i8*, i8** @optarg
br label %13
28: ; preds = %4
%29 = load i8*, i8** @optarg
br label %13
30: ; preds = %4
%31 = load i8*, i8** @optarg
%32 = tail call i32 @atoi(i8* %31)
br label %13
33: ; preds = %4
%34 = load i8*, i8** @optarg
%35 = tail call i32 @atoi(i8* %34)
br label %13
36: ; preds = %4
br label %13
37: ; preds = %4
br label %13
38: ; preds = %4
%39 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%40 = call i32 @snprintf(i8* %39, i32 256, i8* %11, i32 %6)
%41 = icmp eq i32 %8, 0
%42 = call i32 @bat_info(i8* %39, i8* %5, i32 %9, i32 %10)
%43 = load i32, i32* @EXIT_FAILURE
%44 = icmp eq i32 %42, %43
%45 = select i1 %41, i1 true, i1 %44
br i1 %45, label %51, label %46
46: ; preds = %38, %46
%47 = call i32 @sleep(i32 %7)
%48 = call i32 @bat_info(i8* %39, i8* %5, i32 %9, i32 %10)
%49 = load i32, i32* @EXIT_FAILURE
%50 = icmp eq i32 %48, %49
br i1 %50, label %51, label %46
51: ; preds = %46, %38
%52 = phi i32 [ %42, %38 ], [ %48, %46 ]
ret i32 %52
}