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

/* Variables and functions */
int /*<<< orphan*/ DefaultRootWindow(int /*<<< orphan*/ *);
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XFlush(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XStoreName(int /*<<< orphan*/ *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ fetch_battery_info(char *);
int /*<<< orphan*/ fetch_current_time(char *);
int /*<<< orphan*/ fetch_wifi_info(char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  static Display *dpy;
  char status[256];
  char battery[32];
  char wifi[32];
  char time[32];
  if (!(dpy = XOpenDisplay(NULL))) {
    fprintf(stderr, "dwmstatus: cannot open display.\n");
    return 1;
  }
  for (;; sleep(20)) {
    fetch_wifi_info(wifi);
    fetch_battery_info(battery);
    fetch_current_time(time);
    snprintf(status, 256, "%s %s %s", wifi, battery, time);
    XStoreName(dpy, DefaultRootWindow(dpy), status);
    XFlush(dpy);
  }
  XCloseDisplay(dpy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x180,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,0x2eb6(%rip)
cmp    $0x0,%rax
jne    11ef <main+0x4f>
mov    0x2e0d(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x180,%rsp
pop    %rbp
ret
jmp    11f4 <main+0x54>
lea    -0x150(%rbp),%rdi
call   1060 <fetch_wifi_info@plt>
lea    -0x130(%rbp),%rdi
call   1030 <fetch_battery_info@plt>
lea    -0x170(%rbp),%rdi
call   1040 <fetch_current_time@plt>
lea    -0x110(%rbp),%rdi
lea    -0x150(%rbp),%rcx
lea    -0x130(%rbp),%r8
lea    -0x170(%rbp),%r9
mov    $0x100,%esi
lea    0xde1(%rip),%rdx
call   1080 <snprintf@plt>
mov    0x2e2c(%rip),%rax
mov    %rax,-0x178(%rbp)
mov    0x2e1e(%rip),%rdi
call   1070 <DefaultRootWindow@plt>
mov    -0x178(%rbp),%rdi
mov    %eax,%esi
lea    -0x110(%rbp),%rdx
call   1050 <XStoreName@plt>
mov    0x2dfd(%rip),%rdi
call   10b0 <XFlush@plt>
mov    $0x14,%edi
call   10c0 <sleep@plt>
jmp    11f4 <main+0x54>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x168,%rsp
xor    %edi,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,0x2eb9(%rip)
test   %rax,%rax
je     1255 <main+0xb5>
lea    0x20(%rsp),%r14
lea    0x40(%rsp),%r15
mov    %rsp,%r13
lea    0xe45(%rip),%r12
lea    0x60(%rsp),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
mov    %r14,%rdi
call   1060 <fetch_wifi_info@plt>
mov    %r15,%rdi
call   1030 <fetch_battery_info@plt>
mov    %r13,%rdi
call   1040 <fetch_current_time@plt>
mov    %rbx,%rdi
mov    $0x100,%esi
mov    %r12,%rdx
mov    %r14,%rcx
mov    %r15,%r8
mov    %r13,%r9
call   1080 <snprintf@plt>
mov    0x2e50(%rip),%rbp
mov    %rbp,%rdi
call   1070 <DefaultRootWindow@plt>
mov    %rbp,%rdi
mov    %eax,%esi
mov    %rbx,%rdx
call   1050 <XStoreName@plt>
mov    0x2e34(%rip),%rdi
call   10b0 <XFlush@plt>
mov    $0x14,%edi
call   10c0 <sleep@plt>
jmp    11f0 <main+0x50>
mov    0x2d84(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x168,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@main.dpy = internal global i32* null
@stderr = global i32 0
@.str = [33 x i8] c"dwmstatus: cannot open display.\0A\00"
@.str.1 = [9 x i8] c"%s %s %s\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
store i32 0, i32* %1
%6 = call i32* @XOpenDisplay(i32* null)
store i32* %6, i32** @main.dpy
%7 = icmp ne i32* %6, null
br i1 %7, label %11, label %8
8: ; preds = %0
%9 = load i32, i32* @stderr
%10 = call i32 @fprintf(i32 %9, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret i32 1
11: ; preds = %0
br label %12
12: ; preds = %31, %11
%13 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%14 = call i32 @fetch_wifi_info(i8* %13)
%15 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%16 = call i32 @fetch_battery_info(i8* %15)
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%18 = call i32 @fetch_current_time(i8* %17)
%19 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%20 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%21 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%23 = call i32 @snprintf(i8* %19, i32 256, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %20, i8* %21, i8* %22)
%24 = load i32*, i32** @main.dpy
%25 = load i32*, i32** @main.dpy
%26 = call i32 @DefaultRootWindow(i32* %25)
%27 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%28 = call i32 @XStoreName(i32* %24, i32 %26, i8* %27)
%29 = load i32*, i32** @main.dpy
%30 = call i32 @XFlush(i32* %29)
br label %31
31: ; preds = %12
%32 = call i32 @sleep(i32 20)
br label %12
}

LLVM IR (-O2):
@main.dpy = internal unnamed_addr global i32* null
@stderr = global i32 0
@.str = [33 x i8] c"dwmstatus: cannot open display.\0A\00"
@.str.1 = [9 x i8] c"%s %s %s\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca [32 x i8]
%3 = alloca [32 x i8]
%4 = alloca [32 x i8]
%5 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%7 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%8 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%9 = tail call i32* @XOpenDisplay(i32* null)
store i32* %9, i32** @main.dpy
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0))
ret i32 1
14: ; preds = %0, %14
%15 = call i32 @fetch_wifi_info(i8* %7)
%16 = call i32 @fetch_battery_info(i8* %6)
%17 = call i32 @fetch_current_time(i8* %8)
%18 = call i32 @snprintf(i8* %5, i32 256, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %7, i8* %6, i8* %8)
%19 = load i32*, i32** @main.dpy
%20 = call i32 @DefaultRootWindow(i32* %19)
%21 = call i32 @XStoreName(i32* %19, i32 %20, i8* %5)
%22 = load i32*, i32** @main.dpy
%23 = call i32 @XFlush(i32* %22)
%24 = call i32 @sleep(i32 20)
br label %14
}