#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 */
scalar_t__ b_put(char);
int /*<<< orphan*/ *direct_scan(char *);
int /*<<< orphan*/ halt(char *, int /*<<< orphan*/ *);
char *scan_and_copy(char *str) {
  register char *tmp = str;
  if (direct_scan(str) == NULL)
    return (NULL);
  do
    if (b_put(*tmp))
      halt("Scan buffer overflow.", NULL);
  while (*tmp++);
  return (str);
}


x86 assembly (clang, -O0):
<scan_and_copy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <direct_scan@plt>
cmp    $0x0,%rax
jne    1164 <scan_and_copy+0x34>
movq   $0x0,-0x8(%rbp)
jmp    11b4 <scan_and_copy+0x84>
jmp    1169 <scan_and_copy+0x39>
mov    -0x18(%rbp),%rax
movsbl (%rax),%edi
call   1030 <b_put@plt>
cmp    $0x0,%rax
je     118f <scan_and_copy+0x5f>
lea    0xe7a(%rip),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1040 <halt@plt>
jmp    1194 <scan_and_copy+0x64>
mov    -0x18(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x18(%rbp)
cmpb   $0x0,(%rax)
jne    1169 <scan_and_copy+0x39>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<scan_and_copy>:
push   %r15
push   %r14
push   %rbx
mov    %rdi,%r14
call   1050 <direct_scan@plt>
test   %rax,%rax
je     1172 <scan_and_copy+0x42>
lea    0xeb7(%rip),%r15
mov    %r14,%rbx
jmp    1159 <scan_and_copy+0x29>
xchg   %ax,%ax
cmpb   $0x0,(%rbx)
lea    0x1(%rbx),%rbx
je     1175 <scan_and_copy+0x45>
movsbl (%rbx),%edi
call   1030 <b_put@plt>
test   %rax,%rax
je     1150 <scan_and_copy+0x20>
mov    %r15,%rdi
xor    %esi,%esi
call   1040 <halt@plt>
jmp    1150 <scan_and_copy+0x20>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [22 x i8] c"Scan buffer overflow.\00"
define i8* @scan_and_copy(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
store i8* %0, i8** %3
%5 = load i8*, i8** %3
store i8* %5, i8** %4
%6 = load i8*, i8** %3
%7 = call i32* @direct_scan(i8* %6)
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* null, i8** %2
br label %26
10: ; preds = %1
br label %11
11: ; preds = %19, %10
%12 = load i8*, i8** %4
%13 = load i8, i8* %12
%14 = call i64 @b_put(i8 signext %13)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %18
16: ; preds = %11
%17 = call i32 @halt(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32* null)
br label %18
18: ; preds = %16, %11
br label %19
19: ; preds = %18
%20 = load i8*, i8** %4
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %4
%22 = load i8, i8* %20
%23 = icmp ne i8 %22, 0
br i1 %23, label %11, label %24
24: ; preds = %19
%25 = load i8*, i8** %3
store i8* %25, i8** %2
br label %26
26: ; preds = %24, %9
%27 = load i8*, i8** %2
ret i8* %27
}

LLVM IR (-O2):
@.str = [22 x i8] c"Scan buffer overflow.\00"
define i8* @scan_and_copy(i8* %0) {
%2 = tail call i32* @direct_scan(i8* %0)
%3 = icmp eq i32* %2, null
br i1 %3, label %15, label %4
4: ; preds = %1, %11
%5 = phi i8* [ %12, %11 ], [ %0, %1 ]
%6 = load i8, i8* %5
%7 = tail call i64 @b_put(i8 signext %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %4
%10 = tail call i32 @halt(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i32* null)
br label %11
11: ; preds = %4, %9
%12 = getelementptr inbounds i8, i8* %5, i64 1
%13 = load i8, i8* %5
%14 = icmp eq i8 %13, 0
br i1 %14, label %15, label %4
15: ; preds = %11, %1
%16 = phi i8* [ null, %1 ], [ %0, %11 ]
ret i8* %16
}