#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 */
typedef struct TYPE_3__ TYPE_1__;

/* Type definitions */
typedef int /*<<< orphan*/ XFontStruct;
struct TYPE_3__ {
  int width;
};
typedef TYPE_1__ XCharStruct;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XFreeFont(int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *XLoadQueryFont(int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ XTextExtents(int /*<<< orphan*/ *, char *, size_t, int *,
                                int *, int *, TYPE_1__ *);
int /*<<< orphan*/ printf(char *, int, char *);
void emit_font_width(Display *x_display, char *fontname, char *phrase,
                     size_t len) {
  XCharStruct xcs;
  XFontStruct *font;
  int dir, asc, dsc;
  int width = -1;
  if ((font = XLoadQueryFont(x_display, fontname))) {
    XTextExtents(font, phrase, len, &dir, &asc, &dsc, &xcs);
    width = xcs.width;
    XFreeFont(x_display, font);
  }
  printf("%d %s\n", width, fontname);
}


x86 assembly (clang, -O0):
<emit_font_width>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
movl   $0xffffffff,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <XLoadQueryFont@plt>
mov    %rax,-0x30(%rbp)
cmp    $0x0,%rax
je     11b2 <emit_font_width+0x72>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x20(%rbp),%rdx
lea    -0x34(%rbp),%rcx
lea    -0x38(%rbp),%r8
lea    -0x3c(%rbp),%r9
lea    -0x28(%rbp),%rax
mov    %rax,(%rsp)
call   1060 <XTextExtents@plt>
mov    -0x28(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   1030 <XFreeFont@plt>
mov    -0x40(%rbp),%esi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rdi
call   1040 <printf@plt>
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<emit_font_width>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rcx,%r15
mov    %rdx,%r13
mov    %rsi,%r14
mov    %rdi,%r12
call   1050 <XLoadQueryFont@plt>
test   %rax,%rax
je     119e <emit_font_width+0x5e>
mov    %rax,%rbx
lea    0x8(%rsp),%rax
mov    %rax,(%rsp)
lea    0x14(%rsp),%rcx
lea    0x10(%rsp),%r8
lea    0xc(%rsp),%r9
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %r15,%rdx
call   1060 <XTextExtents@plt>
mov    0x8(%rsp),%ebp
mov    %r12,%rdi
mov    %rbx,%rsi
call   1030 <XFreeFont@plt>
jmp    11a3 <emit_font_width+0x63>
mov    $0xffffffff,%ebp
lea    0xe56(%rip),%rdi
mov    %ebp,%esi
mov    %r14,%rdx
call   1040 <printf@plt>
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32 }
@.str = [7 x i8] c"%d %s\0A\00"
define void @emit_font_width(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
%9 = alloca %struct.TYPE_3__
%10 = alloca i32*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
store i32* %0, i32** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
store i64 %3, i64* %8
store i32 -1, i32* %14
%15 = load i32*, i32** %5
%16 = load i8*, i8** %6
%17 = call i32* @XLoadQueryFont(i32* %15, i8* %16)
store i32* %17, i32** %10
%18 = icmp ne i32* %17, null
br i1 %18, label %19, label %29
19: ; preds = %4
%20 = load i32*, i32** %10
%21 = load i8*, i8** %7
%22 = load i64, i64* %8
%23 = call i32 @XTextExtents(i32* %20, i8* %21, i64 %22, i32* %11, i32* %12, i32* %13, %struct.TYPE_3__* %9)
%24 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %9, i32 0, i32 0
%25 = load i32, i32* %24
store i32 %25, i32* %14
%26 = load i32*, i32** %5
%27 = load i32*, i32** %10
%28 = call i32 @XFreeFont(i32* %26, i32* %27)
br label %29
29: ; preds = %19, %4
%30 = load i32, i32* %14
%31 = load i8*, i8** %6
%32 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %30, i8* %31)
ret void
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32 }
@.str = [7 x i8] c"%d %s\0A\00"
define void @emit_font_width(i32* %0, i8* %1, i8* %2, i64 %3) {
%5 = alloca %struct.TYPE_3__
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = bitcast %struct.TYPE_3__* %5 to i8*
%10 = bitcast i32* %6 to i8*
%11 = bitcast i32* %7 to i8*
%12 = bitcast i32* %8 to i8*
%13 = tail call i32* @XLoadQueryFont(i32* %0, i8* %1)
%14 = icmp eq i32* %13, null
br i1 %14, label %20, label %15
15: ; preds = %4
%16 = call i32 @XTextExtents(i32* %13, i8* %2, i64 %3, i32* %6, i32* %7, i32* %8, %struct.TYPE_3__* %5)
%17 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %5, i64 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @XFreeFont(i32* %0, i32* %13)
br label %20
20: ; preds = %15, %4
%21 = phi i32 [ %18, %15 ], [ -1, %4 ]
%22 = call i32 @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %21, i8* %1)
ret void
}