#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 ascent;
  int descent;
};
typedef TYPE_1__ XCharStruct;
typedef int /*<<< orphan*/ GC;
typedef int /*<<< orphan*/ Display;

/* Variables and functions */
int /*<<< orphan*/ XFreeFontInfo(int /*<<< orphan*/ *, int /*<<< orphan*/ *,
                                 int);
int /*<<< orphan*/ XGContextFromGC(int /*<<< orphan*/);
int /*<<< orphan*/ *XQueryFont(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ XTextExtents(int /*<<< orphan*/ *, char const *,
                                int /*<<< orphan*/, int *, int *, int *,
                                TYPE_1__ *);
int XTextWidth(int /*<<< orphan*/ *, char const *, int /*<<< orphan*/);
int /*<<< orphan*/ strlen(char const *);
int query_font_geometry(Display *dpy, GC gc, const char *txt, int *w, int *h,
                        int *a, int *d) {
  XCharStruct text_structure;
  int font_direction, font_ascent, font_descent;
  XFontStruct *fontinfo = XQueryFont(dpy, XGContextFromGC(gc));
  if (!fontinfo) {
    return -1;
  }
  XTextExtents(fontinfo, txt, strlen(txt), &font_direction, &font_ascent,
               &font_descent, &text_structure);
  if (w)
    *w = XTextWidth(fontinfo, txt, strlen(txt));
  if (h)
    *h = text_structure.ascent + text_structure.descent;
  if (a)
    *a = text_structure.ascent;
  if (d)
    *d = text_structure.descent;
  XFreeFontInfo(NULL, fontinfo, 1);
  return 0;
}


x86 assembly (clang, -O0):
<query_font_geometry>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
mov    0x10(%rbp),%rax
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %rcx,-0x28(%rbp)
mov    %r8,-0x30(%rbp)
mov    %r9,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    -0x14(%rbp),%edi
call   1060 <XGContextFromGC@plt>
mov    -0x60(%rbp),%rdi
mov    %eax,%esi
call   1040 <XQueryFont@plt>
mov    %rax,-0x58(%rbp)
cmpq   $0x0,-0x58(%rbp)
jne    11bc <query_font_geometry+0x5c>
movl   $0xffffffff,-0x4(%rbp)
jmp    128b <query_font_geometry+0x12b>
mov    -0x58(%rbp),%rax
mov    %rax,-0x70(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x70(%rbp),%rdi
mov    -0x68(%rbp),%rsi
mov    %eax,%edx
lea    -0x44(%rbp),%rcx
lea    -0x48(%rbp),%r8
lea    -0x4c(%rbp),%r9
lea    -0x40(%rbp),%rax
mov    %rax,(%rsp)
call   1050 <XTextExtents@plt>
cmpq   $0x0,-0x28(%rbp)
je     1233 <query_font_geometry+0xd3>
mov    -0x58(%rbp),%rax
mov    %rax,-0x80(%rbp)
mov    -0x20(%rbp),%rax
mov    %rax,-0x78(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x80(%rbp),%rdi
mov    -0x78(%rbp),%rsi
mov    %eax,%edx
call   1080 <XTextWidth@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x30(%rbp)
je     124a <query_font_geometry+0xea>
mov    -0x40(%rbp),%ecx
add    -0x3c(%rbp),%ecx
mov    -0x30(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,-0x38(%rbp)
je     125e <query_font_geometry+0xfe>
mov    -0x40(%rbp),%ecx
mov    -0x38(%rbp),%rax
mov    %ecx,(%rax)
cmpq   $0x0,0x10(%rbp)
je     1272 <query_font_geometry+0x112>
mov    -0x3c(%rbp),%ecx
mov    0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x58(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edi
mov    $0x1,%edx
call   1070 <XFreeFontInfo@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<query_font_geometry>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %r9,%r14
mov    %r8,%r15
mov    %rcx,%r12
mov    %rdx,%rbp
mov    %rdi,%rbx
mov    %esi,%edi
call   1060 <XGContextFromGC@plt>
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <XQueryFont@plt>
test   %rax,%rax
je     1224 <query_font_geometry+0xc4>
mov    %rax,%r13
mov    %rbp,%rdi
call   1030 <strlen@plt>
lea    0x10(%rsp),%rcx
mov    %rcx,(%rsp)
lea    0x24(%rsp),%rcx
lea    0x20(%rsp),%r8
lea    0x1c(%rsp),%r9
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1050 <XTextExtents@plt>
test   %r12,%r12
je     11e5 <query_font_geometry+0x85>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %r13,%rdi
mov    %rbp,%rsi
mov    %eax,%edx
call   1080 <XTextWidth@plt>
mov    %eax,(%r12)
test   %r15,%r15
je     11f5 <query_font_geometry+0x95>
mov    0x14(%rsp),%eax
add    0x10(%rsp),%eax
mov    %eax,(%r15)
mov    0x60(%rsp),%rax
test   %r14,%r14
je     1206 <query_font_geometry+0xa6>
mov    0x10(%rsp),%ecx
mov    %ecx,(%r14)
test   %rax,%rax
je     1211 <query_font_geometry+0xb1>
mov    0x14(%rsp),%ecx
mov    %ecx,(%rax)
xor    %ebx,%ebx
xor    %edi,%edi
mov    %r13,%rsi
mov    $0x1,%edx
call   1070 <XFreeFontInfo@plt>
jmp    1229 <query_font_geometry+0xc9>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.TYPE_3__ = type { i32, i32 }
define i32 @query_font_geometry(i32* %0, i32 %1, i8* %2, i32* %3, i32* %4, i32* %5, i32* %6) {
%8 = alloca i32
%9 = alloca i32*
%10 = alloca i32
%11 = alloca i8*
%12 = alloca i32*
%13 = alloca i32*
%14 = alloca i32*
%15 = alloca i32*
%16 = alloca %struct.TYPE_3__
%17 = alloca i32
%18 = alloca i32
%19 = alloca i32
%20 = alloca i32*
store i32* %0, i32** %9
store i32 %1, i32* %10
store i8* %2, i8** %11
store i32* %3, i32** %12
store i32* %4, i32** %13
store i32* %5, i32** %14
store i32* %6, i32** %15
%21 = load i32*, i32** %9
%22 = load i32, i32* %10
%23 = call i32 @XGContextFromGC(i32 %22)
%24 = call i32* @XQueryFont(i32* %21, i32 %23)
store i32* %24, i32** %20
%25 = load i32*, i32** %20
%26 = icmp ne i32* %25, null
br i1 %26, label %28, label %27
27: ; preds = %7
store i32 -1, i32* %8
br label %70
28: ; preds = %7
%29 = load i32*, i32** %20
%30 = load i8*, i8** %11
%31 = load i8*, i8** %11
%32 = call i32 @strlen(i8* %31)
%33 = call i32 @XTextExtents(i32* %29, i8* %30, i32 %32, i32* %17, i32* %18, i32* %19, %struct.TYPE_3__* %16)
%34 = load i32*, i32** %12
%35 = icmp ne i32* %34, null
br i1 %35, label %36, label %43
36: ; preds = %28
%37 = load i32*, i32** %20
%38 = load i8*, i8** %11
%39 = load i8*, i8** %11
%40 = call i32 @strlen(i8* %39)
%41 = call i32 @XTextWidth(i32* %37, i8* %38, i32 %40)
%42 = load i32*, i32** %12
store i32 %41, i32* %42
br label %43
43: ; preds = %36, %28
%44 = load i32*, i32** %13
%45 = icmp ne i32* %44, null
br i1 %45, label %46, label %53
46: ; preds = %43
%47 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 1
%50 = load i32, i32* %49
%51 = add nsw i32 %48, %50
%52 = load i32*, i32** %13
store i32 %51, i32* %52
br label %53
53: ; preds = %46, %43
%54 = load i32*, i32** %14
%55 = icmp ne i32* %54, null
br i1 %55, label %56, label %60
56: ; preds = %53
%57 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 0
%58 = load i32, i32* %57
%59 = load i32*, i32** %14
store i32 %58, i32* %59
br label %60
60: ; preds = %56, %53
%61 = load i32*, i32** %15
%62 = icmp ne i32* %61, null
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %16, i32 0, i32 1
%65 = load i32, i32* %64
%66 = load i32*, i32** %15
store i32 %65, i32* %66
br label %67
67: ; preds = %63, %60
%68 = load i32*, i32** %20
%69 = call i32 @XFreeFontInfo(i32* null, i32* %68, i32 1)
store i32 0, i32* %8
br label %70
70: ; preds = %67, %27
%71 = load i32, i32* %8
ret i32 %71
}

LLVM IR (-O2):
%struct.TYPE_3__ = type { i32, i32 }
define i32 @query_font_geometry(i32* %0, i32 %1, i8* %2, i32* writeonly %3, i32* writeonly %4, i32* writeonly %5, i32* writeonly %6) {
%8 = alloca %struct.TYPE_3__
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = bitcast %struct.TYPE_3__* %8 to i8*
%13 = bitcast i32* %9 to i8*
%14 = bitcast i32* %10 to i8*
%15 = bitcast i32* %11 to i8*
%16 = tail call i32 @XGContextFromGC(i32 %1)
%17 = tail call i32* @XQueryFont(i32* %0, i32 %16)
%18 = icmp eq i32* %17, null
br i1 %18, label %46, label %19
19: ; preds = %7
%20 = tail call i32 @strlen(i8* %2)
%21 = call i32 @XTextExtents(i32* %17, i8* %2, i32 %20, i32* %9, i32* %10, i32* %11, %struct.TYPE_3__* %8)
%22 = icmp eq i32* %3, null
br i1 %22, label %26, label %23
23: ; preds = %19
%24 = call i32 @strlen(i8* %2)
%25 = call i32 @XTextWidth(i32* %17, i8* %2, i32 %24)
store i32 %25, i32* %3
br label %26
26: ; preds = %23, %19
%27 = icmp eq i32* %4, null
br i1 %27, label %34, label %28
28: ; preds = %26
%29 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i64 0, i32 0
%30 = load i32, i32* %29
%31 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i64 0, i32 1
%32 = load i32, i32* %31
%33 = add nsw i32 %32, %30
store i32 %33, i32* %4
br label %34
34: ; preds = %28, %26
%35 = icmp eq i32* %5, null
br i1 %35, label %39, label %36
36: ; preds = %34
%37 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i64 0, i32 0
%38 = load i32, i32* %37
store i32 %38, i32* %5
br label %39
39: ; preds = %36, %34
%40 = icmp eq i32* %6, null
br i1 %40, label %44, label %41
41: ; preds = %39
%42 = getelementptr inbounds %struct.TYPE_3__, %struct.TYPE_3__* %8, i64 0, i32 1
%43 = load i32, i32* %42
store i32 %43, i32* %6
br label %44
44: ; preds = %41, %39
%45 = call i32 @XFreeFontInfo(i32* null, i32* %17, i32 1)
br label %46
46: ; preds = %7, %44
%47 = phi i32 [ 0, %44 ], [ -1, %7 ]
ret i32 %47
}