#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 scalar_t__ time_t;
struct aq_device {
  int dummy;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int aq_device_get(struct aq_device *, scalar_t__ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ ui_show_title(void *, char const *);
void tty_show_device(void *ui, const char *title, struct aq_device *dev) {
  FILE *tty = ui;
  int is_on;
  time_t override;
  time_t now;
  ui_show_title(ui, title);
  is_on = aq_device_get(dev, &override);
  fprintf(tty, "show_device: %s\r\n", is_on ? "on" : "off");
  now = time(NULL);
  if (override > now) {
    fprintf(tty, "show_device: Override %4d", (int)(override - now));
  }
}


x86 assembly (clang, -O0):
<tty_show_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <ui_show_title@plt>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1060 <aq_device_get@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0x24(%rbp),%ecx
lea    0xe8e(%rip),%rdx
lea    0xe84(%rip),%rax
cmp    $0x0,%ecx
cmovne %rax,%rdx
lea    0xe64(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x38(%rbp),%rax
jle    11da <tty_show_device+0x9a>
mov    -0x20(%rbp),%rdi
mov    -0x30(%rbp),%rax
sub    -0x38(%rbp),%rax
mov    %eax,%edx
lea    0xe46(%rip),%rsi
mov    $0x0,%al
call   1030 <fprintf@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tty_show_device>:
push   %r14
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rdi,%r14
call   1050 <ui_show_title@plt>
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1060 <aq_device_get@plt>
test   %eax,%eax
lea    0xeb2(%rip),%rax
lea    0xea8(%rip),%rdx
cmove  %rax,%rdx
lea    0xe8b(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
xor    %edi,%edi
call   1040 <time@plt>
mov    (%rsp),%rdx
cmp    %rax,%rdx
jle    11a2 <tty_show_device+0x62>
sub    %eax,%edx
lea    0xe81(%rip),%rsi
mov    %r14,%rdi
xor    %eax,%eax
call   1030 <fprintf@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.aq_device = type { i32 }
@.str = [18 x i8] c"show_device: %s\0D\0A\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [4 x i8] c"off\00"
@.str.3 = [26 x i8] c"show_device: Override %4d\00"
define void @tty_show_device(i8* %0, i8* %1, %struct.aq_device* %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca %struct.aq_device*
%7 = alloca i32*
%8 = alloca i32
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.aq_device* %2, %struct.aq_device** %6
%11 = load i8*, i8** %4
%12 = bitcast i8* %11 to i32*
store i32* %12, i32** %7
%13 = load i8*, i8** %4
%14 = load i8*, i8** %5
%15 = call i32 @ui_show_title(i8* %13, i8* %14)
%16 = load %struct.aq_device*, %struct.aq_device** %6
%17 = call i32 @aq_device_get(%struct.aq_device* %16, i64* %9)
store i32 %17, i32* %8
%18 = load i32*, i32** %7
%19 = load i32, i32* %8
%20 = icmp ne i32 %19, 0
%21 = zext i1 %20 to i64
%22 = select i1 %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0)
%23 = call i32 (i32*, i8*, ...) @fprintf(i32* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %22)
%24 = call i64 @time(i32* null)
store i64 %24, i64* %10
%25 = load i64, i64* %9
%26 = load i64, i64* %10
%27 = icmp sgt i64 %25, %26
br i1 %27, label %28, label %35
28: ; preds = %3
%29 = load i32*, i32** %7
%30 = load i64, i64* %9
%31 = load i64, i64* %10
%32 = sub nsw i64 %30, %31
%33 = trunc i64 %32 to i32
%34 = call i32 (i32*, i8*, ...) @fprintf(i32* %29, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %33)
br label %35
35: ; preds = %28, %3
ret void
}

LLVM IR (-O2):
%struct.aq_device = type { i32 }
@.str = [18 x i8] c"show_device: %s\0D\0A\00"
@.str.1 = [3 x i8] c"on\00"
@.str.2 = [4 x i8] c"off\00"
@.str.3 = [26 x i8] c"show_device: Override %4d\00"
define void @tty_show_device(i8* %0, i8* %1, %struct.aq_device* %2) {
%4 = alloca i64
%5 = bitcast i8* %0 to i32*
%6 = bitcast i64* %4 to i8*
%7 = tail call i32 @ui_show_title(i8* %0, i8* %1)
%8 = call i32 @aq_device_get(%struct.aq_device* %2, i64* %4)
%9 = icmp eq i32 %8, 0
%10 = select i1 %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0)
%11 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = call i64 @time(i32* null)
%13 = load i64, i64* %4
%14 = icmp sgt i64 %13, %12
br i1 %14, label %15, label %19
15: ; preds = %3
%16 = sub nsw i64 %13, %12
%17 = trunc i64 %16 to i32
%18 = call i32 (i32*, i8*, ...) @fprintf(i32* %5, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i32 %17)
br label %19
19: ; preds = %15, %3
ret void
}