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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
size_t get_char_width(char const *);
size_t correct_offset(const char line[], const int offsets[], size_t offset) {
  assert(offset != 0U && "Offset has to be greater than zero.");
  const int prev_offset = offsets[offset - 1];
  const size_t char_width = get_char_width(line + prev_offset);
  return prev_offset + char_width;
}


x86 assembly (clang, -O0):
<correct_offset>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x18(%rbp)
mov    %al,-0x29(%rbp)
je     114e <correct_offset+0x2e>
mov    $0x1,%al
mov    %al,-0x29(%rbp)
jmp    114e <correct_offset+0x2e>
mov    -0x29(%rbp),%al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%rax
mov    -0x18(%rbp),%rcx
sub    $0x1,%rcx
mov    (%rax,%rcx,4),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x8(%rbp),%rdi
movslq -0x1c(%rbp),%rax
add    %rax,%rdi
call   1030 <get_char_width@plt>
mov    %rax,-0x28(%rbp)
movslq -0x1c(%rbp),%rax
add    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<correct_offset>:
push   %r15
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %rsi,%r14
mov    %rdi,%r15
xor    %edi,%edi
add    $0xffffffffffffffff,%rbx
setb   %dil
call   1040 <assert@plt>
movslq (%r14,%rbx,4),%rbx
add    %rbx,%r15
mov    %r15,%rdi
call   1030 <get_char_width@plt>
add    %rbx,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [36 x i8] c"Offset has to be greater than zero.\00"
define i64 @correct_offset(i8* %0, i32* %1, i64 %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i32
%8 = alloca i64
store i8* %0, i8** %4
store i32* %1, i32** %5
store i64 %2, i64* %6
%9 = load i64, i64* %6
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %12
11: ; preds = %3
br label %12
12: ; preds = %11, %3
%13 = phi i1 [ false, %3 ], [ true, %11 ]
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i32*, i32** %5
%17 = load i64, i64* %6
%18 = sub i64 %17, 1
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
store i32 %20, i32* %7
%21 = load i8*, i8** %4
%22 = load i32, i32* %7
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %21, i64 %23
%25 = call i64 @get_char_width(i8* %24)
store i64 %25, i64* %8
%26 = load i32, i32* %7
%27 = sext i32 %26 to i64
%28 = load i64, i64* %8
%29 = add i64 %27, %28
ret i64 %29
}

LLVM IR (-O2):
define i64 @correct_offset(i8* %0, i32* nocapture %1, i64 %2) {
%4 = icmp ne i64 %2, 0
%5 = zext i1 %4 to i32
%6 = tail call i32 @assert(i32 %5)
%7 = add i64 %2, -1
%8 = getelementptr inbounds i32, i32* %1, i64 %7
%9 = load i32, i32* %8
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
%12 = tail call i64 @get_char_width(i8* %11)
%13 = add i64 %12, %10
ret i64 %13
}