#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 atoi(char *);
int /*<<< orphan*/ ends_with_101(char *, size_t);
int /*<<< orphan*/ increment(char *, size_t);
void update_buffer(char *str, size_t l) {
  while (atoi(str + (l - 3)) % 8 != 0 && !ends_with_101(str, l))
    increment(str, l);
}


x86 assembly (clang, -O0):
<update_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rax
sub    $0x3,%rax
add    %rax,%rdi
call   1050 <atoi@plt>
mov    $0x8,%ecx
cltd
idiv   %ecx
xor    %eax,%eax
cmp    $0x0,%edx
mov    %al,-0x11(%rbp)
je     1182 <update_buffer+0x52>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1040 <ends_with_101@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
mov    %al,-0x11(%rbp)
mov    -0x11(%rbp),%al
test   $0x1,%al
jne    1192 <update_buffer+0x62>
jmp    11a4 <update_buffer+0x74>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <increment@plt>
jmp    1140 <update_buffer+0x10>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<update_buffer>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
lea    (%rsi,%rdi,1),%r15
add    $0xfffffffffffffffd,%r15
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1050 <atoi@plt>
test   $0x7,%al
je     1178 <update_buffer+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1040 <ends_with_101@plt>
test   %eax,%eax
jne    1178 <update_buffer+0x48>
mov    %rbx,%rdi
mov    %r14,%rsi
call   1030 <increment@plt>
jmp    1150 <update_buffer+0x20>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @update_buffer(i8* %0, i64 %1) {
%3 = alloca i8*
%4 = alloca i64
store i8* %0, i8** %3
store i64 %1, i64* %4
br label %5
5: ; preds = %21, %2
%6 = load i8*, i8** %3
%7 = load i64, i64* %4
%8 = sub i64 %7, 3
%9 = getelementptr inbounds i8, i8* %6, i64 %8
%10 = call i32 @atoi(i8* %9)
%11 = srem i32 %10, 8
%12 = icmp ne i32 %11, 0
br i1 %12, label %13, label %19
13: ; preds = %5
%14 = load i8*, i8** %3
%15 = load i64, i64* %4
%16 = call i32 @ends_with_101(i8* %14, i64 %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br label %19
19: ; preds = %13, %5
%20 = phi i1 [ false, %5 ], [ %18, %13 ]
br i1 %20, label %21, label %25
21: ; preds = %19
%22 = load i8*, i8** %3
%23 = load i64, i64* %4
%24 = call i32 @increment(i8* %22, i64 %23)
br label %5
25: ; preds = %19
ret void
}

LLVM IR (-O2):
define void @update_buffer(i8* %0, i64 %1) {
%3 = add i64 %1, -3
%4 = getelementptr inbounds i8, i8* %0, i64 %3
%5 = tail call i32 @atoi(i8* %4)
%6 = and i32 %5, 7
%7 = icmp eq i32 %6, 0
br i1 %7, label %16, label %8
8: ; preds = %2, %11
%9 = tail call i32 @ends_with_101(i8* %0, i64 %1)
%10 = icmp eq i32 %9, 0
br i1 %10, label %11, label %16
11: ; preds = %8
%12 = tail call i32 @increment(i8* %0, i64 %1)
%13 = tail call i32 @atoi(i8* %4)
%14 = and i32 %13, 7
%15 = icmp eq i32 %14, 0
br i1 %15, label %16, label %8
16: ; preds = %8, %11, %2
ret void
}