#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 EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int getopt(int, char **, char *);
int mem_info(char *);
char *optarg;
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ sleep(int);
int main(int argc, char *argv[]) {
  char *format = "%d";
  int interval = 5;
  bool snoop = false;
  int opt;
  while ((opt = getopt(argc, argv, "hsf:i:p:n:")) != -1) {
    switch (opt) {
    case 'h':
      printf("battery [-h|-s|-f FORMAT|-i INTERVAL\n");
      exit(EXIT_SUCCESS);
      break;
    case 's':
      snoop = true;
      break;
    case 'f':
      format = optarg;
      break;
    case 'i':
      interval = atoi(optarg);
      break;
    }
  }
  int exit_code;
  if (snoop)
    while ((exit_code = mem_info(format)) != EXIT_FAILURE)
      sleep(interval);
  else
    exit_code = mem_info(format);
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xebb(%rip),%rax
mov    %rax,-0x18(%rbp)
movl   $0x5,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe9e(%rip),%rdx
call   1050 <getopt@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
je     1227 <main+0xc7>
mov    -0x24(%rbp),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x30(%rbp)
sub    $0xd,%eax
ja     1222 <main+0xc2>
mov    -0x30(%rbp),%rax
lea    0xe32(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe68(%rip),%rdi
call   1030 <printf@plt>
mov    0x2de6(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
movl   $0x1,-0x20(%rbp)
jmp    1222 <main+0xc2>
mov    0x2df4(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    1222 <main+0xc2>
mov    0x2de1(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,-0x1c(%rbp)
jmp    118f <main+0x2f>
cmpl   $0x0,-0x20(%rbp)
je     1263 <main+0x103>
jmp    1236 <main+0xd6>
mov    -0x18(%rbp),%rdi
call   1040 <mem_info@plt>
mov    %eax,-0x28(%rbp)
mov    0x2d8f(%rip),%rcx
cmp    (%rcx),%eax
je     125e <main+0xfe>
mov    -0x1c(%rbp),%edi
call   1080 <sleep@plt>
jmp    1236 <main+0xd6>
jmp    126f <main+0x10f>
mov    -0x18(%rbp),%rdi
call   1040 <mem_info@plt>
mov    %eax,-0x28(%rbp)
mov    -0x28(%rbp),%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
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xec1(%rip),%r14
movl   $0x0,0x4(%rsp)
mov    $0x5,%r15d
lea    0xeaf(%rip),%r12
lea    0xe6d(%rip),%r13
jmp    11a5 <main+0x45>
cs nopw 0x0(%rax,%rax,1)
nop
cmp    $0xffffffff,%eax
je     11ee <main+0x8e>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   1050 <getopt@plt>
lea    -0x66(%rax),%ecx
cmp    $0xd,%ecx
ja     11a0 <main+0x40>
movslq 0x0(%r13,%rcx,4),%rax
add    %r13,%rax
jmp    *%rax
mov    0x2e2d(%rip),%rax
mov    (%rax),%r14
jmp    11a5 <main+0x45>
mov    0x2e21(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%r15d
jmp    11a5 <main+0x45>
movl   $0x1,0x4(%rsp)
jmp    11a5 <main+0x45>
mov    %r14,%rdi
call   1040 <mem_info@plt>
cmpl   $0x0,0x4(%rsp)
je     1224 <main+0xc4>
mov    0x2dd4(%rip),%rbx
cmp    (%rbx),%eax
je     1224 <main+0xc4>
nopl   0x0(%rax,%rax,1)
mov    %r15d,%edi
call   1080 <sleep@plt>
mov    %r14,%rdi
call   1040 <mem_info@plt>
cmp    (%rbx),%eax
jne    1210 <main+0xb0>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xe0c(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"hsf:i:p:n:\00"
@.str.2 = [38 x i8] c"battery [-h|-s|-f FORMAT|-i INTERVAL\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 i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8** %6
store i32 5, i32* %7
store i32 0, i32* %8
br label %11
11: ; preds = %28, %2
%12 = load i32, i32* %4
%13 = load i8**, i8*** %5
%14 = call i32 @getopt(i32 %12, i8** %13, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
store i32 %14, i32* %9
%15 = icmp ne i32 %14, -1
br i1 %15, label %16, label %29
16: ; preds = %11
%17 = load i32, i32* %9
switch i32 %17, label %28 [
i32 104, label %18
i32 115, label %22
i32 102, label %23
i32 105, label %25
]
18: ; preds = %16
%19 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @EXIT_SUCCESS
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %16
store i32 1, i32* %8
br label %28
23: ; preds = %16
%24 = load i8*, i8** @optarg
store i8* %24, i8** %6
br label %28
25: ; preds = %16
%26 = load i8*, i8** @optarg
%27 = call i32 @atoi(i8* %26)
store i32 %27, i32* %7
br label %28
28: ; preds = %16, %25, %23, %22
br label %11
29: ; preds = %11
%30 = load i32, i32* %8
%31 = icmp ne i32 %30, 0
br i1 %31, label %32, label %42
32: ; preds = %29
br label %33
33: ; preds = %38, %32
%34 = load i8*, i8** %6
%35 = call i32 @mem_info(i8* %34)
store i32 %35, i32* %10
%36 = load i32, i32* @EXIT_FAILURE
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %41
38: ; preds = %33
%39 = load i32, i32* %7
%40 = call i32 @sleep(i32 %39)
br label %33
41: ; preds = %33
br label %45
42: ; preds = %29
%43 = load i8*, i8** %6
%44 = call i32 @mem_info(i8* %43)
store i32 %44, i32* %10
br label %45
45: ; preds = %42, %41
%46 = load i32, i32* %10
ret i32 %46
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [11 x i8] c"hsf:i:p:n:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@str = [37 x i8] c"battery [-h|-s|-f FORMAT|-i INTERVAL\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %20, %2
%4 = phi i32 [ %22, %20 ], [ 5, %2 ]
%5 = phi i32 [ %8, %20 ], [ 0, %2 ]
%6 = phi i8* [ %11, %20 ], [ getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), %2 ]
br label %7
7: ; preds = %12, %3
%8 = phi i32 [ %5, %3 ], [ 1, %12 ]
%9 = phi i8* [ %6, %3 ], [ %11, %12 ]
br label %10
10: ; preds = %7, %18
%11 = phi i8* [ %9, %7 ], [ %19, %18 ]
br label %12
12: ; preds = %10, %12
%13 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
switch i32 %13, label %12 [
i32 -1, label %23
i32 104, label %14
i32 115, label %7
i32 102, label %18
i32 105, label %20
]
14: ; preds = %12
%15 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_SUCCESS
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %12
%19 = load i8*, i8** @optarg
br label %10
20: ; preds = %12
%21 = load i8*, i8** @optarg
%22 = tail call i32 @atoi(i8* %21)
br label %3
23: ; preds = %12
%24 = icmp eq i32 %8, 0
%25 = tail call i32 @mem_info(i8* %11)
%26 = load i32, i32* @EXIT_FAILURE
%27 = icmp eq i32 %25, %26
%28 = select i1 %24, i1 true, i1 %27
br i1 %28, label %34, label %29
29: ; preds = %23, %29
%30 = tail call i32 @sleep(i32 %4)
%31 = tail call i32 @mem_info(i8* %11)
%32 = load i32, i32* @EXIT_FAILURE
%33 = icmp eq i32 %31, %32
br i1 %33, label %34, label %29
34: ; preds = %29, %23
%35 = phi i32 [ %25, %23 ], [ %31, %29 ]
ret i32 %35
}