#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*/ WINDOW;

/* Variables and functions */
int aq_device_get(struct aq_device *, scalar_t__ *);
int /*<<< orphan*/ sprintf(char *, char *, int);
scalar_t__ time(int /*<<< orphan*/ *);
int /*<<< orphan*/ ui_show_title(void *, char const *);
int /*<<< orphan*/ waddch(int /*<<< orphan*/ *, char);
int /*<<< orphan*/ wmove(int /*<<< orphan*/ *, int, int);
void curses_show_device(void *ui, const char *title, struct aq_device *dev) {
  WINDOW *win = ui;
  time_t override;
  int is_on;
  char buff[10];
  time_t now;
  ui_show_title(ui, title);
  is_on = aq_device_get(dev, &override);
  wmove(win, 5, 0);
  if (is_on) {
    waddch(win, '1');
  } else {
    waddch(win, '0');
  }
  now = time(NULL);
  if (override > now) {
    int i;
    wmove(win, 5, 2);
    waddch(win, 'M');
    wmove(win, 5, 4);
    sprintf(buff, "%4d", (int)(override - now));
    for (i = 0; buff[i] != 0; i++) {
      waddch(win, buff[i]);
    }
  }
}


x86 assembly (clang, -O0):
<curses_show_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%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    -0x28(%rbp),%rsi
call   1080 <aq_device_get@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x20(%rbp),%rdi
mov    $0x5,%esi
xor    %edx,%edx
call   1070 <wmove@plt>
cmpl   $0x0,-0x2c(%rbp)
je     11c6 <curses_show_device+0x66>
mov    -0x20(%rbp),%rdi
mov    $0x31,%esi
call   1030 <waddch@plt>
jmp    11d4 <curses_show_device+0x74>
mov    -0x20(%rbp),%rdi
mov    $0x30,%esi
call   1030 <waddch@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1040 <time@plt>
mov    %rax,-0x40(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x40(%rbp),%rax
jle    127b <curses_show_device+0x11b>
mov    -0x20(%rbp),%rdi
mov    $0x5,%esi
mov    $0x2,%edx
call   1070 <wmove@plt>
mov    -0x20(%rbp),%rdi
mov    $0x4d,%esi
call   1030 <waddch@plt>
mov    -0x20(%rbp),%rdi
mov    $0x5,%esi
mov    $0x4,%edx
call   1070 <wmove@plt>
lea    -0x36(%rbp),%rdi
mov    -0x28(%rbp),%rax
sub    -0x40(%rbp),%rax
mov    %eax,%edx
lea    0xdc8(%rip),%rsi
call   1060 <sprintf@plt>
movl   $0x0,-0x44(%rbp)
movslq -0x44(%rbp),%rax
movsbl -0x36(%rbp,%rax,1),%eax
cmp    $0x0,%eax
je     1276 <curses_show_device+0x116>
mov    -0x20(%rbp),%rdi
movslq -0x44(%rbp),%rax
movsbl -0x36(%rbp,%rax,1),%esi
call   1030 <waddch@plt>
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1244 <curses_show_device+0xe4>
jmp    127b <curses_show_device+0x11b>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<curses_show_device>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
mov    %rdx,%r14
mov    %rdi,%rbx
call   1050 <ui_show_title@plt>
lea    0x8(%rsp),%rsi
mov    %r14,%rdi
call   1080 <aq_device_get@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
mov    $0x5,%esi
xor    %edx,%edx
call   1070 <wmove@plt>
cmp    $0x1,%ebp
mov    $0x31,%esi
sbb    $0x0,%esi
mov    %rbx,%rdi
call   1030 <waddch@plt>
xor    %edi,%edi
call   1040 <time@plt>
cmp    %rax,0x8(%rsp)
jle    1227 <curses_show_device+0xc7>
mov    %rax,%r14
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x2,%edx
call   1070 <wmove@plt>
mov    %rbx,%rdi
mov    $0x4d,%esi
call   1030 <waddch@plt>
mov    %rbx,%rdi
mov    $0x5,%esi
mov    $0x4,%edx
call   1070 <wmove@plt>
mov    0x8(%rsp),%edx
sub    %r14d,%edx
lea    0xe0c(%rip),%rsi
lea    0x16(%rsp),%rdi
call   1060 <sprintf@plt>
mov    0x16(%rsp),%al
test   %al,%al
je     1227 <curses_show_device+0xc7>
lea    0x17(%rsp),%rbp
nopl   0x0(%rax,%rax,1)
movsbl %al,%esi
mov    %rbx,%rdi
call   1030 <waddch@plt>
movzbl 0x0(%rbp),%eax
add    $0x1,%rbp
test   %al,%al
jne    1210 <curses_show_device+0xb0>
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.aq_device = type { i32 }
@.str = [4 x i8] c"%4d\00"
define void @curses_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 i64
%9 = alloca i32
%10 = alloca [10 x i8]
%11 = alloca i64
%12 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
store %struct.aq_device* %2, %struct.aq_device** %6
%13 = load i8*, i8** %4
%14 = bitcast i8* %13 to i32*
store i32* %14, i32** %7
%15 = load i8*, i8** %4
%16 = load i8*, i8** %5
%17 = call i32 @ui_show_title(i8* %15, i8* %16)
%18 = load %struct.aq_device*, %struct.aq_device** %6
%19 = call i32 @aq_device_get(%struct.aq_device* %18, i64* %8)
store i32 %19, i32* %9
%20 = load i32*, i32** %7
%21 = call i32 @wmove(i32* %20, i32 5, i32 0)
%22 = load i32, i32* %9
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %27
24: ; preds = %3
%25 = load i32*, i32** %7
%26 = call i32 @waddch(i32* %25, i8 signext 49)
br label %30
27: ; preds = %3
%28 = load i32*, i32** %7
%29 = call i32 @waddch(i32* %28, i8 signext 48)
br label %30
30: ; preds = %27, %24
%31 = call i64 @time(i32* null)
store i64 %31, i64* %11
%32 = load i64, i64* %8
%33 = load i64, i64* %11
%34 = icmp sgt i64 %32, %33
br i1 %34, label %35, label %66
35: ; preds = %30
%36 = load i32*, i32** %7
%37 = call i32 @wmove(i32* %36, i32 5, i32 2)
%38 = load i32*, i32** %7
%39 = call i32 @waddch(i32* %38, i8 signext 77)
%40 = load i32*, i32** %7
%41 = call i32 @wmove(i32* %40, i32 5, i32 4)
%42 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 0
%43 = load i64, i64* %8
%44 = load i64, i64* %11
%45 = sub nsw i64 %43, %44
%46 = trunc i64 %45 to i32
%47 = call i32 @sprintf(i8* %42, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %46)
store i32 0, i32* %12
br label %48
48: ; preds = %62, %35
%49 = load i32, i32* %12
%50 = sext i32 %49 to i64
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 %50
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = icmp ne i32 %53, 0
br i1 %54, label %55, label %65
55: ; preds = %48
%56 = load i32*, i32** %7
%57 = load i32, i32* %12
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds [10 x i8], [10 x i8]* %10, i64 0, i64 %58
%60 = load i8, i8* %59
%61 = call i32 @waddch(i32* %56, i8 signext %60)
br label %62
62: ; preds = %55
%63 = load i32, i32* %12
%64 = add nsw i32 %63, 1
store i32 %64, i32* %12
br label %48
65: ; preds = %48
br label %66
66: ; preds = %65, %30
ret void
}

LLVM IR (-O2):
%struct.aq_device = type { i32 }
@.str = [4 x i8] c"%4d\00"
define void @curses_show_device(i8* %0, i8* %1, %struct.aq_device* %2) {
%4 = alloca i64
%5 = alloca [10 x i8]
%6 = bitcast i8* %0 to i32*
%7 = bitcast i64* %4 to i8*
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%9 = tail call i32 @ui_show_title(i8* %0, i8* %1)
%10 = call i32 @aq_device_get(%struct.aq_device* %2, i64* %4)
%11 = call i32 @wmove(i32* %6, i32 5, i32 0)
%12 = icmp eq i32 %10, 0
%13 = select i1 %12, i8 48, i8 49
%14 = call i32 @waddch(i32* %6, i8 signext %13)
%15 = call i64 @time(i32* null)
%16 = load i64, i64* %4
%17 = icmp sgt i64 %16, %15
br i1 %17, label %18, label %36
18: ; preds = %3
%19 = call i32 @wmove(i32* %6, i32 5, i32 2)
%20 = call i32 @waddch(i32* %6, i8 signext 77)
%21 = call i32 @wmove(i32* %6, i32 5, i32 4)
%22 = load i64, i64* %4
%23 = sub nsw i64 %22, %15
%24 = trunc i64 %23 to i32
%25 = call i32 @sprintf(i8* %8, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %24)
%26 = load i8, i8* %8
%27 = icmp eq i8 %26, 0
br i1 %27, label %36, label %28
28: ; preds = %18, %28
%29 = phi i64 [ %32, %28 ], [ 0, %18 ]
%30 = phi i8 [ %34, %28 ], [ %26, %18 ]
%31 = call i32 @waddch(i32* %6, i8 signext %30)
%32 = add nuw i64 %29, 1
%33 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 %32
%34 = load i8, i8* %33
%35 = icmp eq i8 %34, 0
br i1 %35, label %36, label %28
36: ; preds = %28, %18, %3
ret void
}