#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*/ window_id_str;
typedef scalar_t__ Window;

/* Variables and functions */
int /*<<< orphan*/ Log(char *);
int /*<<< orphan*/ setenv(char *, char *, int);
int snprintf(char *, int, char *, unsigned long long);
void ExportWindowID(Window w) {
  char window_id_str[32];
  int window_id_len = snprintf(window_id_str, sizeof(window_id_str), "%llu",
                               (unsigned long long)w);
  if (window_id_len <= 0 || (size_t)window_id_len >= sizeof(window_id_str)) {
    Log("Window ID doesn't fit into buffer");
    return;
  }
  setenv("XSCREENSAVER_WINDOW", window_id_str, 1);
}


x86 assembly (clang, -O0):
<ExportWindowID>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x20,%esi
lea    0xeb0(%rip),%rdx
call   1040 <snprintf@plt>
mov    %eax,-0x34(%rbp)
cmpl   $0x0,-0x34(%rbp)
jle    1170 <ExportWindowID+0x40>
movslq -0x34(%rbp),%rax
cmp    $0x20,%rax
jb     1181 <ExportWindowID+0x51>
lea    0xe8e(%rip),%rdi
call   1050 <Log@plt>
jmp    1196 <ExportWindowID+0x66>
lea    -0x30(%rbp),%rsi
lea    0xe9b(%rip),%rdi
mov    $0x1,%edx
call   1030 <setenv@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<ExportWindowID>:
sub    $0x28,%rsp
mov    %rdi,%rcx
lea    0xec2(%rip),%rdx
mov    %rsp,%rdi
mov    $0x20,%esi
call   1040 <snprintf@plt>
add    $0xffffffe0,%eax
cmp    $0xffffffe0,%eax
ja     1164 <ExportWindowID+0x34>
lea    0xeab(%rip),%rdi
call   1050 <Log@plt>
add    $0x28,%rsp
ret
lea    0xebc(%rip),%rdi
mov    %rsp,%rsi
mov    $0x1,%edx
call   1030 <setenv@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [34 x i8] c"Window ID doesn't fit into buffer\00"
@.str.2 = [20 x i8] c"XSCREENSAVER_WINDOW\00"
define void @ExportWindowID(i64 %0) {
%2 = alloca i64
%3 = alloca [32 x i8]
%4 = alloca i32
store i64 %0, i64* %2
%5 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%6 = load i64, i64* %2
%7 = call i32 @snprintf(i8* %5, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp sle i32 %8, 0
br i1 %9, label %14, label %10
10: ; preds = %1
%11 = load i32, i32* %4
%12 = sext i32 %11 to i64
%13 = icmp uge i64 %12, 32
br i1 %13, label %14, label %16
14: ; preds = %10, %1
%15 = call i32 @Log(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %19
16: ; preds = %10
%17 = getelementptr inbounds [32 x i8], [32 x i8]* %3, i64 0, i64 0
%18 = call i32 @setenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %17, i32 1)
br label %19
19: ; preds = %16, %14
ret void
}

LLVM IR (-O2):
@.str = [5 x i8] c"%llu\00"
@.str.1 = [34 x i8] c"Window ID doesn't fit into buffer\00"
@.str.2 = [20 x i8] c"XSCREENSAVER_WINDOW\00"
define void @ExportWindowID(i64 %0) {
%2 = alloca [32 x i8]
%3 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 32, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i64 %0)
%5 = add i32 %4, -32
%6 = icmp ult i32 %5, -31
br i1 %6, label %7, label %9
7: ; preds = %1
%8 = call i32 @Log(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0))
br label %11
9: ; preds = %1
%10 = call i32 @setenv(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i8* %3, i32 1)
br label %11
11: ; preds = %9, %7
ret void
}