#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 font_hdr {
  int dummy;
};

/* Variables and functions */
scalar_t__ fchar_width(struct font_hdr *, unsigned char *);
long fnstring_width(struct font_hdr *f, unsigned char *s, int n) {
  long acc = 0;
  while (--n >= 0) {
    acc += fchar_width(f, s);
    s++;
  }
  return (acc);
}


x86 assembly (clang, -O0):
<fnstring_width>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jl     1163 <fnstring_width+0x53>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <fchar_width@plt>
add    -0x20(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
jmp    112b <fnstring_width+0x1b>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fnstring_width>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
test   %edx,%edx
jle    114c <fnstring_width+0x3c>
mov    %edx,%ebp
mov    %rsi,%rbx
mov    %rdi,%r14
add    $0x1,%ebp
xor    %r15d,%r15d
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %rbx,%rsi
call   1030 <fchar_width@plt>
add    %rax,%r15
add    $0x1,%rbx
add    $0xffffffff,%ebp
cmp    $0x1,%ebp
ja     1130 <fnstring_width+0x20>
jmp    114f <fnstring_width+0x3f>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.font_hdr = type { i32 }
define i64 @fnstring_width(%struct.font_hdr* %0, i8* %1, i32 %2) {
%4 = alloca %struct.font_hdr*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i64
store %struct.font_hdr* %0, %struct.font_hdr** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
store i64 0, i64* %7
br label %8
8: ; preds = %12, %3
%9 = load i32, i32* %6
%10 = add nsw i32 %9, -1
store i32 %10, i32* %6
%11 = icmp sge i32 %10, 0
br i1 %11, label %12, label %20
12: ; preds = %8
%13 = load %struct.font_hdr*, %struct.font_hdr** %4
%14 = load i8*, i8** %5
%15 = call i64 @fchar_width(%struct.font_hdr* %13, i8* %14)
%16 = load i64, i64* %7
%17 = add nsw i64 %16, %15
store i64 %17, i64* %7
%18 = load i8*, i8** %5
%19 = getelementptr inbounds i8, i8* %18, i32 1
store i8* %19, i8** %5
br label %8
20: ; preds = %8
%21 = load i64, i64* %7
ret i64 %21
}

LLVM IR (-O2):
%struct.font_hdr = type { i32 }
define i64 @fnstring_width(%struct.font_hdr* %0, i8* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %14
5: ; preds = %3, %5
%6 = phi i64 [ %11, %5 ], [ 0, %3 ]
%7 = phi i32 [ %9, %5 ], [ %2, %3 ]
%8 = phi i8* [ %12, %5 ], [ %1, %3 ]
%9 = add nsw i32 %7, -1
%10 = tail call i64 @fchar_width(%struct.font_hdr* %0, i8* %8)
%11 = add nsw i64 %10, %6
%12 = getelementptr inbounds i8, i8* %8, i64 1
%13 = icmp ugt i32 %7, 1
br i1 %13, label %5, label %14
14: ; preds = %5, %3
%15 = phi i64 [ 0, %3 ], [ %11, %5 ]
ret i64 %15
}