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

/* Variables and functions */
int buffer_addchar(struct buffer *, unsigned char const);
int buffer_addstring(struct buffer *b, const unsigned char *s) {
  int r;
  for (; *s; s++) {
    if ((r = buffer_addchar(b, *s)) != 0) {
      return r;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<buffer_addstring>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rax
cmpb   $0x0,(%rax)
je     116a <buffer_addstring+0x5a>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rax
movzbl (%rax),%esi
call   1030 <buffer_addchar@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
je     1154 <buffer_addstring+0x44>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1171 <buffer_addstring+0x61>
jmp    1159 <buffer_addstring+0x49>
mov    -0x18(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x18(%rbp)
jmp    1120 <buffer_addstring+0x10>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<buffer_addstring>:
push   %rbp
push   %r14
push   %rbx
mov    (%rsi),%al
xor    %r14d,%r14d
test   %al,%al
je     114f <buffer_addstring+0x3f>
mov    %rsi,%rbx
mov    %rdi,%rbp
add    $0x1,%rbx
nopw   0x0(%rax,%rax,1)
movzbl %al,%esi
mov    %rbp,%rdi
call   1030 <buffer_addchar@plt>
test   %eax,%eax
jne    114c <buffer_addstring+0x3c>
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    1130 <buffer_addstring+0x20>
jmp    114f <buffer_addstring+0x3f>
mov    %eax,%r14d
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.buffer = type { i32 }
define i32 @buffer_addstring(%struct.buffer* %0, i8* %1) {
%3 = alloca i32
%4 = alloca %struct.buffer*
%5 = alloca i8*
%6 = alloca i32
store %struct.buffer* %0, %struct.buffer** %4
store i8* %1, i8** %5
br label %7
7: ; preds = %20, %2
%8 = load i8*, i8** %5
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %7
%12 = load %struct.buffer*, %struct.buffer** %4
%13 = load i8*, i8** %5
%14 = load i8, i8* %13
%15 = call i32 @buffer_addchar(%struct.buffer* %12, i8 zeroext %14)
store i32 %15, i32* %6
%16 = icmp ne i32 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %11
%18 = load i32, i32* %6
store i32 %18, i32* %3
br label %24
19: ; preds = %11
br label %20
20: ; preds = %19
%21 = load i8*, i8** %5
%22 = getelementptr inbounds i8, i8* %21, i32 1
store i8* %22, i8** %5
br label %7
23: ; preds = %7
store i32 0, i32* %3
br label %24
24: ; preds = %23, %17
%25 = load i32, i32* %3
ret i32 %25
}

LLVM IR (-O2):
%struct.buffer = type { i32 }
define i32 @buffer_addstring(%struct.buffer* %0, i8* nocapture %1) {
%3 = load i8, i8* %1
%4 = icmp eq i8 %3, 0
br i1 %4, label %14, label %8
5: ; preds = %8
%6 = load i8, i8* %13
%7 = icmp eq i8 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %2, %5
%9 = phi i8 [ %6, %5 ], [ %3, %2 ]
%10 = phi i8* [ %13, %5 ], [ %1, %2 ]
%11 = tail call i32 @buffer_addchar(%struct.buffer* %0, i8 zeroext %9)
%12 = icmp eq i32 %11, 0
%13 = getelementptr inbounds i8, i8* %10, i64 1
br i1 %12, label %5, label %14
14: ; preds = %8, %5, %2
%15 = phi i32 [ 0, %2 ], [ 0, %5 ], [ %11, %8 ]
ret i32 %15
}