#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 char *Window;

/* Variables and functions */
scalar_t__ NormalState;
int /*<<< orphan*/ XFree(char *);
char *get_wm_name(char *);
scalar_t__ get_wm_state(char *);
size_t snprintf(char *, size_t, char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
void snprint_wm_name(char *buf, size_t len, Window w) {
  char *n;
  if ((n = get_wm_name(w))) {
    if (get_wm_state(w) == NormalState) {
      if (snprintf(buf, len, "%s", n) > len)
        strcpy(buf + len - 4, "...");
    } else {
      if (snprintf(buf, len, "[%s]", n) > len)
        strcpy(buf + len - 5, "...]");
    }
    XFree(n);
  } else {
    snprintf(buf, len, "%#lx", w);
  }
}


x86 assembly (clang, -O0):
<snprint_wm_name>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <get_wm_name@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1220 <snprint_wm_name+0xd0>
mov    -0x18(%rbp),%rdi
call   1060 <get_wm_state@plt>
mov    0x2e55(%rip),%rcx
cmp    (%rcx),%rax
jne    11d3 <snprint_wm_name+0x83>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xe59(%rip),%rdx
call   1050 <snprintf@plt>
cmp    -0x10(%rbp),%rax
jbe    11ce <snprint_wm_name+0x7e>
mov    -0x8(%rbp),%rdi
add    -0x10(%rbp),%rdi
add    $0xfffffffffffffffc,%rdi
lea    0xe3a(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1212 <snprint_wm_name+0xc2>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x20(%rbp),%rcx
lea    0xe21(%rip),%rdx
call   1050 <snprintf@plt>
cmp    -0x10(%rbp),%rax
jbe    120d <snprint_wm_name+0xbd>
mov    -0x8(%rbp),%rdi
add    -0x10(%rbp),%rdi
add    $0xfffffffffffffffb,%rdi
lea    0xe04(%rip),%rsi
call   1030 <strcpy@plt>
jmp    1212 <snprint_wm_name+0xc2>
mov    -0x20(%rbp),%rdi
call   1040 <XFree@plt>
jmp    1238 <snprint_wm_name+0xe8>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rcx
lea    0xdde(%rip),%rdx
call   1050 <snprintf@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<snprint_wm_name>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r12
mov    %rdx,%rdi
call   1070 <get_wm_name@plt>
test   %rax,%rax
je     11af <snprint_wm_name+0x5f>
mov    %rax,%r15
mov    %rbx,%rdi
call   1060 <get_wm_state@plt>
mov    0x2e60(%rip),%rcx
cmp    (%rcx),%rax
jne    11cf <snprint_wm_name+0x7f>
lea    0xe74(%rip),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rcx
call   1050 <snprintf@plt>
cmp    %r14,%rax
jbe    1205 <snprint_wm_name+0xb5>
lea    0xe5d(%rip),%rsi
mov    $0xfffffffffffffffc,%rax
jmp    11f7 <snprint_wm_name+0xa7>
lea    0xe5b(%rip),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %rbx,%rcx
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1050 <snprintf@plt>
lea    0xe31(%rip),%rdx
mov    %r12,%rdi
mov    %r14,%rsi
mov    %r15,%rcx
call   1050 <snprintf@plt>
cmp    %r14,%rax
jbe    1205 <snprint_wm_name+0xb5>
lea    0xe1c(%rip),%rsi
mov    $0xfffffffffffffffb,%rax
add    %r14,%r12
add    %rax,%r12
mov    %r12,%rdi
call   1030 <strcpy@plt>
mov    %r15,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <XFree@plt>

LLVM IR (-O0):
@NormalState = global i64 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"...\00"
@.str.2 = [5 x i8] c"[%s]\00"
@.str.3 = [5 x i8] c"...]\00"
@.str.4 = [5 x i8] c"%#lx\00"
define void @snprint_wm_name(i8* %0, i64 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i8*
store i8* %0, i8** %4
store i64 %1, i64* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i8* @get_wm_name(i8* %8)
store i8* %9, i8** %7
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %47
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = call i64 @get_wm_state(i8* %12)
%14 = load i64, i64* @NormalState
%15 = icmp eq i64 %13, %14
br i1 %15, label %16, label %30
16: ; preds = %11
%17 = load i8*, i8** %4
%18 = load i64, i64* %5
%19 = load i8*, i8** %7
%20 = call i64 @snprintf(i8* %17, i64 %18, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = load i64, i64* %5
%22 = icmp ugt i64 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %16
%24 = load i8*, i8** %4
%25 = load i64, i64* %5
%26 = getelementptr inbounds i8, i8* %24, i64 %25
%27 = getelementptr inbounds i8, i8* %26, i64 -4
%28 = call i32 @strcpy(i8* %27, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0))
br label %29
29: ; preds = %23, %16
br label %44
30: ; preds = %11
%31 = load i8*, i8** %4
%32 = load i64, i64* %5
%33 = load i8*, i8** %7
%34 = call i64 @snprintf(i8* %31, i64 %32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %33)
%35 = load i64, i64* %5
%36 = icmp ugt i64 %34, %35
br i1 %36, label %37, label %43
37: ; preds = %30
%38 = load i8*, i8** %4
%39 = load i64, i64* %5
%40 = getelementptr inbounds i8, i8* %38, i64 %39
%41 = getelementptr inbounds i8, i8* %40, i64 -5
%42 = call i32 @strcpy(i8* %41, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %43
43: ; preds = %37, %30
br label %44
44: ; preds = %43, %29
%45 = load i8*, i8** %7
%46 = call i32 @XFree(i8* %45)
br label %52
47: ; preds = %3
%48 = load i8*, i8** %4
%49 = load i64, i64* %5
%50 = load i8*, i8** %6
%51 = call i64 @snprintf(i8* %48, i64 %49, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %50)
br label %52
52: ; preds = %47, %44
ret void
}

LLVM IR (-O2):
@NormalState = global i64 0
@.str = [3 x i8] c"%s\00"
@.str.1 = [4 x i8] c"...\00"
@.str.2 = [5 x i8] c"[%s]\00"
@.str.3 = [5 x i8] c"...]\00"
@.str.4 = [5 x i8] c"%#lx\00"
define void @snprint_wm_name(i8* %0, i64 %1, i8* %2) {
%4 = tail call i8* @get_wm_name(i8* %2)
%5 = icmp eq i8* %4, null
br i1 %5, label %24, label %6
6: ; preds = %3
%7 = tail call i64 @get_wm_state(i8* %2)
%8 = load i64, i64* @NormalState
%9 = icmp eq i64 %7, %8
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = tail call i64 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %4)
%12 = icmp ugt i64 %11, %1
br i1 %12, label %16, label %22
13: ; preds = %6
%14 = tail call i64 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%15 = icmp ugt i64 %14, %1
br i1 %15, label %16, label %22
16: ; preds = %13, %10
%17 = phi i64 [ -4, %10 ], [ -5, %13 ]
%18 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %10 ], [ getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), %13 ]
%19 = getelementptr inbounds i8, i8* %0, i64 %1
%20 = getelementptr inbounds i8, i8* %19, i64 %17
%21 = tail call i32 @strcpy(i8* %20, i8* %18)
br label %22
22: ; preds = %16, %13, %10
%23 = tail call i32 @XFree(i8* %4)
br label %26
24: ; preds = %3
%25 = tail call i64 @snprintf(i8* %0, i64 %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i8* %2)
br label %26
26: ; preds = %24, %22
ret void
}