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

/* Variables and functions */
scalar_t__ dm_append(struct dmbuf *, char *, unsigned int);
unsigned int strtoul(char const *, char **, int);
int dm_component(struct dmbuf *d, const char *text, const char **out) {
  char *next;
  unsigned int len = strtoul(text, &next, 10);
  if (next == text)
    return -1;
  if (dm_append(d, next, len) < 0)
    return -1;
  if (out)
    *out = next + len;
  return 0;
}


x86 assembly (clang, -O0):
<dm_component>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jne    1163 <dm_component+0x43>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <dm_component+0x8c>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
mov    -0x2c(%rbp),%edx
call   1040 <dm_append@plt>
cmp    $0x0,%rax
jge    1189 <dm_component+0x69>
movl   $0xffffffff,-0x4(%rbp)
jmp    11ac <dm_component+0x8c>
cmpq   $0x0,-0x20(%rbp)
je     11a5 <dm_component+0x85>
mov    -0x28(%rbp),%rcx
mov    -0x2c(%rbp),%eax
add    %rax,%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dm_component>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%rbp
mov    %rdi,%r12
mov    %rsp,%rsi
mov    %rbp,%rdi
mov    $0xa,%edx
call   1030 <strtoul@plt>
mov    (%rsp),%rbx
mov    $0xffffffff,%r13d
cmp    %rbp,%rbx
je     1179 <dm_component+0x59>
mov    %eax,%r15d
mov    %r12,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <dm_append@plt>
test   %rax,%rax
js     1179 <dm_component+0x59>
xor    %r13d,%r13d
test   %r14,%r14
je     1179 <dm_component+0x59>
mov    %r15d,%eax
add    %rax,%rbx
mov    %rbx,(%r14)
mov    %r13d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.dmbuf = type { i32 }
define i32 @dm_component(%struct.dmbuf* %0, i8* %1, i8** %2) {
%4 = alloca i32
%5 = alloca %struct.dmbuf*
%6 = alloca i8*
%7 = alloca i8**
%8 = alloca i8*
%9 = alloca i32
store %struct.dmbuf* %0, %struct.dmbuf** %5
store i8* %1, i8** %6
store i8** %2, i8*** %7
%10 = load i8*, i8** %6
%11 = call i32 @strtoul(i8* %10, i8** %8, i32 10)
store i32 %11, i32* %9
%12 = load i8*, i8** %8
%13 = load i8*, i8** %6
%14 = icmp eq i8* %12, %13
br i1 %14, label %15, label %16
15: ; preds = %3
store i32 -1, i32* %4
br label %33
16: ; preds = %3
%17 = load %struct.dmbuf*, %struct.dmbuf** %5
%18 = load i8*, i8** %8
%19 = load i32, i32* %9
%20 = call i64 @dm_append(%struct.dmbuf* %17, i8* %18, i32 %19)
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %16
store i32 -1, i32* %4
br label %33
23: ; preds = %16
%24 = load i8**, i8*** %7
%25 = icmp ne i8** %24, null
br i1 %25, label %26, label %32
26: ; preds = %23
%27 = load i8*, i8** %8
%28 = load i32, i32* %9
%29 = zext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
%31 = load i8**, i8*** %7
store i8* %30, i8** %31
br label %32
32: ; preds = %26, %23
store i32 0, i32* %4
br label %33
33: ; preds = %32, %22, %15
%34 = load i32, i32* %4
ret i32 %34
}

LLVM IR (-O2):
%struct.dmbuf = type { i32 }
define i32 @dm_component(%struct.dmbuf* %0, i8* %1, i8** writeonly %2) {
%4 = alloca i8*
%5 = bitcast i8** %4 to i8*
%6 = call i32 @strtoul(i8* %1, i8** %4, i32 10)
%7 = load i8*, i8** %4
%8 = icmp eq i8* %7, %1
br i1 %8, label %17, label %9
9: ; preds = %3
%10 = tail call i64 @dm_append(%struct.dmbuf* %0, i8* %7, i32 %6)
%11 = icmp slt i64 %10, 0
br i1 %11, label %17, label %12
12: ; preds = %9
%13 = icmp eq i8** %2, null
br i1 %13, label %17, label %14
14: ; preds = %12
%15 = zext i32 %6 to i64
%16 = getelementptr inbounds i8, i8* %7, i64 %15
store i8* %16, i8** %2
br label %17
17: ; preds = %12, %14, %9, %3
%18 = phi i32 [ -1, %3 ], [ -1, %9 ], [ 0, %14 ], [ 0, %12 ]
ret i32 %18
}