#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 */
struct timeval {
  unsigned long tv_sec;
};
struct stat {
  unsigned long st_atime;
};
typedef int /*<<< orphan*/ dev;

/* Variables and functions */
scalar_t__ lstat(char *, struct stat *);
int printf(char *, ...);
int snprintf(char *, int, char *, char *, char *);
int _print_idle(struct timeval *tv, char *device) {
  char dev[16];
  struct stat st;
  unsigned long idle;
  if (snprintf(dev, sizeof(dev), "%s%s", "/dev/", device) > (int)sizeof(dev))
    return printf("%5s ", "?");
  if (lstat(dev, &st) != 0)
    return printf("%5s ", "?");
  idle = tv->tv_sec - st.st_atime;
  if (idle / 3600 >= 24)
    return printf("%4lud ", idle / 3600 / 24);
  else if (idle / 60 >= 60)
    return printf("%02lu:%02lu ", idle / 3600, idle % 3600 / 60);
  return printf("%02lum%02lu ", idle / 60, idle % 60);
}


x86 assembly (clang, -O0):
<_print_idle>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%r8
mov    $0x10,%esi
lea    0xeac(%rip),%rdx
lea    0xeaa(%rip),%rcx
call   1040 <snprintf@plt>
cmp    $0x10,%eax
jle    1186 <_print_idle+0x56>
lea    0xe9b(%rip),%rdi
lea    0xe99(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x4(%rbp)
jmp    12a4 <_print_idle+0x174>
lea    -0x30(%rbp),%rdi
lea    -0x38(%rbp),%rsi
call   1050 <lstat@plt>
cmp    $0x0,%rax
je     11ba <_print_idle+0x8a>
lea    0xe67(%rip),%rdi
lea    0xe65(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x4(%rbp)
jmp    12a4 <_print_idle+0x174>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
sub    -0x38(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x18,%rax
jb     1212 <_print_idle+0xe2>
mov    -0x40(%rbp),%rax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %rcx
mov    $0x18,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x4(%rbp)
jmp    12a4 <_print_idle+0x174>
mov    -0x40(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
cmp    $0x3c,%rax
jb     126f <_print_idle+0x13f>
mov    -0x40(%rbp),%rax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
mov    -0x40(%rbp),%rax
mov    $0xe10,%ecx
xor    %edx,%edx
div    %rcx
mov    %rdx,%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rdx
lea    0xdb9(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x4(%rbp)
jmp    12a4 <_print_idle+0x174>
jmp    1274 <_print_idle+0x144>
mov    -0x40(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,%rsi
mov    -0x40(%rbp),%rax
mov    $0x3c,%ecx
xor    %edx,%edx
div    %rcx
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<_print_idle>:
push   %rbx
sub    $0x20,%rsp
mov    %rsi,%r8
mov    %rdi,%rbx
lea    0xebe(%rip),%rdx
lea    0xebc(%rip),%rcx
lea    0x10(%rsp),%rdi
mov    $0x10,%esi
call   1040 <snprintf@plt>
cmp    $0x11,%eax
jge    1171 <_print_idle+0x41>
lea    0x10(%rsp),%rdi
lea    0x8(%rsp),%rsi
call   1050 <lstat@plt>
test   %rax,%rax
je     118c <_print_idle+0x5c>
lea    0xe93(%rip),%rdi
lea    0xe91(%rip),%rsi
xor    %eax,%eax
call   1030 <printf@plt>
add    $0x20,%rsp
pop    %rbx
ret
mov    (%rbx),%rcx
sub    0x8(%rsp),%rcx
mov    %rcx,%rax
shr    $0x4,%rax
movabs $0x91a2b3c4d5e6f81,%rdx
2b 1a 09
mul    %rdx
cmp    $0x15180,%rcx
jb     11d1 <_print_idle+0xa1>
movabs $0xc22e450672894ab7,%rdx
45 2e c2
mov    %rcx,%rax
mul    %rdx
shr    $0x10,%rdx
lea    0xe46(%rip),%rdi
mov    %rdx,%rsi
jmp    117f <_print_idle+0x4f>
cmp    $0xe10,%rcx
jb     120d <_print_idle+0xdd>
shr    $0x3,%rdx
mov    %ecx,%eax
mov    $0x91a2b3c5,%esi
imul   %rax,%rsi
shr    $0x2b,%rsi
imul   $0xe10,%esi,%eax
sub    %eax,%ecx
imul   $0x8889,%ecx,%eax
shr    $0x15,%eax
lea    0xe14(%rip),%rdi
mov    %rdx,%rsi
mov    %rax,%rdx
jmp    1228 <_print_idle+0xf8>
movzwl %cx,%eax
imul   $0x8889,%eax,%esi
shr    $0x15,%esi
imul   $0x3c,%esi,%eax
sub    %eax,%ecx
movzwl %cx,%edx
lea    0xdfe(%rip),%rdi
xor    %eax,%eax
call   1030 <printf@plt>
jmp    1186 <_print_idle+0x56>

LLVM IR (-O0):
%struct.timeval = type { i64 }
%struct.stat = type { i64 }
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"/dev/\00"
@.str.2 = [5 x i8] c"%5s \00"
@.str.3 = [2 x i8] c"?\00"
@.str.4 = [7 x i8] c"%4lud \00"
@.str.5 = [13 x i8] c"%02lu:%02lu \00"
@.str.6 = [13 x i8] c"%02lum%02lu \00"
define i32 @_print_idle(%struct.timeval* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.timeval*
%5 = alloca i8*
%6 = alloca [16 x i8]
%7 = alloca %struct.stat
%8 = alloca i64
store %struct.timeval* %0, %struct.timeval** %4
store i8* %1, i8** %5
%9 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%10 = load i8*, i8** %5
%11 = call i32 @snprintf(i8* %9, i32 16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%12 = icmp sgt i32 %11, 16
br i1 %12, label %13, label %15
13: ; preds = %2
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 %14, i32* %3
br label %54
15: ; preds = %2
%16 = getelementptr inbounds [16 x i8], [16 x i8]* %6, i64 0, i64 0
%17 = call i64 @lstat(i8* %16, %struct.stat* %7)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %15
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32 %20, i32* %3
br label %54
21: ; preds = %15
%22 = load %struct.timeval*, %struct.timeval** %4
%23 = getelementptr inbounds %struct.timeval, %struct.timeval* %22, i32 0, i32 0
%24 = load i64, i64* %23
%25 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%26 = load i64, i64* %25
%27 = sub i64 %24, %26
store i64 %27, i64* %8
%28 = load i64, i64* %8
%29 = udiv i64 %28, 3600
%30 = icmp uge i64 %29, 24
br i1 %30, label %31, label %36
31: ; preds = %21
%32 = load i64, i64* %8
%33 = udiv i64 %32, 3600
%34 = udiv i64 %33, 24
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 %34)
store i32 %35, i32* %3
br label %54
36: ; preds = %21
%37 = load i64, i64* %8
%38 = udiv i64 %37, 60
%39 = icmp uge i64 %38, 60
br i1 %39, label %40, label %47
40: ; preds = %36
%41 = load i64, i64* %8
%42 = udiv i64 %41, 3600
%43 = load i64, i64* %8
%44 = urem i64 %43, 3600
%45 = udiv i64 %44, 60
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %42, i64 %45)
store i32 %46, i32* %3
br label %54
47: ; preds = %36
br label %48
48: ; preds = %47
%49 = load i64, i64* %8
%50 = udiv i64 %49, 60
%51 = load i64, i64* %8
%52 = urem i64 %51, 60
%53 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 %50, i64 %52)
store i32 %53, i32* %3
br label %54
54: ; preds = %48, %40, %31, %19, %13
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.timeval = type { i64 }
%struct.stat = type { i64 }
@.str = [5 x i8] c"%s%s\00"
@.str.1 = [6 x i8] c"/dev/\00"
@.str.2 = [5 x i8] c"%5s \00"
@.str.3 = [2 x i8] c"?\00"
@.str.4 = [7 x i8] c"%4lud \00"
@.str.5 = [13 x i8] c"%02lu:%02lu \00"
@.str.6 = [13 x i8] c"%02lum%02lu \00"
define i32 @_print_idle(%struct.timeval* nocapture %0, i8* %1) {
%3 = alloca [16 x i8]
%4 = alloca %struct.stat
%5 = getelementptr inbounds [16 x i8], [16 x i8]* %3, i64 0, i64 0
%6 = bitcast %struct.stat* %4 to i8*
%7 = call i32 @snprintf(i8* %5, i32 16, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* %1)
%8 = icmp sgt i32 %7, 16
br i1 %8, label %9, label %11
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %43
11: ; preds = %2
%12 = call i64 @lstat(i8* %5, %struct.stat* %4)
%13 = icmp eq i64 %12, 0
br i1 %13, label %16, label %14
14: ; preds = %11
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %43
16: ; preds = %11
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
%18 = load i64, i64* %17
%19 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%20 = load i64, i64* %19
%21 = sub i64 %18, %20
%22 = udiv i64 %21, 3600
%23 = icmp ugt i64 %21, 86399
br i1 %23, label %24, label %27
24: ; preds = %16
%25 = udiv i64 %21, 86400
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.4, i64 0, i64 0), i64 %25)
br label %43
27: ; preds = %16
%28 = icmp ugt i64 %21, 3599
br i1 %28, label %29, label %36
29: ; preds = %27
%30 = trunc i64 %21 to i32
%31 = urem i32 %30, 3600
%32 = trunc i32 %31 to i16
%33 = udiv i16 %32, 60
%34 = zext i16 %33 to i64
%35 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.5, i64 0, i64 0), i64 %22, i64 %34)
br label %43
36: ; preds = %27
%37 = trunc i64 %21 to i16
%38 = udiv i16 %37, 60
%39 = zext i16 %38 to i64
%40 = urem i16 %37, 60
%41 = zext i16 %40 to i64
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.6, i64 0, i64 0), i64 %39, i64 %41)
br label %43
43: ; preds = %36, %29, %24, %14, %9
%44 = phi i32 [ %10, %9 ], [ %15, %14 ], [ %26, %24 ], [ %35, %29 ], [ %42, %36 ]
ret i32 %44
}