#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*/ EOVERFLOW;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ EX_USAGE;
int INT_MAX;
int /*<<< orphan*/ XCloseDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ XFreeFontNames(char **);
char **XListFonts(int /*<<< orphan*/ *, char *, int, int *);
int /*<<< orphan*/ *XOpenDisplay(int /*<<< orphan*/ *);
int /*<<< orphan*/ _IONBF;
int /*<<< orphan*/ emit_font_width(int /*<<< orphan*/ *, char *, char *,
                                   size_t);
int /*<<< orphan*/ errc(int, int /*<<< orphan*/, char *);
int /*<<< orphan*/ errx(int, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ setvbuf(int /*<<< orphan*/, char *, int /*<<< orphan*/,
                           size_t);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
size_t strlen(char *);
int main(int argc, char *argv[]) {
  Display *x_display;
  char **fontnames;
  int maxnames, total;
  size_t len;
  if (argc != 2) {
    fputs("Usage: xfontwidths text-phrase\n", stderr);
    exit(EX_USAGE);
  }
  if (!(x_display = XOpenDisplay(NULL)))
    errx(1, "XOpenDisplay failed");
  maxnames = 4096;
  while (1) {
    if (!(fontnames = XListFonts(x_display, "*", maxnames, &total)))
      errx(1, "no fonts found??");
    if (total == maxnames) {
      if (maxnames > INT_MAX / 2)
        errc(1, EOVERFLOW, "overflow on font names list??");
      maxnames *= 2;
      XFreeFontNames(fontnames);
      continue;
    }
    break;
  }
  fprintf(stderr, "total-fonts %d\n", total);
  setvbuf(stdout, (char *)NULL, _IONBF, (size_t)0);
  len = strlen(argv[1]);
  for (int i = 0; i < total; i++)
    emit_font_width(x_display, fontnames[i], argv[1], len);
  XFreeFontNames(fontnames);
  XCloseDisplay(x_display);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     1203 <main+0x43>
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
lea    0xe10(%rip),%rdi
call   1080 <fputs@plt>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    122b <main+0x6b>
mov    $0x1,%edi
lea    0xdfa(%rip),%rsi
call   1070 <errx@plt>
movl   $0x1000,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x24(%rbp),%edx
lea    0xdf4(%rip),%rsi
lea    -0x28(%rbp),%rcx
call   1060 <XListFonts@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    1268 <main+0xa8>
mov    $0x1,%edi
lea    0xdd3(%rip),%rsi
call   1070 <errx@plt>
mov    -0x28(%rbp),%eax
cmp    -0x24(%rbp),%eax
jne    12c9 <main+0x109>
mov    -0x24(%rbp),%eax
mov    %eax,-0x38(%rbp)
mov    0x2d5f(%rip),%rax
mov    (%rax),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x38(%rbp),%eax
cmp    %ecx,%eax
jle    12b2 <main+0xf2>
mov    0x2d51(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xd9a(%rip),%rdx
call   1050 <errc@plt>
mov    -0x24(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <XFreeFontNames@plt>
jmp    1232 <main+0x72>
jmp    12ce <main+0x10e>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
lea    0xd84(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2ccb(%rip),%rax
mov    (%rax),%edi
mov    0x2cda(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rcx,%rsi
call   10b0 <setvbuf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x30(%rbp)
movl   $0x0,-0x34(%rbp)
mov    -0x34(%rbp),%eax
cmp    -0x28(%rbp),%eax
jge    1357 <main+0x197>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rax
movslq -0x34(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdx
mov    -0x30(%rbp),%rcx
call   10e0 <emit_font_width@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    131c <main+0x15c>
mov    -0x20(%rbp),%rdi
call   1030 <XFreeFontNames@plt>
mov    -0x18(%rbp),%rdi
call   10d0 <XCloseDisplay@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1287 <main+0xc7>
mov    %rsi,0x10(%rsp)
xor    %edi,%edi
call   1090 <XOpenDisplay@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11fc <main+0x3c>
lea    0xe2e(%rip),%rsi
mov    $0x1,%edi
call   1070 <errx@plt>
mov    $0x1000,%ebp
lea    0xe2c(%rip),%r12
lea    0xc(%rsp),%r13
mov    0x2dcc(%rip),%r14
jmp    122a <main+0x6a>
cs nopw 0x0(%rax,%rax,1)
add    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <XFreeFontNames@plt>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %ebp,%edx
mov    %r13,%rcx
call   1060 <XListFonts@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1253 <main+0x93>
mov    $0x1,%edi
lea    0xde8(%rip),%rsi
call   1070 <errx@plt>
mov    0xc(%rsp),%edx
cmp    %ebp,%edx
jne    12aa <main+0xea>
mov    (%r14),%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
cmp    %ecx,%ebp
jle    1220 <main+0x60>
mov    0x2d7e(%rip),%rax
mov    (%rax),%esi
mov    $0x1,%edi
lea    0xdc7(%rip),%rdx
call   1050 <errc@plt>
jmp    1220 <main+0x60>
mov    0x2d32(%rip),%rax
mov    (%rax),%esi
lea    0xd69(%rip),%rdi
call   1080 <fputs@plt>
mov    0x2d35(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>
mov    0x2d0f(%rip),%rax
mov    (%rax),%edi
lea    0xdab(%rip),%rsi
call   10a0 <fprintf@plt>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
xor    %ecx,%ecx
call   10b0 <setvbuf@plt>
mov    0x10(%rsp),%r13
mov    0x8(%r13),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
cmpl   $0x0,0xc(%rsp)
jle    1341 <main+0x181>
mov    %rax,%r12
mov    (%rbx),%rsi
mov    %r15,%rdi
mov    %r14,%rdx
mov    %rax,%rcx
call   10e0 <emit_font_width@plt>
cmpl   $0x2,0xc(%rsp)
jl     1341 <main+0x181>
mov    $0x1,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    0x8(%r13),%rdx
mov    (%rbx,%rbp,8),%rsi
mov    %r15,%rdi
mov    %r12,%rcx
call   10e0 <emit_font_width@plt>
add    $0x1,%rbp
movslq 0xc(%rsp),%rax
cmp    %rax,%rbp
jl     1320 <main+0x160>
mov    %rbx,%rdi
call   1030 <XFreeFontNames@plt>
mov    %r15,%rdi
call   10d0 <XCloseDisplay@plt>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [32 x i8] c"Usage: xfontwidths text-phrase\0A\00"
@stderr = global i32 0
@EX_USAGE = global i32 0
@.str.1 = [20 x i8] c"XOpenDisplay failed\00"
@.str.2 = [2 x i8] c"*\00"
@.str.3 = [17 x i8] c"no fonts found??\00"
@INT_MAX = global i32 0
@EOVERFLOW = global i32 0
@.str.4 = [30 x i8] c"overflow on font names list??\00"
@.str.5 = [16 x i8] c"total-fonts %d\0A\00"
@stdout = global i32 0
@_IONBF = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i32
%10 = alloca i64
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp ne i32 %12, 2
br i1 %13, label %14, label %19
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %15)
%17 = load i32, i32* @EX_USAGE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %2
%20 = call i32* @XOpenDisplay(i32* null)
store i32* %20, i32** %6
%21 = icmp ne i32* %20, null
br i1 %21, label %24, label %22
22: ; preds = %19
%23 = call i32 @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %24
24: ; preds = %22, %19
store i32 4096, i32* %8
br label %25
25: ; preds = %24, %44
%26 = load i32*, i32** %6
%27 = load i32, i32* %8
%28 = call i8** @XListFonts(i32* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %27, i32* %9)
store i8** %28, i8*** %7
%29 = icmp ne i8** %28, null
br i1 %29, label %32, label %30
30: ; preds = %25
%31 = call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %32
32: ; preds = %30, %25
%33 = load i32, i32* %9
%34 = load i32, i32* %8
%35 = icmp eq i32 %33, %34
br i1 %35, label %36, label %49
36: ; preds = %32
%37 = load i32, i32* %8
%38 = load i32, i32* @INT_MAX
%39 = sdiv i32 %38, 2
%40 = icmp sgt i32 %37, %39
br i1 %40, label %41, label %44
41: ; preds = %36
%42 = load i32, i32* @EOVERFLOW
%43 = call i32 @errc(i32 1, i32 %42, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %44
44: ; preds = %41, %36
%45 = load i32, i32* %8
%46 = mul nsw i32 %45, 2
store i32 %46, i32* %8
%47 = load i8**, i8*** %7
%48 = call i32 @XFreeFontNames(i8** %47)
br label %25
49: ; preds = %32
br label %50
50: ; preds = %49
%51 = load i32, i32* @stderr
%52 = load i32, i32* %9
%53 = call i32 @fprintf(i32 %51, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %52)
%54 = load i32, i32* @stdout
%55 = load i32, i32* @_IONBF
%56 = call i32 @setvbuf(i32 %54, i8* null, i32 %55, i64 0)
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 1
%59 = load i8*, i8** %58
%60 = call i64 @strlen(i8* %59)
store i64 %60, i64* %10
store i32 0, i32* %11
br label %61
61: ; preds = %77, %50
%62 = load i32, i32* %11
%63 = load i32, i32* %9
%64 = icmp slt i32 %62, %63
br i1 %64, label %65, label %80
65: ; preds = %61
%66 = load i32*, i32** %6
%67 = load i8**, i8*** %7
%68 = load i32, i32* %11
%69 = sext i32 %68 to i64
%70 = getelementptr inbounds i8*, i8** %67, i64 %69
%71 = load i8*, i8** %70
%72 = load i8**, i8*** %5
%73 = getelementptr inbounds i8*, i8** %72, i64 1
%74 = load i8*, i8** %73
%75 = load i64, i64* %10
%76 = call i32 @emit_font_width(i32* %66, i8* %71, i8* %74, i64 %75)
br label %77
77: ; preds = %65
%78 = load i32, i32* %11
%79 = add nsw i32 %78, 1
store i32 %79, i32* %11
br label %61
80: ; preds = %61
%81 = load i8**, i8*** %7
%82 = call i32 @XFreeFontNames(i8** %81)
%83 = load i32*, i32** %6
%84 = call i32 @XCloseDisplay(i32* %83)
%85 = load i32, i32* @EXIT_SUCCESS
%86 = call i32 @exit(i32 %85)
unreachable
}

LLVM IR (-O2):
@.str = [32 x i8] c"Usage: xfontwidths text-phrase\0A\00"
@stderr = global i32 0
@EX_USAGE = global i32 0
@.str.1 = [20 x i8] c"XOpenDisplay failed\00"
@.str.2 = [2 x i8] c"*\00"
@.str.3 = [17 x i8] c"no fonts found??\00"
@INT_MAX = global i32 0
@EOVERFLOW = global i32 0
@.str.4 = [30 x i8] c"overflow on font names list??\00"
@.str.5 = [16 x i8] c"total-fonts %d\0A\00"
@stdout = global i32 0
@_IONBF = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %11, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fputs(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = load i32, i32* @EX_USAGE
%10 = tail call i32 @exit(i32 %9)
unreachable
11: ; preds = %2
%12 = tail call i32* @XOpenDisplay(i32* null)
%13 = icmp eq i32* %12, null
br i1 %13, label %14, label %16
14: ; preds = %11
%15 = tail call i32 @errx(i32 1, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %16
16: ; preds = %14, %11
br label %17
17: ; preds = %16, %33
%18 = phi i32 [ %34, %33 ], [ 4096, %16 ]
%19 = call i8** @XListFonts(i32* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0), i32 %18, i32* %3)
%20 = icmp eq i8** %19, null
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = call i32 @errx(i32 1, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.3, i64 0, i64 0))
br label %23
23: ; preds = %21, %17
%24 = load i32, i32* %3
%25 = icmp eq i32 %24, %18
br i1 %25, label %26, label %36
26: ; preds = %23
%27 = load i32, i32* @INT_MAX
%28 = sdiv i32 %27, 2
%29 = icmp sgt i32 %18, %28
br i1 %29, label %30, label %33
30: ; preds = %26
%31 = load i32, i32* @EOVERFLOW
%32 = call i32 @errc(i32 1, i32 %31, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.4, i64 0, i64 0))
br label %33
33: ; preds = %30, %26
%34 = shl nsw i32 %18, 1
%35 = call i32 @XFreeFontNames(i8** %19)
br label %17
36: ; preds = %23
%37 = load i32, i32* @stderr
%38 = call i32 @fprintf(i32 %37, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i32 %24)
%39 = load i32, i32* @stdout
%40 = load i32, i32* @_IONBF
%41 = call i32 @setvbuf(i32 %39, i8* null, i32 %40, i64 0)
%42 = getelementptr inbounds i8*, i8** %1, i64 1
%43 = load i8*, i8** %42
%44 = call i64 @strlen(i8* dereferenceable(1) %43)
%45 = load i32, i32* %3
%46 = icmp sgt i32 %45, 0
br i1 %46, label %47, label %52
47: ; preds = %36
%48 = load i8*, i8** %19
%49 = call i32 @emit_font_width(i32* %12, i8* %48, i8* %43, i64 %44)
%50 = load i32, i32* %3
%51 = icmp sgt i32 %50, 1
br i1 %51, label %57, label %52
52: ; preds = %57, %47, %36
%53 = call i32 @XFreeFontNames(i8** %19)
%54 = call i32 @XCloseDisplay(i32* %12)
%55 = load i32, i32* @EXIT_SUCCESS
%56 = call i32 @exit(i32 %55)
unreachable
57: ; preds = %47, %57
%58 = phi i64 [ %63, %57 ], [ 1, %47 ]
%59 = load i8*, i8** %42
%60 = getelementptr inbounds i8*, i8** %19, i64 %58
%61 = load i8*, i8** %60
%62 = call i32 @emit_font_width(i32* %12, i8* %61, i8* %59, i64 %44)
%63 = add nuw nsw i64 %58, 1
%64 = load i32, i32* %3
%65 = sext i32 %64 to i64
%66 = icmp slt i64 %63, %65
br i1 %66, label %57, label %52
}