#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*/ buffer;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ ioctl(int, unsigned long, char *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int /*<<< orphan*/ sscanf(char *, char *, unsigned long *);
char *strstr(char *, char const *);
int main() {
  FILE *fp_proc, *fp_dev;
  char buffer[2048], output[30];
  size_t bytes_read;
  char *match;
  int i;
  unsigned long ioctlcmd;
  const char *ioctl_key[12] = {
      "IOCTL_UPTIME",          "IOCTL_IRQ_TIME",    "IOCTL_JIFFIES",
      "IOCTL_USER_TIME",       "IOCTL_SYSTEM_TIME", "IOCTL_NICE_TIME",
      "IOCTL_IDLE_TIME",       "IOCTL_IOWAIT_TIME", "IOCTL_GUEST_TIME",
      "IOCTL_GUEST_NICE_TIME", "IOCTL_STEAL_TIME",  "IOCTL_SOFTIRQ_TIME"};
  fp_proc = fopen("/proc/systemtimes", "r");
  if (!fp_proc) {
    printf("/proc/systemtimes is not available\n");
    return 0;
  }
  bytes_read = fread(buffer, 1, sizeof(buffer), fp_proc);
  fclose(fp_proc);
  if (bytes_read == 0 || bytes_read == sizeof(buffer)) {
    printf("Some unexpected error in read process\n");
    return 0;
  }
  printf("--------   Procfs-IOCTL System Times   --------\n");
  printf("Enter a Number Between 1 to 12:\n");
  printf("1:Uptime\t2:IRQ Time\n");
  printf("3:Jiffies\t4:User Time\n");
  printf("5:System Time\t6:Nice Time\n");
  printf("7:Idle Time\t8:IOWait Time\n");
  printf("9:Guest Time\t10:Guest Nice Time\n");
  printf("11:Steal Time\t12:Softirq Time\n");
  printf("Your Choice: ");
  scanf("%d", &i);
  printf("-----------------------------------------------\n");
  if (i >= 1 && i <= 12) {
    match = strstr(buffer, ioctl_key[i - 1]);
    if (!match) {
      printf("%s has not found\n", ioctl_key[i - 1]);
      return -1;
    }
    switch (i) {
    case 1:
      sscanf(match, "IOCTL_UPTIME, %lu", &ioctlcmd);
      break;
    case 2:
      sscanf(match, "IOCTL_IRQ_TIME, %lu", &ioctlcmd);
      break;
    case 3:
      sscanf(match, "IOCTL_JIFFIES, %lu", &ioctlcmd);
      break;
    case 4:
      sscanf(match, "IOCTL_USER_TIME, %lu", &ioctlcmd);
      break;
    case 5:
      sscanf(match, "IOCTL_SYSTEM_TIME, %lu", &ioctlcmd);
      break;
    case 6:
      sscanf(match, "IOCTL_NICE_TIME, %lu", &ioctlcmd);
      break;
    case 7:
      sscanf(match, "IOCTL_IDLE_TIME, %lu", &ioctlcmd);
      break;
    case 8:
      sscanf(match, "IOCTL_IOWAIT_TIME, %lu", &ioctlcmd);
      break;
    case 9:
      sscanf(match, "IOCTL_GUEST_TIME, %lu", &ioctlcmd);
      break;
    case 10:
      sscanf(match, "IOCTL_GUEST_NICE_TIME, %lu", &ioctlcmd);
      break;
    case 11:
      sscanf(match, "IOCTL_STEAL_TIME, %lu", &ioctlcmd);
      break;
    default:
      sscanf(match, "IOCTL_SOFTIRQ_TIME, %lu", &ioctlcmd);
    }
  } else {
    printf("Invalid Command\n");
    return -1;
  }
  int fd = open("/proc/systemtimes", O_RDONLY);
  ioctl(fd, ioctlcmd, output);
  close(fd);
  printf("Output: %s\n", output);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x8d0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x8c0(%rbp),%rdi
lea    0x2be0(%rip),%rsi
mov    $0x60,%edx
call   1080 <memcpy@plt>
lea    0xf14(%rip),%rdi
lea    0xf1f(%rip),%rsi
call   10c0 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1216 <main+0x66>
lea    0xf06(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15ae <main+0x3fe>
lea    -0x820(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x800,%edx
call   1030 <fread@plt>
mov    %rax,-0x848(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x848(%rbp)
je     125f <main+0xaf>
cmpq   $0x800,-0x848(%rbp)
jne    1279 <main+0xc9>
lea    0xec7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    15ae <main+0x3fe>
lea    0xed4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xef7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf11(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf1a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf27(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf34(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf47(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf58(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf58(%rip),%rdi
lea    -0x854(%rbp),%rsi
call   10a0 <scanf@plt>
lea    0xf48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
cmpl   $0x1,-0x854(%rbp)
jl     1539 <main+0x389>
cmpl   $0xc,-0x854(%rbp)
jg     1539 <main+0x389>
lea    -0x820(%rbp),%rdi
mov    -0x854(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x8c0(%rbp,%rax,8),%rsi
ff
call   10d0 <strstr@plt>
mov    %rax,-0x850(%rbp)
cmpq   $0x0,-0x850(%rbp)
jne    1393 <main+0x1e3>
mov    -0x854(%rbp),%eax
sub    $0x1,%eax
cltq
mov    -0x8c0(%rbp,%rax,8),%rsi
ff
lea    0xf0a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ae <main+0x3fe>
mov    -0x854(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x8d0(%rbp)
sub    $0xa,%eax
ja     151a <main+0x36a>
mov    -0x8d0(%rbp),%rax
lea    0xc44(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
mov    -0x850(%rbp),%rdi
lea    0xec9(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xebc(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xeb1(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xea5(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe9b(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe93(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe89(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe7f(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe77(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe6e(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe6a(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1534 <main+0x384>
mov    -0x850(%rbp),%rdi
lea    0xe61(%rip),%rsi
lea    -0x860(%rbp),%rdx
call   1090 <sscanf@plt>
jmp    1553 <main+0x3a3>
lea    0xe61(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15ae <main+0x3fe>
mov    0x2a86(%rip),%rax
mov    (%rax),%esi
lea    0xb92(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x8c4(%rbp)
mov    -0x8c4(%rbp),%edi
mov    -0x860(%rbp),%rsi
lea    -0x840(%rbp),%rdx
call   1060 <ioctl@plt>
mov    -0x8c4(%rbp),%edi
call   1070 <close@plt>
lea    -0x840(%rbp),%rsi
lea    0xe12(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x8d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x830,%rsp
lea    0xf07(%rip),%rdi
lea    0xf12(%rip),%rsi
call   10c0 <fopen@plt>
test   %rax,%rax
je     12d7 <main+0x127>
mov    %rax,%rbx
lea    0x30(%rsp),%rdi
mov    $0x1,%esi
mov    $0x800,%edx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %rax,%r14
mov    %rbx,%rdi
call   1050 <fclose@plt>
test   $0xfffffffffffff7ff,%r14
je     12e0 <main+0x130>
lea    0x1024(%rip),%rdi
call   1030 <puts@plt>
lea    0x1048(%rip),%rdi
call   1030 <puts@plt>
lea    0x105c(%rip),%rdi
call   1030 <puts@plt>
lea    0x1064(%rip),%rdi
call   1030 <puts@plt>
lea    0x106e(%rip),%rdi
call   1030 <puts@plt>
lea    0x107c(%rip),%rdi
call   1030 <puts@plt>
lea    0x108a(%rip),%rdi
call   1030 <puts@plt>
lea    0x109e(%rip),%rdi
call   1030 <puts@plt>
lea    0xe6d(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xe6d(%rip),%rdi
lea    0x4(%rsp),%rsi
call   10a0 <scanf@plt>
lea    0x1091(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%ebp
add    $0xffffffff,%ebp
cmp    $0xb,%ebp
ja     12f3 <main+0x143>
mov    %ebp,%eax
lea    0x2b07(%rip),%rcx
mov    (%rcx,%rax,8),%rbx
lea    0x30(%rsp),%rdi
mov    %rbx,%rsi
call   10d0 <strstr@plt>
test   %rax,%rax
je     1306 <main+0x156>
cmp    $0xb,%ebp
jae    131e <main+0x16e>
movslq %ebp,%rcx
lea    0x10ba(%rip),%rdx
movslq (%rdx,%rcx,4),%rsi
add    %rdx,%rsi
jmp    1325 <main+0x175>
lea    0xf33(%rip),%rdi
jmp    12e7 <main+0x137>
lea    0x1079(%rip),%rdi
call   1030 <puts@plt>
xor    %ebx,%ebx
jmp    1377 <main+0x1c7>
lea    0x1056(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%ebx
jmp    1377 <main+0x1c7>
lea    0xde1(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebx
jmp    1377 <main+0x1c7>
lea    0xec8(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %rax,%rdi
call   1090 <sscanf@plt>
mov    0x2ca7(%rip),%rax
mov    (%rax),%esi
lea    0xd87(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,%ebx
mov    0x8(%rsp),%rsi
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rdx
call   1070 <ioctl@plt>
mov    %ebx,%edi
call   1080 <close@plt>
lea    0xe9a(%rip),%rdi
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %ebx,%eax
add    $0x830,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"IOCTL_UPTIME\00"
@.str.1 = [15 x i8] c"IOCTL_IRQ_TIME\00"
@.str.2 = [14 x i8] c"IOCTL_JIFFIES\00"
@.str.3 = [16 x i8] c"IOCTL_USER_TIME\00"
@.str.4 = [18 x i8] c"IOCTL_SYSTEM_TIME\00"
@.str.5 = [16 x i8] c"IOCTL_NICE_TIME\00"
@.str.6 = [16 x i8] c"IOCTL_IDLE_TIME\00"
@.str.7 = [18 x i8] c"IOCTL_IOWAIT_TIME\00"
@.str.8 = [17 x i8] c"IOCTL_GUEST_TIME\00"
@.str.9 = [22 x i8] c"IOCTL_GUEST_NICE_TIME\00"
@.str.10 = [17 x i8] c"IOCTL_STEAL_TIME\00"
@.str.11 = [19 x i8] c"IOCTL_SOFTIRQ_TIME\00"
@__const.main.ioctl_key = [12 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i32 0, i32 0)]
@.str.12 = [18 x i8] c"/proc/systemtimes\00"
@.str.13 = [2 x i8] c"r\00"
@.str.14 = [36 x i8] c"/proc/systemtimes is not available\0A\00"
@.str.15 = [39 x i8] c"Some unexpected error in read process\0A\00"
@.str.16 = [49 x i8] c"-------- Procfs-IOCTL System Times --------\0A\00"
@.str.17 = [33 x i8] c"Enter a Number Between 1 to 12:\0A\00"
@.str.18 = [21 x i8] c"1:Uptime\092:IRQ Time\0A\00"
@.str.19 = [23 x i8] c"3:Jiffies\094:User Time\0A\00"
@.str.20 = [27 x i8] c"5:System Time\096:Nice Time\0A\00"
@.str.21 = [27 x i8] c"7:Idle Time\098:IOWait Time\0A\00"
@.str.22 = [33 x i8] c"9:Guest Time\0910:Guest Nice Time\0A\00"
@.str.23 = [31 x i8] c"11:Steal Time\0912:Softirq Time\0A\00"
@.str.24 = [14 x i8] c"Your Choice: \00"
@.str.25 = [3 x i8] c"%d\00"
@.str.26 = [49 x i8] c"-----------------------------------------------\0A\00"
@.str.27 = [18 x i8] c"%s has not found\0A\00"
@.str.28 = [18 x i8] c"IOCTL_UPTIME, %lu\00"
@.str.29 = [20 x i8] c"IOCTL_IRQ_TIME, %lu\00"
@.str.30 = [19 x i8] c"IOCTL_JIFFIES, %lu\00"
@.str.31 = [21 x i8] c"IOCTL_USER_TIME, %lu\00"
@.str.32 = [23 x i8] c"IOCTL_SYSTEM_TIME, %lu\00"
@.str.33 = [21 x i8] c"IOCTL_NICE_TIME, %lu\00"
@.str.34 = [21 x i8] c"IOCTL_IDLE_TIME, %lu\00"
@.str.35 = [23 x i8] c"IOCTL_IOWAIT_TIME, %lu\00"
@.str.36 = [22 x i8] c"IOCTL_GUEST_TIME, %lu\00"
@.str.37 = [27 x i8] c"IOCTL_GUEST_NICE_TIME, %lu\00"
@.str.38 = [22 x i8] c"IOCTL_STEAL_TIME, %lu\00"
@.str.39 = [24 x i8] c"IOCTL_SOFTIRQ_TIME, %lu\00"
@.str.40 = [17 x i8] c"Invalid Command\0A\00"
@O_RDONLY = global i32 0
@.str.41 = [12 x i8] c"Output: %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32*
%4 = alloca [2048 x i8]
%5 = alloca [30 x i8]
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i32
%9 = alloca i64
%10 = alloca [12 x i8*]
%11 = alloca i32
store i32 0, i32* %1
%12 = bitcast [12 x i8*]* %10 to i8*
%13 = call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = icmp ne i32* %14, null
br i1 %15, label %18, label %16
16: ; preds = %0
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.14, i64 0, i64 0))
store i32 0, i32* %1
br label %117
18: ; preds = %0
%19 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%20 = load i32*, i32** %2
%21 = call i64 @fread(i8* %19, i32 1, i32 2048, i32* %20)
store i64 %21, i64* %6
%22 = load i32*, i32** %2
%23 = call i32 @fclose(i32* %22)
%24 = load i64, i64* %6
%25 = icmp eq i64 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %18
%27 = load i64, i64* %6
%28 = icmp eq i64 %27, 2048
br i1 %28, label %29, label %31
29: ; preds = %26, %18
%30 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.15, i64 0, i64 0))
store i32 0, i32* %1
br label %117
31: ; preds = %26
%32 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.16, i64 0, i64 0))
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.17, i64 0, i64 0))
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.18, i64 0, i64 0))
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.19, i64 0, i64 0))
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.20, i64 0, i64 0))
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.21, i64 0, i64 0))
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.22, i64 0, i64 0))
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.23, i64 0, i64 0))
%40 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.24, i64 0, i64 0))
%41 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i32* %8)
%42 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.26, i64 0, i64 0))
%43 = load i32, i32* %8
%44 = icmp sge i32 %43, 1
br i1 %44, label %45, label %104
45: ; preds = %31
%46 = load i32, i32* %8
%47 = icmp sle i32 %46, 12
br i1 %47, label %48, label %104
48: ; preds = %45
%49 = getelementptr inbounds [2048 x i8], [2048 x i8]* %4, i64 0, i64 0
%50 = load i32, i32* %8
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds [12 x i8*], [12 x i8*]* %10, i64 0, i64 %52
%54 = load i8*, i8** %53
%55 = call i8* @strstr(i8* %49, i8* %54)
store i8* %55, i8** %7
%56 = load i8*, i8** %7
%57 = icmp ne i8* %56, null
br i1 %57, label %65, label %58
58: ; preds = %48
%59 = load i32, i32* %8
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds [12 x i8*], [12 x i8*]* %10, i64 0, i64 %61
%63 = load i8*, i8** %62
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.27, i64 0, i64 0), i8* %63)
store i32 -1, i32* %1
br label %117
65: ; preds = %48
%66 = load i32, i32* %8
switch i32 %66, label %100 [
i32 1, label %67
i32 2, label %70
i32 3, label %73
i32 4, label %76
i32 5, label %79
i32 6, label %82
i32 7, label %85
i32 8, label %88
i32 9, label %91
i32 10, label %94
i32 11, label %97
]
67: ; preds = %65
%68 = load i8*, i8** %7
%69 = call i32 @sscanf(i8* %68, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.28, i64 0, i64 0), i64* %9)
br label %103
70: ; preds = %65
%71 = load i8*, i8** %7
%72 = call i32 @sscanf(i8* %71, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.29, i64 0, i64 0), i64* %9)
br label %103
73: ; preds = %65
%74 = load i8*, i8** %7
%75 = call i32 @sscanf(i8* %74, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.30, i64 0, i64 0), i64* %9)
br label %103
76: ; preds = %65
%77 = load i8*, i8** %7
%78 = call i32 @sscanf(i8* %77, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.31, i64 0, i64 0), i64* %9)
br label %103
79: ; preds = %65
%80 = load i8*, i8** %7
%81 = call i32 @sscanf(i8* %80, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.32, i64 0, i64 0), i64* %9)
br label %103
82: ; preds = %65
%83 = load i8*, i8** %7
%84 = call i32 @sscanf(i8* %83, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.33, i64 0, i64 0), i64* %9)
br label %103
85: ; preds = %65
%86 = load i8*, i8** %7
%87 = call i32 @sscanf(i8* %86, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.34, i64 0, i64 0), i64* %9)
br label %103
88: ; preds = %65
%89 = load i8*, i8** %7
%90 = call i32 @sscanf(i8* %89, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.35, i64 0, i64 0), i64* %9)
br label %103
91: ; preds = %65
%92 = load i8*, i8** %7
%93 = call i32 @sscanf(i8* %92, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.36, i64 0, i64 0), i64* %9)
br label %103
94: ; preds = %65
%95 = load i8*, i8** %7
%96 = call i32 @sscanf(i8* %95, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.37, i64 0, i64 0), i64* %9)
br label %103
97: ; preds = %65
%98 = load i8*, i8** %7
%99 = call i32 @sscanf(i8* %98, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.38, i64 0, i64 0), i64* %9)
br label %103
100: ; preds = %65
%101 = load i8*, i8** %7
%102 = call i32 @sscanf(i8* %101, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.39, i64 0, i64 0), i64* %9)
br label %103
103: ; preds = %100, %97, %94, %91, %88, %85, %82, %79, %76, %73, %70, %67
br label %106
104: ; preds = %45, %31
%105 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.40, i64 0, i64 0))
store i32 -1, i32* %1
br label %117
106: ; preds = %103
%107 = load i32, i32* @O_RDONLY
%108 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %107)
store i32 %108, i32* %11
%109 = load i32, i32* %11
%110 = load i64, i64* %9
%111 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%112 = call i32 @ioctl(i32 %109, i64 %110, i8* %111)
%113 = load i32, i32* %11
%114 = call i32 @close(i32 %113)
%115 = getelementptr inbounds [30 x i8], [30 x i8]* %5, i64 0, i64 0
%116 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.41, i64 0, i64 0), i8* %115)
store i32 0, i32* %1
br label %117
117: ; preds = %106, %104, %58, %29, %16
%118 = load i32, i32* %1
ret i32 %118
}

LLVM IR (-O2):
@.str = [13 x i8] c"IOCTL_UPTIME\00"
@.str.1 = [15 x i8] c"IOCTL_IRQ_TIME\00"
@.str.2 = [14 x i8] c"IOCTL_JIFFIES\00"
@.str.3 = [16 x i8] c"IOCTL_USER_TIME\00"
@.str.4 = [18 x i8] c"IOCTL_SYSTEM_TIME\00"
@.str.5 = [16 x i8] c"IOCTL_NICE_TIME\00"
@.str.6 = [16 x i8] c"IOCTL_IDLE_TIME\00"
@.str.7 = [18 x i8] c"IOCTL_IOWAIT_TIME\00"
@.str.8 = [17 x i8] c"IOCTL_GUEST_TIME\00"
@.str.9 = [22 x i8] c"IOCTL_GUEST_NICE_TIME\00"
@.str.10 = [17 x i8] c"IOCTL_STEAL_TIME\00"
@.str.11 = [19 x i8] c"IOCTL_SOFTIRQ_TIME\00"
@__const.main.ioctl_key = [12 x i8*] [i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.3, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i32 0, i32 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i32 0, i32 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.8, i32 0, i32 0), i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.9, i32 0, i32 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.10, i32 0, i32 0), i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.11, i32 0, i32 0)]
@.str.12 = [18 x i8] c"/proc/systemtimes\00"
@.str.13 = [2 x i8] c"r\00"
@.str.24 = [14 x i8] c"Your Choice: \00"
@.str.25 = [3 x i8] c"%d\00"
@.str.27 = [18 x i8] c"%s has not found\0A\00"
@.str.28 = [18 x i8] c"IOCTL_UPTIME, %lu\00"
@.str.29 = [20 x i8] c"IOCTL_IRQ_TIME, %lu\00"
@.str.30 = [19 x i8] c"IOCTL_JIFFIES, %lu\00"
@.str.31 = [21 x i8] c"IOCTL_USER_TIME, %lu\00"
@.str.32 = [23 x i8] c"IOCTL_SYSTEM_TIME, %lu\00"
@.str.33 = [21 x i8] c"IOCTL_NICE_TIME, %lu\00"
@.str.34 = [21 x i8] c"IOCTL_IDLE_TIME, %lu\00"
@.str.35 = [23 x i8] c"IOCTL_IOWAIT_TIME, %lu\00"
@.str.36 = [22 x i8] c"IOCTL_GUEST_TIME, %lu\00"
@.str.37 = [27 x i8] c"IOCTL_GUEST_NICE_TIME, %lu\00"
@.str.38 = [22 x i8] c"IOCTL_STEAL_TIME, %lu\00"
@.str.39 = [24 x i8] c"IOCTL_SOFTIRQ_TIME, %lu\00"
@O_RDONLY = global i32 0
@.str.41 = [12 x i8] c"Output: %s\0A\00"
@str = [35 x i8] c"/proc/systemtimes is not available\00"
@str.42 = [48 x i8] c"-------- Procfs-IOCTL System Times --------\00"
@str.43 = [32 x i8] c"Enter a Number Between 1 to 12:\00"
@str.44 = [20 x i8] c"1:Uptime\092:IRQ Time\00"
@str.45 = [22 x i8] c"3:Jiffies\094:User Time\00"
@str.46 = [26 x i8] c"5:System Time\096:Nice Time\00"
@str.47 = [26 x i8] c"7:Idle Time\098:IOWait Time\00"
@str.48 = [32 x i8] c"9:Guest Time\0910:Guest Nice Time\00"
@str.49 = [30 x i8] c"11:Steal Time\0912:Softirq Time\00"
@str.50 = [48 x i8] c"-----------------------------------------------\00"
@str.51 = [16 x i8] c"Invalid Command\00"
@str.52 = [38 x i8] c"Some unexpected error in read process\00"
@reltable.main = [11 x i32] [i32 trunc (i64 sub (i64 ptrtoint ([18 x i8]* @.str.28 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([20 x i8]* @.str.29 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([19 x i8]* @.str.30 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.31 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.32 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.33 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([21 x i8]* @.str.34 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([23 x i8]* @.str.35 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.36 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([27 x i8]* @.str.37 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32), i32 trunc (i64 sub (i64 ptrtoint ([22 x i8]* @.str.38 to i64), i64 ptrtoint ([11 x i32]* @reltable.main to i64)) to i32)]
define i32 @main() {
%1 = alloca [2048 x i8]
%2 = alloca [30 x i8]
%3 = alloca i32
%4 = alloca i64
%5 = getelementptr inbounds [2048 x i8], [2048 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %2, i64 0, i64 0
%7 = bitcast i32* %3 to i8*
%8 = bitcast i64* %4 to i8*
%9 = tail call i32* @fopen(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.13, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %0
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([35 x i8], [35 x i8]* @str, i64 0, i64 0))
br label %61
13: ; preds = %0
%14 = call i64 @fread(i8* %5, i32 1, i32 2048, i32* %9)
%15 = tail call i32 @fclose(i32* %9)
%16 = and i64 %14, -2049
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %13
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([38 x i8], [38 x i8]* @str.52, i64 0, i64 0))
br label %61
20: ; preds = %13
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.42, i64 0, i64 0))
%22 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.43, i64 0, i64 0))
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @str.44, i64 0, i64 0))
%24 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.45, i64 0, i64 0))
%25 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.46, i64 0, i64 0))
%26 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([26 x i8], [26 x i8]* @str.47, i64 0, i64 0))
%27 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @str.48, i64 0, i64 0))
%28 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @str.49, i64 0, i64 0))
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.24, i64 0, i64 0))
%30 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.25, i64 0, i64 0), i32* %3)
%31 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @str.50, i64 0, i64 0))
%32 = load i32, i32* %3
%33 = add i32 %32, -1
%34 = icmp ult i32 %33, 12
br i1 %34, label %35, label %46
35: ; preds = %20
%36 = zext i32 %33 to i64
%37 = getelementptr inbounds [12 x i8*], [12 x i8*]* @__const.main.ioctl_key, i64 0, i64 %36
%38 = load i8*, i8** %37
%39 = call i8* @strstr(i8* %5, i8* dereferenceable(1) %38)
%40 = icmp eq i8* %39, null
br i1 %40, label %41, label %43
41: ; preds = %35
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.27, i64 0, i64 0), i8* %38)
br label %61
43: ; preds = %35
%44 = add i32 %32, -1
%45 = icmp ult i32 %44, 11
br i1 %45, label %48, label %52
46: ; preds = %20
%47 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str.51, i64 0, i64 0))
br label %61
48: ; preds = %43
%49 = sext i32 %44 to i64
%50 = shl i64 %49, 2
%51 = call i8* @llvm.load.relative.i64(i8* bitcast ([11 x i32]* @reltable.main to i8*), i64 %50)
br label %52
52: ; preds = %43, %48
%53 = phi i8* [ %51, %48 ], [ getelementptr inbounds ([24 x i8], [24 x i8]* @.str.39, i64 0, i64 0), %43 ]
%54 = call i32 @sscanf(i8* %39, i8* %53, i64* %4)
%55 = load i32, i32* @O_RDONLY
%56 = call i32 @open(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.12, i64 0, i64 0), i32 %55)
%57 = load i64, i64* %4
%58 = call i32 @ioctl(i32 %56, i64 %57, i8* %6)
%59 = call i32 @close(i32 %56)
%60 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.41, i64 0, i64 0), i8* %6)
br label %61
61: ; preds = %52, %46, %41, %18, %11
%62 = phi i32 [ 0, %18 ], [ 0, %52 ], [ -1, %41 ], [ -1, %46 ], [ 0, %11 ]
ret i32 %62
}