#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 */
struct dtx_glyphmap {
  int dummy;
};
struct dtx_font {
  int dummy;
};

/* Variables and functions */
struct dtx_glyphmap *dtx_get_font_glyphmap(struct dtx_font *, int, char);
int /*<<< orphan*/ dtx_prepare(struct dtx_font *, int);
int /*<<< orphan*/ dtx_prepare_range(struct dtx_font *, int, int, int);
int dtx_save_glyphmap(char const *, struct dtx_glyphmap *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
int font2glyphmap(struct dtx_font *font, const char *infname,
                  const char *outfname, int size, int rstart, int rend) {
  struct dtx_glyphmap *gmap;
  if (rstart != -1) {
    dtx_prepare_range(font, size, rstart, rend);
    if (!(gmap = dtx_get_font_glyphmap(font, size, rstart))) {
      fprintf(stderr,
              "failed to retrieve unicode glyphmap (code range: %d-%d)\n",
              rstart, rend);
      return -1;
    }
  } else {
    dtx_prepare(font, size);
    if (!(gmap = dtx_get_font_glyphmap(font, size, ' '))) {
      fprintf(stderr, "failed to retrieve ASCII glyphmap!\n");
      return -1;
    }
  }
  if (dtx_save_glyphmap(outfname, gmap) == -1) {
    fprintf(stderr, "failed to save glyphmap to: %s\n", outfname);
    return -1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<font2glyphmap>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    %ecx,-0x24(%rbp)
mov    %r8d,-0x28(%rbp)
mov    %r9d,-0x2c(%rbp)
cmpl   $0xffffffff,-0x28(%rbp)
je     11d9 <font2glyphmap+0x89>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
call   1030 <dtx_prepare_range@plt>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x28(%rbp),%eax
movsbl %al,%edx
call   1040 <dtx_get_font_glyphmap@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    11d4 <font2glyphmap+0x84>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xe3f(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <font2glyphmap+0x120>
jmp    122c <font2glyphmap+0xdc>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
call   1070 <dtx_prepare@plt>
mov    -0x10(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    $0x20,%edx
call   1040 <dtx_get_font_glyphmap@plt>
mov    %rax,-0x38(%rbp)
cmp    $0x0,%rax
jne    1227 <font2glyphmap+0xd7>
mov    0x2dd5(%rip),%rax
mov    (%rax),%edi
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <font2glyphmap+0x120>
jmp    122c <font2glyphmap+0xdc>
mov    -0x20(%rbp),%rdi
mov    -0x38(%rbp),%rsi
call   1060 <dtx_save_glyphmap@plt>
cmp    $0xffffffff,%eax
jne    1269 <font2glyphmap+0x119>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1270 <font2glyphmap+0x120>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<font2glyphmap>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %ecx,%ebp
mov    %rdx,%r14
mov    %rdi,%rbx
cmp    $0xffffffff,%r8d
je     11ae <font2glyphmap+0x5e>
mov    %r9d,%r15d
mov    %r8d,%r12d
mov    %rbx,%rdi
mov    %ebp,%esi
mov    %r8d,%edx
mov    %r9d,%ecx
call   1030 <dtx_prepare_range@plt>
movsbl %r12b,%edx
mov    %rbx,%rdi
mov    %ebp,%esi
call   1040 <dtx_get_font_glyphmap@plt>
test   %rax,%rax
jne    11cc <font2glyphmap+0x7c>
mov    0x2e4a(%rip),%rax
mov    (%rax),%edi
lea    0xe61(%rip),%rsi
mov    %r12d,%edx
mov    %r15d,%ecx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1213 <font2glyphmap+0xc3>
mov    %rbx,%rdi
mov    %ebp,%esi
call   1070 <dtx_prepare@plt>
mov    %rbx,%rdi
mov    %ebp,%esi
mov    $0x20,%edx
call   1040 <dtx_get_font_glyphmap@plt>
test   %rax,%rax
je     11fc <font2glyphmap+0xac>
mov    %r14,%rdi
mov    %rax,%rsi
call   1060 <dtx_save_glyphmap@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1218 <font2glyphmap+0xc8>
mov    0x2df9(%rip),%rax
mov    (%rax),%edi
lea    0xe6d(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1213 <font2glyphmap+0xc3>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe2d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dtx_font = type { i32 }
%struct.dtx_glyphmap = type { i32 }
@stderr = global i32 0
@.str = [57 x i8] c"failed to retrieve unicode glyphmap (code range: %d-%d)\0A\00"
@.str.1 = [36 x i8] c"failed to retrieve ASCII glyphmap!\0A\00"
@.str.2 = [32 x i8] c"failed to save glyphmap to: %s\0A\00"
define i32 @font2glyphmap(%struct.dtx_font* %0, i8* %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca %struct.dtx_font*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca %struct.dtx_glyphmap*
store %struct.dtx_font* %0, %struct.dtx_font** %8
store i8* %1, i8** %9
store i8* %2, i8** %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
%15 = load i32, i32* %12
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %35
17: ; preds = %6
%18 = load %struct.dtx_font*, %struct.dtx_font** %8
%19 = load i32, i32* %11
%20 = load i32, i32* %12
%21 = load i32, i32* %13
%22 = call i32 @dtx_prepare_range(%struct.dtx_font* %18, i32 %19, i32 %20, i32 %21)
%23 = load %struct.dtx_font*, %struct.dtx_font** %8
%24 = load i32, i32* %11
%25 = load i32, i32* %12
%26 = trunc i32 %25 to i8
%27 = call %struct.dtx_glyphmap* @dtx_get_font_glyphmap(%struct.dtx_font* %23, i32 %24, i8 signext %26)
store %struct.dtx_glyphmap* %27, %struct.dtx_glyphmap** %14
%28 = icmp ne %struct.dtx_glyphmap* %27, null
br i1 %28, label %34, label %29
29: ; preds = %17
%30 = load i32, i32* @stderr
%31 = load i32, i32* %12
%32 = load i32, i32* %13
%33 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %31, i32 %32)
store i32 -1, i32* %7
br label %57
34: ; preds = %17
br label %47
35: ; preds = %6
%36 = load %struct.dtx_font*, %struct.dtx_font** %8
%37 = load i32, i32* %11
%38 = call i32 @dtx_prepare(%struct.dtx_font* %36, i32 %37)
%39 = load %struct.dtx_font*, %struct.dtx_font** %8
%40 = load i32, i32* %11
%41 = call %struct.dtx_glyphmap* @dtx_get_font_glyphmap(%struct.dtx_font* %39, i32 %40, i8 signext 32)
store %struct.dtx_glyphmap* %41, %struct.dtx_glyphmap** %14
%42 = icmp ne %struct.dtx_glyphmap* %41, null
br i1 %42, label %46, label %43
43: ; preds = %35
%44 = load i32, i32* @stderr
%45 = call i32 (i32, i8*, ...) @fprintf(i32 %44, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %7
br label %57
46: ; preds = %35
br label %47
47: ; preds = %46, %34
%48 = load i8*, i8** %10
%49 = load %struct.dtx_glyphmap*, %struct.dtx_glyphmap** %14
%50 = call i32 @dtx_save_glyphmap(i8* %48, %struct.dtx_glyphmap* %49)
%51 = icmp eq i32 %50, -1
br i1 %51, label %52, label %56
52: ; preds = %47
%53 = load i32, i32* @stderr
%54 = load i8*, i8** %10
%55 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %54)
store i32 -1, i32* %7
br label %57
56: ; preds = %47
store i32 0, i32* %7
br label %57
57: ; preds = %56, %52, %43, %29
%58 = load i32, i32* %7
ret i32 %58
}

LLVM IR (-O2):
%struct.dtx_font = type { i32 }
%struct.dtx_glyphmap = type { i32 }
@stderr = global i32 0
@.str = [57 x i8] c"failed to retrieve unicode glyphmap (code range: %d-%d)\0A\00"
@.str.1 = [36 x i8] c"failed to retrieve ASCII glyphmap!\0A\00"
@.str.2 = [32 x i8] c"failed to save glyphmap to: %s\0A\00"
define i32 @font2glyphmap(%struct.dtx_font* %0, i8* nocapture readnone %1, i8* %2, i32 %3, i32 %4, i32 %5) {
%7 = icmp eq i32 %4, -1
br i1 %7, label %16, label %8
8: ; preds = %6
%9 = tail call i32 @dtx_prepare_range(%struct.dtx_font* %0, i32 %3, i32 %4, i32 %5)
%10 = trunc i32 %4 to i8
%11 = tail call %struct.dtx_glyphmap* @dtx_get_font_glyphmap(%struct.dtx_font* %0, i32 %3, i8 signext %10)
%12 = icmp eq %struct.dtx_glyphmap* %11, null
br i1 %12, label %13, label %23
13: ; preds = %8
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0), i32 %4, i32 %5)
br label %30
16: ; preds = %6
%17 = tail call i32 @dtx_prepare(%struct.dtx_font* %0, i32 %3)
%18 = tail call %struct.dtx_glyphmap* @dtx_get_font_glyphmap(%struct.dtx_font* %0, i32 %3, i8 signext 32)
%19 = icmp eq %struct.dtx_glyphmap* %18, null
br i1 %19, label %20, label %23
20: ; preds = %16
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.1, i64 0, i64 0))
br label %30
23: ; preds = %16, %8
%24 = phi %struct.dtx_glyphmap* [ %11, %8 ], [ %18, %16 ]
%25 = tail call i32 @dtx_save_glyphmap(i8* %2, %struct.dtx_glyphmap* %24)
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %30
27: ; preds = %23
%28 = load i32, i32* @stderr
%29 = tail call i32 (i32, i8*, ...) @fprintf(i32 %28, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %30
30: ; preds = %23, %27, %20, %13
%31 = phi i32 [ -1, %27 ], [ -1, %13 ], [ -1, %20 ], [ 0, %23 ]
ret i32 %31
}