#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*/ num;

/* Variables and functions */
int /*<<< orphan*/ Com_sprintf(char *, int, char *, int);
int strlen(char *);
int CG_DrawFieldWidth(int x, int y, int width, int value, int charWidth,
                      int charHeight) {
  char num[16], *ptr;
  int l;
  int frame;
  int totalwidth = 0;
  if (width < 1) {
    return 0;
  }
  if (width > 5) {
    width = 5;
  }
  switch (width) {
  case 1:
    value = value > 9 ? 9 : value;
    value = value < 0 ? 0 : value;
    break;
  case 2:
    value = value > 99 ? 99 : value;
    value = value < -9 ? -9 : value;
    break;
  case 3:
    value = value > 999 ? 999 : value;
    value = value < -99 ? -99 : value;
    break;
  case 4:
    value = value > 9999 ? 9999 : value;
    value = value < -999 ? -999 : value;
    break;
  }
  Com_sprintf(num, sizeof(num), "%i", value);
  l = strlen(num);
  if (l > width)
    l = width;
  ptr = num;
  while (*ptr && l) {
    if (*ptr == '-')
      frame = 10;
    else
      frame = *ptr - '0';
    totalwidth += charWidth;
    ptr++;
    l--;
  }
  return totalwidth;
}


x86 assembly (clang, -O0):
<CG_DrawFieldWidth>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
mov    %edi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %edx,-0x10(%rbp)
mov    %ecx,-0x14(%rbp)
mov    %r8d,-0x18(%rbp)
mov    %r9d,-0x1c(%rbp)
movl   $0x0,-0x44(%rbp)
cmpl   $0x1,-0x10(%rbp)
jge    115c <CG_DrawFieldWidth+0x3c>
movl   $0x0,-0x4(%rbp)
jmp    1382 <CG_DrawFieldWidth+0x262>
cmpl   $0x5,-0x10(%rbp)
jle    116d <CG_DrawFieldWidth+0x4d>
movl   $0x5,-0x10(%rbp)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,%ecx
mov    %rcx,-0x50(%rbp)
sub    $0x3,%eax
ja     12c3 <CG_DrawFieldWidth+0x1a3>
mov    -0x50(%rbp),%rax
lea    0xe73(%rip),%rcx
movslq (%rcx,%rax,4),%rax
add    %rcx,%rax
jmp    *%rax
cmpl   $0x9,-0x14(%rbp)
jle    11ad <CG_DrawFieldWidth+0x8d>
mov    $0x9,%eax
mov    %eax,-0x54(%rbp)
jmp    11b3 <CG_DrawFieldWidth+0x93>
mov    -0x14(%rbp),%eax
mov    %eax,-0x54(%rbp)
mov    -0x54(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11cd <CG_DrawFieldWidth+0xad>
xor    %eax,%eax
mov    %eax,-0x58(%rbp)
jmp    11d3 <CG_DrawFieldWidth+0xb3>
mov    -0x14(%rbp),%eax
mov    %eax,-0x58(%rbp)
mov    -0x58(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12c3 <CG_DrawFieldWidth+0x1a3>
cmpl   $0x63,-0x14(%rbp)
jle    11f5 <CG_DrawFieldWidth+0xd5>
mov    $0x63,%eax
mov    %eax,-0x5c(%rbp)
jmp    11fb <CG_DrawFieldWidth+0xdb>
mov    -0x14(%rbp),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x5c(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xfffffff7,-0x14(%rbp)
jge    1218 <CG_DrawFieldWidth+0xf8>
mov    $0xfffffff7,%eax
mov    %eax,-0x60(%rbp)
jmp    121e <CG_DrawFieldWidth+0xfe>
mov    -0x14(%rbp),%eax
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12c3 <CG_DrawFieldWidth+0x1a3>
cmpl   $0x3e7,-0x14(%rbp)
jle    1243 <CG_DrawFieldWidth+0x123>
mov    $0x3e7,%eax
mov    %eax,-0x64(%rbp)
jmp    1249 <CG_DrawFieldWidth+0x129>
mov    -0x14(%rbp),%eax
mov    %eax,-0x64(%rbp)
mov    -0x64(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xffffff9d,-0x14(%rbp)
jge    1266 <CG_DrawFieldWidth+0x146>
mov    $0xffffff9d,%eax
mov    %eax,-0x68(%rbp)
jmp    126c <CG_DrawFieldWidth+0x14c>
mov    -0x14(%rbp),%eax
mov    %eax,-0x68(%rbp)
mov    -0x68(%rbp),%eax
mov    %eax,-0x14(%rbp)
jmp    12c3 <CG_DrawFieldWidth+0x1a3>
cmpl   $0x270f,-0x14(%rbp)
jle    1291 <CG_DrawFieldWidth+0x171>
mov    $0x270f,%eax
mov    %eax,-0x6c(%rbp)
jmp    1297 <CG_DrawFieldWidth+0x177>
mov    -0x14(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x6c(%rbp),%eax
mov    %eax,-0x14(%rbp)
cmpl   $0xfffffc19,-0x14(%rbp)
jge    12b7 <CG_DrawFieldWidth+0x197>
mov    $0xfffffc19,%eax
mov    %eax,-0x70(%rbp)
jmp    12bd <CG_DrawFieldWidth+0x19d>
mov    -0x14(%rbp),%eax
mov    %eax,-0x70(%rbp)
mov    -0x70(%rbp),%eax
mov    %eax,-0x14(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x14(%rbp),%ecx
mov    $0x10,%esi
lea    0xd3a(%rip),%rdx
call   1040 <Com_sprintf@plt>
lea    -0x30(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x10(%rbp),%eax
jle    12f9 <CG_DrawFieldWidth+0x1d9>
mov    -0x10(%rbp),%eax
mov    %eax,-0x3c(%rbp)
lea    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movsbl (%rax),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0x71(%rbp)
je     1320 <CG_DrawFieldWidth+0x200>
cmpl   $0x0,-0x3c(%rbp)
setne  %al
mov    %al,-0x71(%rbp)
mov    -0x71(%rbp),%al
test   $0x1,%al
jne    1330 <CG_DrawFieldWidth+0x210>
jmp    137c <CG_DrawFieldWidth+0x25c>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    134c <CG_DrawFieldWidth+0x22c>
movl   $0xa,-0x40(%rbp)
jmp    1359 <CG_DrawFieldWidth+0x239>
mov    -0x38(%rbp),%rax
movsbl (%rax),%eax
sub    $0x30,%eax
mov    %eax,-0x40(%rbp)
mov    -0x18(%rbp),%eax
add    -0x44(%rbp),%eax
mov    %eax,-0x44(%rbp)
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
mov    -0x3c(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x3c(%rbp)
jmp    1301 <CG_DrawFieldWidth+0x1e1>
mov    -0x44(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<CG_DrawFieldWidth>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %ebx,%ebx
test   %edx,%edx
jle    1213 <CG_DrawFieldWidth+0xf3>
mov    %r8d,%ebp
cmp    $0x5,%edx
mov    $0x5,%r15d
cmovb  %edx,%r15d
lea    -0x1(%r15),%eax
cmp    $0x3,%eax
ja     11b9 <CG_DrawFieldWidth+0x99>
lea    0xeac(%rip),%rdx
movslq (%rdx,%rax,4),%rax
add    %rdx,%rax
jmp    *%rax
cmp    $0x9,%ecx
mov    $0x9,%eax
cmovl  %ecx,%eax
xor    %ecx,%ecx
test   %eax,%eax
cmovns %eax,%ecx
jmp    11b9 <CG_DrawFieldWidth+0x99>
cmp    $0x63,%ecx
mov    $0x63,%eax
cmovl  %ecx,%eax
cmp    $0xfffffff8,%eax
mov    $0xfffffff7,%ecx
jmp    11b6 <CG_DrawFieldWidth+0x96>
cmp    $0x3e7,%ecx
mov    $0x3e7,%eax
cmovl  %ecx,%eax
cmp    $0xffffff9e,%eax
mov    $0xffffff9d,%ecx
jmp    11b6 <CG_DrawFieldWidth+0x96>
cmp    $0x270f,%ecx
mov    $0x270f,%eax
cmovl  %ecx,%eax
cmp    $0xfffffc1a,%eax
mov    $0xfffffc19,%ecx
cmovge %eax,%ecx
lea    0xe50(%rip),%rdx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x10,%esi
call   1040 <Com_sprintf@plt>
mov    %r14,%rdi
call   1030 <strlen@plt>
cmp    %r15d,%eax
cmovg  %r15d,%eax
cmpb   $0x0,(%rsp)
je     1213 <CG_DrawFieldWidth+0xf3>
test   %eax,%eax
je     1213 <CG_DrawFieldWidth+0xf3>
mov    %eax,%eax
xor    %ebx,%ebx
mov    $0x1,%ecx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
add    %ebp,%ebx
cmpb   $0x0,(%rsp,%rcx,1)
je     1213 <CG_DrawFieldWidth+0xf3>
lea    0x1(%rcx),%rdx
cmp    %ecx,%eax
mov    %rdx,%rcx
jne    1200 <CG_DrawFieldWidth+0xe0>
mov    %ebx,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%i\00"
define i32 @CG_DrawFieldWidth(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca [16 x i8]
%15 = alloca i8*
%16 = alloca i32
%17 = alloca i32
%18 = alloca i32
store i32 %0, i32* %8
store i32 %1, i32* %9
store i32 %2, i32* %10
store i32 %3, i32* %11
store i32 %4, i32* %12
store i32 %5, i32* %13
store i32 0, i32* %18
%19 = load i32, i32* %10
%20 = icmp slt i32 %19, 1
br i1 %20, label %21, label %22
21: ; preds = %6
store i32 0, i32* %7
br label %132
22: ; preds = %6
%23 = load i32, i32* %10
%24 = icmp sgt i32 %23, 5
br i1 %24, label %25, label %26
25: ; preds = %22
store i32 5, i32* %10
br label %26
26: ; preds = %25, %22
%27 = load i32, i32* %10
switch i32 %27, label %88 [
i32 1, label %28
i32 2, label %43
i32 3, label %58
i32 4, label %73
]
28: ; preds = %26
%29 = load i32, i32* %11
%30 = icmp sgt i32 %29, 9
br i1 %30, label %31, label %32
31: ; preds = %28
br label %34
32: ; preds = %28
%33 = load i32, i32* %11
br label %34
34: ; preds = %32, %31
%35 = phi i32 [ 9, %31 ], [ %33, %32 ]
store i32 %35, i32* %11
%36 = load i32, i32* %11
%37 = icmp slt i32 %36, 0
br i1 %37, label %38, label %39
38: ; preds = %34
br label %41
39: ; preds = %34
%40 = load i32, i32* %11
br label %41
41: ; preds = %39, %38
%42 = phi i32 [ 0, %38 ], [ %40, %39 ]
store i32 %42, i32* %11
br label %88
43: ; preds = %26
%44 = load i32, i32* %11
%45 = icmp sgt i32 %44, 99
br i1 %45, label %46, label %47
46: ; preds = %43
br label %49
47: ; preds = %43
%48 = load i32, i32* %11
br label %49
49: ; preds = %47, %46
%50 = phi i32 [ 99, %46 ], [ %48, %47 ]
store i32 %50, i32* %11
%51 = load i32, i32* %11
%52 = icmp slt i32 %51, -9
br i1 %52, label %53, label %54
53: ; preds = %49
br label %56
54: ; preds = %49
%55 = load i32, i32* %11
br label %56
56: ; preds = %54, %53
%57 = phi i32 [ -9, %53 ], [ %55, %54 ]
store i32 %57, i32* %11
br label %88
58: ; preds = %26
%59 = load i32, i32* %11
%60 = icmp sgt i32 %59, 999
br i1 %60, label %61, label %62
61: ; preds = %58
br label %64
62: ; preds = %58
%63 = load i32, i32* %11
br label %64
64: ; preds = %62, %61
%65 = phi i32 [ 999, %61 ], [ %63, %62 ]
store i32 %65, i32* %11
%66 = load i32, i32* %11
%67 = icmp slt i32 %66, -99
br i1 %67, label %68, label %69
68: ; preds = %64
br label %71
69: ; preds = %64
%70 = load i32, i32* %11
br label %71
71: ; preds = %69, %68
%72 = phi i32 [ -99, %68 ], [ %70, %69 ]
store i32 %72, i32* %11
br label %88
73: ; preds = %26
%74 = load i32, i32* %11
%75 = icmp sgt i32 %74, 9999
br i1 %75, label %76, label %77
76: ; preds = %73
br label %79
77: ; preds = %73
%78 = load i32, i32* %11
br label %79
79: ; preds = %77, %76
%80 = phi i32 [ 9999, %76 ], [ %78, %77 ]
store i32 %80, i32* %11
%81 = load i32, i32* %11
%82 = icmp slt i32 %81, -999
br i1 %82, label %83, label %84
83: ; preds = %79
br label %86
84: ; preds = %79
%85 = load i32, i32* %11
br label %86
86: ; preds = %84, %83
%87 = phi i32 [ -999, %83 ], [ %85, %84 ]
store i32 %87, i32* %11
br label %88
88: ; preds = %26, %86, %71, %56, %41
%89 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%90 = load i32, i32* %11
%91 = call i32 @Com_sprintf(i8* %89, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %90)
%92 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
%93 = call i32 @strlen(i8* %92)
store i32 %93, i32* %16
%94 = load i32, i32* %16
%95 = load i32, i32* %10
%96 = icmp sgt i32 %94, %95
br i1 %96, label %97, label %99
97: ; preds = %88
%98 = load i32, i32* %10
store i32 %98, i32* %16
br label %99
99: ; preds = %97, %88
%100 = getelementptr inbounds [16 x i8], [16 x i8]* %14, i64 0, i64 0
store i8* %100, i8** %15
br label %101
101: ; preds = %122, %99
%102 = load i8*, i8** %15
%103 = load i8, i8* %102
%104 = sext i8 %103 to i32
%105 = icmp ne i32 %104, 0
br i1 %105, label %106, label %109
106: ; preds = %101
%107 = load i32, i32* %16
%108 = icmp ne i32 %107, 0
br label %109
109: ; preds = %106, %101
%110 = phi i1 [ false, %101 ], [ %108, %106 ]
br i1 %110, label %111, label %130
111: ; preds = %109
%112 = load i8*, i8** %15
%113 = load i8, i8* %112
%114 = sext i8 %113 to i32
%115 = icmp eq i32 %114, 45
br i1 %115, label %116, label %117
116: ; preds = %111
store i32 10, i32* %17
br label %122
117: ; preds = %111
%118 = load i8*, i8** %15
%119 = load i8, i8* %118
%120 = sext i8 %119 to i32
%121 = sub nsw i32 %120, 48
store i32 %121, i32* %17
br label %122
122: ; preds = %117, %116
%123 = load i32, i32* %12
%124 = load i32, i32* %18
%125 = add nsw i32 %124, %123
store i32 %125, i32* %18
%126 = load i8*, i8** %15
%127 = getelementptr inbounds i8, i8* %126, i32 1
store i8* %127, i8** %15
%128 = load i32, i32* %16
%129 = add nsw i32 %128, -1
store i32 %129, i32* %16
br label %101
130: ; preds = %109
%131 = load i32, i32* %18
store i32 %131, i32* %7
br label %132
132: ; preds = %130, %21
%133 = load i32, i32* %7
ret i32 %133
}

LLVM IR (-O2):
@.str = [3 x i8] c"%i\00"
define i32 @CG_DrawFieldWidth(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5) {
%7 = alloca [16 x i8]
%8 = getelementptr inbounds [16 x i8], [16 x i8]* %7, i64 0, i64 0
%9 = icmp slt i32 %2, 1
br i1 %9, label %54, label %10
10: ; preds = %6
%11 = icmp ult i32 %2, 5
%12 = select i1 %11, i32 %2, i32 5
switch i32 %12, label %33 [
i32 1, label %13
i32 2, label %18
i32 3, label %23
i32 4, label %28
]
13: ; preds = %10
%14 = icmp slt i32 %3, 9
%15 = select i1 %14, i32 %3, i32 9
%16 = icmp sgt i32 %15, 0
%17 = select i1 %16, i32 %15, i32 0
br label %33
18: ; preds = %10
%19 = icmp slt i32 %3, 99
%20 = select i1 %19, i32 %3, i32 99
%21 = icmp sgt i32 %20, -9
%22 = select i1 %21, i32 %20, i32 -9
br label %33
23: ; preds = %10
%24 = icmp slt i32 %3, 999
%25 = select i1 %24, i32 %3, i32 999
%26 = icmp sgt i32 %25, -99
%27 = select i1 %26, i32 %25, i32 -99
br label %33
28: ; preds = %10
%29 = icmp slt i32 %3, 9999
%30 = select i1 %29, i32 %3, i32 9999
%31 = icmp sgt i32 %30, -999
%32 = select i1 %31, i32 %30, i32 -999
br label %33
33: ; preds = %10, %28, %23, %18, %13
%34 = phi i32 [ %3, %10 ], [ %32, %28 ], [ %27, %23 ], [ %22, %18 ], [ %17, %13 ]
%35 = call i32 @Com_sprintf(i8* %8, i32 16, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32 %34)
%36 = call i32 @strlen(i8* %8)
%37 = icmp sgt i32 %36, %12
%38 = select i1 %37, i32 %12, i32 %36
%39 = load i8, i8* %8
%40 = icmp ne i8 %39, 0
%41 = icmp ne i32 %38, 0
%42 = select i1 %40, i1 %41, i1 false
br i1 %42, label %43, label %54
43: ; preds = %33, %43
%44 = phi i32 [ %47, %43 ], [ 0, %33 ]
%45 = phi i32 [ %49, %43 ], [ %38, %33 ]
%46 = phi i8* [ %48, %43 ], [ %8, %33 ]
%47 = add nsw i32 %44, %4
%48 = getelementptr inbounds i8, i8* %46, i64 1
%49 = add nsw i32 %45, -1
%50 = load i8, i8* %48
%51 = icmp ne i8 %50, 0
%52 = icmp ne i32 %49, 0
%53 = select i1 %51, i1 %52, i1 false
br i1 %53, label %43, label %54
54: ; preds = %43, %33, %6
%55 = phi i32 [ 0, %6 ], [ 0, %33 ], [ %47, %43 ]
ret i32 %55
}