#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*/ False;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XStoreName(int /*<<< orphan*/ *, int /*<<< orphan*/, char *);
int /*<<< orphan*/ XSync(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int getbattery();
int getconnections();
char *getdatetime();
char *getload();
char *malloc(int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ snprintf(char *, int, char *, int, int, char *, char *);
int /*<<< orphan*/ stderr;
int main(void) {
  char *status;
  char *datetime;
  char *loadavg;
  int battery;
  int connects;
  Display *dpy;
  if (!(dpy = XOpenDisplay(NULL))) {
    fprintf(stderr, "Cannot open display.\n");
    return 1;
  }
  if ((status = malloc(200)) == NULL)
    exit(1);
  char buf[200];
  for (;; sleep(1)) {
    datetime = getdatetime();
    loadavg = getload();
    battery = getbattery();
    connects = getconnections();
    snprintf(buf, 200, "TCP: %d | %d%% | %s | %s", connects, battery, loadavg,
             datetime);
    free(datetime);
    XStoreName(dpy, DefaultRootWindow(dpy), buf);
    XSync(dpy, False);
  }
  free(status);
  XCloseDisplay(dpy);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
jne    122c <main+0x4c>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xde7(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0x110,%rsp
pop    %rbp
ret
mov    $0xc8,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x10(%rbp)
cmp    $0x0,%rax
jne    124e <main+0x6e>
mov    $0x1,%edi
call   10f0 <exit@plt>
jmp    1253 <main+0x73>
mov    $0x0,%al
call   10b0 <getdatetime@plt>
mov    %rax,-0x18(%rbp)
mov    $0x0,%al
call   1040 <getload@plt>
mov    %rax,-0x20(%rbp)
mov    $0x0,%al
call   10e0 <getbattery@plt>
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1060 <getconnections@plt>
mov    %eax,-0x28(%rbp)
lea    -0x100(%rbp),%rdi
mov    -0x28(%rbp),%ecx
mov    -0x24(%rbp),%r8d
mov    -0x20(%rbp),%r9
mov    -0x18(%rbp),%rax
mov    $0xc8,%esi
lea    0xd77(%rip),%rdx
mov    %rax,(%rsp)
call   1080 <snprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x30(%rbp),%rax
mov    %rax,-0x108(%rbp)
mov    -0x30(%rbp),%rdi
call   1070 <DefaultRootWindow@plt>
mov    -0x108(%rbp),%rdi
mov    %eax,%esi
lea    -0x100(%rbp),%rdx
call   1050 <XStoreName@plt>
mov    -0x30(%rbp),%rdi
mov    0x2d03(%rip),%rax
mov    (%rax),%esi
call   10d0 <XSync@plt>
mov    $0x1,%edi
call   1100 <sleep@plt>
jmp    1253 <main+0x73>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xd8,%rsp
xor    %edi,%edi
call   1090 <XOpenDisplay@plt>
test   %rax,%rax
je     1268 <main+0xa8>
mov    %rax,%r12
lea    0x10(%rsp),%r15
mov    0x2df8(%rip),%r14
xor    %eax,%eax
call   10b0 <getdatetime@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <getload@plt>
mov    %rax,%r13
xor    %eax,%eax
call   10d0 <getbattery@plt>
mov    %eax,%ebp
xor    %eax,%eax
call   1060 <getconnections@plt>
mov    %rbx,(%rsp)
mov    %r15,%rdi
mov    $0xc8,%esi
lea    0xdef(%rip),%rdx
mov    %eax,%ecx
mov    %ebp,%r8d
mov    %r13,%r9
call   1080 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    %r12,%rdi
call   1070 <DefaultRootWindow@plt>
mov    %r12,%rdi
mov    %eax,%esi
mov    %r15,%rdx
call   1050 <XStoreName@plt>
mov    (%r14),%esi
mov    %r12,%rdi
call   10c0 <XSync@plt>
mov    $0x1,%edi
call   10e0 <sleep@plt>
jmp    11f0 <main+0x30>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
lea    0xd88(%rip),%rsi
call   10a0 <fprintf@plt>
mov    $0x1,%eax
add    $0xd8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [22 x i8] c"Cannot open display.\0A\00"
@.str.1 = [25 x i8] c"TCP: %d | %d%% | %s | %s\00"
@False = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
%8 = alloca [200 x i8]
store i32 0, i32* %1
%9 = call i32* @XOpenDisplay(i32* null)
store i32* %9, i32** %7
%10 = icmp ne i32* %9, null
br i1 %10, label %14, label %11
11: ; preds = %0
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
ret i32 1
14: ; preds = %0
%15 = call i8* @malloc(i32 200)
store i8* %15, i8** %2
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %14
br label %20
20: ; preds = %41, %19
%21 = call i8* (...) @getdatetime()
store i8* %21, i8** %3
%22 = call i8* (...) @getload()
store i8* %22, i8** %4
%23 = call i32 (...) @getbattery()
store i32 %23, i32* %5
%24 = call i32 (...) @getconnections()
store i32 %24, i32* %6
%25 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%26 = load i32, i32* %6
%27 = load i32, i32* %5
%28 = load i8*, i8** %4
%29 = load i8*, i8** %3
%30 = call i32 @snprintf(i8* %25, i32 200, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %26, i32 %27, i8* %28, i8* %29)
%31 = load i8*, i8** %3
%32 = call i32 @free(i8* %31)
%33 = load i32*, i32** %7
%34 = load i32*, i32** %7
%35 = call i32 @DefaultRootWindow(i32* %34)
%36 = getelementptr inbounds [200 x i8], [200 x i8]* %8, i64 0, i64 0
%37 = call i32 @XStoreName(i32* %33, i32 %35, i8* %36)
%38 = load i32*, i32** %7
%39 = load i32, i32* @False
%40 = call i32 @XSync(i32* %38, i32 %39)
br label %41
41: ; preds = %20
%42 = call i32 @sleep(i32 1)
br label %20
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [22 x i8] c"Cannot open display.\0A\00"
@.str.1 = [25 x i8] c"TCP: %d | %d%% | %s | %s\00"
@False = global i32 0
define i32 @main() {
%1 = alloca [200 x i8]
%2 = tail call i32* @XOpenDisplay(i32* null)
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %7
4: ; preds = %0
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0))
ret i32 1
7: ; preds = %0
%8 = getelementptr inbounds [200 x i8], [200 x i8]* %1, i64 0, i64 0
br label %9
9: ; preds = %9, %7
%10 = call i8* (...) @getdatetime()
%11 = call i8* (...) @getload()
%12 = call i32 (...) @getbattery()
%13 = call i32 (...) @getconnections()
%14 = call i32 @snprintf(i8* %8, i32 200, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.1, i64 0, i64 0), i32 %13, i32 %12, i8* %11, i8* %10)
%15 = call i32 @free(i8* %10)
%16 = call i32 @DefaultRootWindow(i32* %2)
%17 = call i32 @XStoreName(i32* %2, i32 %16, i8* %8)
%18 = load i32, i32* @False
%19 = call i32 @XSync(i32* %2, i32 %18)
%20 = call i32 @sleep(i32 1)
br label %9
}