#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 */
typedef int /*<<< orphan*/ ret;

/* Variables and functions */
int /*<<< orphan*/ com_strcpy(char *, int, char *);
scalar_t__ memcmp(char *, char *, int);
int strlen(char *);
int spreadchar(char *code, char *msg, char *ret) {
  char *p;
  if (code == NULL || msg == NULL || ret == NULL)
    return 0;
  if (strlen(msg) <= strlen(code))
    return 0;
  if (memcmp(code, msg, strlen(code)) != 0)
    return 0;
  p = msg + strlen(code) + 1;
  if (p == NULL)
    return 0;
  com_strcpy(ret, sizeof(ret), p);
  return 1;
}


x86 assembly (clang, -O0):
<spreadchar>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1165 <spreadchar+0x35>
cmpq   $0x0,-0x18(%rbp)
je     1165 <spreadchar+0x35>
cmpq   $0x0,-0x20(%rbp)
jne    1171 <spreadchar+0x41>
movl   $0x0,-0x4(%rbp)
jmp    1232 <spreadchar+0x102>
mov    -0x18(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x2c(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x2c(%rbp),%eax
cmp    %ecx,%eax
jg     119f <spreadchar+0x6f>
movl   $0x0,-0x4(%rbp)
jmp    1232 <spreadchar+0x102>
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    -0x40(%rbp),%rdi
mov    -0x38(%rbp),%rsi
mov    %eax,%edx
call   1040 <memcmp@plt>
cmp    $0x0,%rax
je     11dd <spreadchar+0xad>
movl   $0x0,-0x4(%rbp)
jmp    1232 <spreadchar+0x102>
mov    -0x18(%rbp),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x48(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1219 <spreadchar+0xe9>
movl   $0x0,-0x4(%rbp)
jmp    1232 <spreadchar+0x102>
mov    -0x20(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    $0x8,%esi
call   1050 <com_strcpy@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<spreadchar>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
xor    %r15d,%r15d
test   %rdi,%rdi
je     11aa <spreadchar+0x7a>
mov    %rsi,%rbx
test   %rsi,%rsi
je     11aa <spreadchar+0x7a>
mov    %rdx,%r14
test   %rdx,%rdx
je     11aa <spreadchar+0x7a>
mov    %rdi,%rbp
mov    %rbx,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %rbp,%rdi
call   1030 <strlen@plt>
cmp    %eax,%r12d
jle    11aa <spreadchar+0x7a>
mov    %rbp,%rdi
call   1030 <strlen@plt>
mov    %rbp,%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <memcmp@plt>
test   %rax,%rax
jne    11aa <spreadchar+0x7a>
mov    %rbp,%rdi
call   1030 <strlen@plt>
cltq
lea    (%rbx,%rax,1),%rdx
add    $0x1,%rdx
mov    %r14,%rdi
mov    $0x8,%esi
call   1050 <com_strcpy@plt>
mov    $0x1,%r15d
mov    %r15d,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define i32 @spreadchar(i8* %0, i8* %1, i8* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i8*
store i8* %0, i8** %5
store i8* %1, i8** %6
store i8* %2, i8** %7
%9 = load i8*, i8** %5
%10 = icmp eq i8* %9, null
br i1 %10, label %17, label %11
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = icmp eq i8* %12, null
br i1 %13, label %17, label %14
14: ; preds = %11
%15 = load i8*, i8** %7
%16 = icmp eq i8* %15, null
br i1 %16, label %17, label %18
17: ; preds = %14, %11, %3
store i32 0, i32* %4
br label %47
18: ; preds = %14
%19 = load i8*, i8** %6
%20 = call i32 @strlen(i8* %19)
%21 = load i8*, i8** %5
%22 = call i32 @strlen(i8* %21)
%23 = icmp sle i32 %20, %22
br i1 %23, label %24, label %25
24: ; preds = %18
store i32 0, i32* %4
br label %47
25: ; preds = %18
%26 = load i8*, i8** %5
%27 = load i8*, i8** %6
%28 = load i8*, i8** %5
%29 = call i32 @strlen(i8* %28)
%30 = call i64 @memcmp(i8* %26, i8* %27, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %25
store i32 0, i32* %4
br label %47
33: ; preds = %25
%34 = load i8*, i8** %6
%35 = load i8*, i8** %5
%36 = call i32 @strlen(i8* %35)
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
%39 = getelementptr inbounds i8, i8* %38, i64 1
store i8* %39, i8** %8
%40 = load i8*, i8** %8
%41 = icmp eq i8* %40, null
br i1 %41, label %42, label %43
42: ; preds = %33
store i32 0, i32* %4
br label %47
43: ; preds = %33
%44 = load i8*, i8** %7
%45 = load i8*, i8** %8
%46 = call i32 @com_strcpy(i8* %44, i32 8, i8* %45)
store i32 1, i32* %4
br label %47
47: ; preds = %43, %42, %32, %24, %17
%48 = load i32, i32* %4
ret i32 %48
}

LLVM IR (-O2):
define i32 @spreadchar(i8* %0, i8* %1, i8* %2) {
%4 = icmp eq i8* %0, null
%5 = icmp eq i8* %1, null
%6 = or i1 %4, %5
%7 = icmp eq i8* %2, null
%8 = or i1 %6, %7
br i1 %8, label %23, label %9
9: ; preds = %3
%10 = tail call i32 @strlen(i8* %1)
%11 = tail call i32 @strlen(i8* %0)
%12 = icmp sgt i32 %10, %11
br i1 %12, label %13, label %23
13: ; preds = %9
%14 = tail call i32 @strlen(i8* %0)
%15 = tail call i64 @memcmp(i8* %0, i8* %1, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %13
%18 = tail call i32 @strlen(i8* %0)
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds i8, i8* %1, i64 %19
%21 = getelementptr inbounds i8, i8* %20, i64 1
%22 = tail call i32 @com_strcpy(i8* %2, i32 8, i8* %21)
br label %23
23: ; preds = %13, %9, %3, %17
%24 = phi i32 [ 1, %17 ], [ 0, %3 ], [ 0, %9 ], [ 0, %13 ]
ret i32 %24
}