#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 EXIT_SUCCESS;
int atoi(char *);
int getopt(int, char **, char *);
char *optarg;
int /*<<< orphan*/ printf(char *);
int put_info(char *, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int);
int main(int argc, char *argv[]) {
  char *path = "/sys/bus/acpi/devices/LNXTHERM:%02d/thermal_zone/temp";
  char *format = "%3.1f";
  int index = 00;
  int interval = 3;
  bool snoop = false;
  int opt;
  while ((opt = getopt(argc, argv, "hsf:i:p:n:")) != -1) {
    switch (opt) {
    case 'h':
      printf("temp [-h|-s|-f FORMAT|-i INTERVAL|-p PATH|-n INDEX]\n");
      return EXIT_SUCCESS;
    case 's':
      snoop = true;
      break;
    case 'f':
      format = optarg;
      break;
    case 'i':
      interval = atoi(optarg);
      break;
    case 'p':
      path = optarg;
      break;
    case 'n':
      index = atoi(optarg);
      break;
    }
  }
  char real_path[256] = {0};
  snprintf(real_path, sizeof(real_path), path, index);
  int exit_code;
  if (snoop)
    while ((exit_code = put_info(real_path, format)) != EXIT_FAILURE)
      sleep(interval);
  else
    exit_code = put_info(real_path, format);
  return exit_code;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xea8(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xed3(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x3,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xeb2(%rip),%rdx
call   1060 <getopt@plt>
mov    %eax,-0x30(%rbp)
cmp    $0xffffffff,%eax
je     127f <main+0x10f>
mov    -0x30(%rbp),%eax
add    $0xffffff9a,%eax
mov    %eax,%ecx
mov    %rcx,-0x140(%rbp)
sub    $0xd,%eax
ja     127a <main+0x10a>
mov    -0x140(%rbp),%rax
lea    0xe07(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
lea    0xe76(%rip),%rdi
call   1030 <printf@plt>
mov    0x2dbb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130f <main+0x19f>
movl   $0x1,-0x2c(%rbp)
jmp    127a <main+0x10a>
mov    0x2dc6(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x20(%rbp)
jmp    127a <main+0x10a>
mov    0x2db3(%rip),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x28(%rbp)
jmp    127a <main+0x10a>
mov    0x2d9c(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
jmp    127a <main+0x10a>
mov    0x2d89(%rip),%rax
mov    (%rax),%rdi
call   1070 <atoi@plt>
mov    %eax,-0x24(%rbp)
jmp    11b4 <main+0x44>
lea    -0x130(%rbp),%rdi
xor    %esi,%esi
mov    $0x100,%edx
call   1050 <memset@plt>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    -0x24(%rbp),%ecx
mov    $0x100,%esi
call   1040 <snprintf@plt>
cmpl   $0x0,-0x2c(%rbp)
je     12f0 <main+0x180>
jmp    12b9 <main+0x149>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <put_info@plt>
mov    %eax,-0x134(%rbp)
mov    0x2d02(%rip),%rcx
cmp    (%rcx),%eax
je     12eb <main+0x17b>
mov    -0x28(%rbp),%edi
call   1080 <sleep@plt>
jmp    12b9 <main+0x149>
jmp    1306 <main+0x196>
lea    -0x130(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1090 <put_info@plt>
mov    %eax,-0x134(%rbp)
mov    -0x134(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rsi,%rbp
mov    %edi,%ebx
mov    $0x3,%r12d
movl   $0x0,(%rsp)
lea    0xee4(%rip),%r13
lea    0xea7(%rip),%rax
mov    %rax,0x8(%rsp)
lea    0xed7(%rip),%r14
lea    0xe5c(%rip),%r15
movl   $0x0,0x4(%rsp)
jmp    11b9 <main+0x59>
xchg   %ax,%ax
cmp    $0xffffffff,%eax
je     124d <main+0xed>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r14,%rdx
call   1050 <getopt@plt>
lea    -0x66(%rax),%ecx
cmp    $0xd,%ecx
ja     11b0 <main+0x50>
movslq (%r15,%rcx,4),%rax
add    %r15,%rax
jmp    *%rax
mov    0x2e1a(%rip),%rax
mov    (%rax),%r13
jmp    11b9 <main+0x59>
mov    0x2e0e(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,%r12d
jmp    11b9 <main+0x59>
mov    0x2dfa(%rip),%rax
mov    (%rax),%rdi
call   1060 <atoi@plt>
mov    %eax,(%rsp)
jmp    11b9 <main+0x59>
mov    0x2de6(%rip),%rax
mov    (%rax),%rax
mov    %rax,0x8(%rsp)
jmp    11b9 <main+0x59>
movl   $0x1,0x4(%rsp)
jmp    11b9 <main+0x59>
lea    0xe52(%rip),%rdi
call   1030 <puts@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
xorps  %xmm0,%xmm0
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)
movaps %xmm0,0x10(%rsp)
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
mov    0x8(%rsp),%rdx
mov    (%rsp),%ecx
call   1040 <snprintf@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <put_info@plt>
cmpl   $0x0,0x4(%rsp)
je     123b <main+0xdb>
mov    0x2ce6(%rip),%rbp
cmp    0x0(%rbp),%eax
je     123b <main+0xdb>
lea    0x10(%rsp),%rbx
mov    %r12d,%edi
call   1070 <sleep@plt>
mov    %rbx,%rdi
mov    %r13,%rsi
call   1080 <put_info@plt>
cmp    0x0(%rbp),%eax
jne    1300 <main+0x1a0>
jmp    123b <main+0xdb>

LLVM IR (-O0):
@.str = [54 x i8] c"/sys/bus/acpi/devices/LNXTHERM:%02d/thermal_zone/temp\00"
@.str.1 = [6 x i8] c"%3.1f\00"
@.str.2 = [11 x i8] c"hsf:i:p:n:\00"
@.str.3 = [53 x i8] c"temp [-h|-s|-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 [256 x i8]
%13 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([54 x i8], [54 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
br label %14
14: ; preds = %35, %2
%15 = load i32, i32* %4
%16 = load i8**, i8*** %5
%17 = call i32 @getopt(i32 %15, i8** %16, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
store i32 %17, i32* %11
%18 = icmp ne i32 %17, -1
br i1 %18, label %19, label %36
19: ; preds = %14
%20 = load i32, i32* %11
switch i32 %20, label %35 [
i32 104, label %21
i32 115, label %24
i32 102, label %25
i32 105, label %27
i32 112, label %30
i32 110, label %32
]
21: ; preds = %19
%22 = call i32 @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.3, i64 0, i64 0))
%23 = load i32, i32* @EXIT_SUCCESS
store i32 %23, i32* %3
br label %61
24: ; preds = %19
store i32 1, i32* %10
br label %35
25: ; preds = %19
%26 = load i8*, i8** @optarg
store i8* %26, i8** %7
br label %35
27: ; preds = %19
%28 = load i8*, i8** @optarg
%29 = call i32 @atoi(i8* %28)
store i32 %29, i32* %9
br label %35
30: ; preds = %19
%31 = load i8*, i8** @optarg
store i8* %31, i8** %6
br label %35
32: ; preds = %19
%33 = load i8*, i8** @optarg
%34 = call i32 @atoi(i8* %33)
store i32 %34, i32* %8
br label %35
35: ; preds = %19, %32, %30, %27, %25, %24
br label %14
36: ; preds = %14
%37 = bitcast [256 x i8]* %12 to i8*
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%39 = load i8*, i8** %6
%40 = load i32, i32* %8
%41 = call i32 @snprintf(i8* %38, i32 256, i8* %39, i32 %40)
%42 = load i32, i32* %10
%43 = icmp ne i32 %42, 0
br i1 %43, label %44, label %55
44: ; preds = %36
br label %45
45: ; preds = %51, %44
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%47 = load i8*, i8** %7
%48 = call i32 @put_info(i8* %46, i8* %47)
store i32 %48, i32* %13
%49 = load i32, i32* @EXIT_FAILURE
%50 = icmp ne i32 %48, %49
br i1 %50, label %51, label %54
51: ; preds = %45
%52 = load i32, i32* %9
%53 = call i32 @sleep(i32 %52)
br label %45
54: ; preds = %45
br label %59
55: ; preds = %36
%56 = getelementptr inbounds [256 x i8], [256 x i8]* %12, i64 0, i64 0
%57 = load i8*, i8** %7
%58 = call i32 @put_info(i8* %56, i8* %57)
store i32 %58, i32* %13
br label %59
59: ; preds = %55, %54
%60 = load i32, i32* %13
store i32 %60, i32* %3
br label %61
61: ; preds = %59, %21
%62 = load i32, i32* %3
ret i32 %62
}

LLVM IR (-O2):
@.str = [54 x i8] c"/sys/bus/acpi/devices/LNXTHERM:%02d/thermal_zone/temp\00"
@.str.1 = [6 x i8] c"%3.1f\00"
@.str.2 = [11 x i8] c"hsf:i:p:n:\00"
@EXIT_SUCCESS = global i32 0
@optarg = global i8* null
@EXIT_FAILURE = global i32 0
@str = [52 x i8] c"temp [-h|-s|-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 = %34, %2
%5 = phi i8* [ %35, %34 ], [ getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), %2 ]
%6 = phi i8* [ %11, %34 ], [ getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), %2 ]
%7 = phi i32 [ %16, %34 ], [ 0, %2 ]
%8 = phi i32 [ %20, %34 ], [ 3, %2 ]
%9 = phi i32 [ %23, %34 ], [ 0, %2 ]
br label %10
10: ; preds = %4, %29
%11 = phi i8* [ %6, %4 ], [ %30, %29 ]
%12 = phi i32 [ %7, %4 ], [ %16, %29 ]
%13 = phi i32 [ %8, %4 ], [ %20, %29 ]
%14 = phi i32 [ %9, %4 ], [ %23, %29 ]
br label %15
15: ; preds = %10, %36
%16 = phi i32 [ %12, %10 ], [ %38, %36 ]
%17 = phi i32 [ %13, %10 ], [ %20, %36 ]
%18 = phi i32 [ %14, %10 ], [ %23, %36 ]
br label %19
19: ; preds = %15, %31
%20 = phi i32 [ %17, %15 ], [ %33, %31 ]
%21 = phi i32 [ %18, %15 ], [ %23, %31 ]
br label %22
22: ; preds = %24, %19
%23 = phi i32 [ %21, %19 ], [ 1, %24 ]
br label %24
24: ; preds = %22, %24
%25 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0))
switch i32 %25, label %24 [
i32 -1, label %39
i32 104, label %26
i32 115, label %22
i32 102, label %29
i32 105, label %31
i32 112, label %34
i32 110, label %36
]
26: ; preds = %24
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_SUCCESS
br label %54
29: ; preds = %24
%30 = load i8*, i8** @optarg
br label %10
31: ; preds = %24
%32 = load i8*, i8** @optarg
%33 = tail call i32 @atoi(i8* %32)
br label %19
34: ; preds = %24
%35 = load i8*, i8** @optarg
br label %4
36: ; preds = %24
%37 = load i8*, i8** @optarg
%38 = tail call i32 @atoi(i8* %37)
br label %15
39: ; preds = %24
%40 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%41 = call i32 @snprintf(i8* %40, i32 256, i8* %5, i32 %16)
%42 = icmp eq i32 %23, 0
%43 = call i32 @put_info(i8* %40, i8* %11)
%44 = load i32, i32* @EXIT_FAILURE
%45 = icmp eq i32 %43, %44
%46 = select i1 %42, i1 true, i1 %45
br i1 %46, label %52, label %47
47: ; preds = %39, %47
%48 = call i32 @sleep(i32 %20)
%49 = call i32 @put_info(i8* %40, i8* %11)
%50 = load i32, i32* @EXIT_FAILURE
%51 = icmp eq i32 %49, %50
br i1 %51, label %52, label %47
52: ; preds = %47, %39
%53 = phi i32 [ %43, %39 ], [ %49, %47 ]
br label %54
54: ; preds = %52, %26
%55 = phi i32 [ %28, %26 ], [ %53, %52 ]
ret i32 %55
}