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

/* Variables and functions */
int get_char(struct file_state *, char const *);
char *next_char(struct file_state *, char const *, int);
void char_strcpy(char *dest, struct file_state *file, const char *src,
                 const char *end) {
  while (src < end) {
    int c;
    c = get_char(file, src);
    src = next_char(file, src, 1);
    *dest++ = c;
  }
}


x86 assembly (clang, -O0):
<char_strcpy>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
cmp    -0x20(%rbp),%rax
jae    1187 <char_strcpy+0x67>
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <get_char@plt>
mov    %eax,-0x24(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    $0x1,%edx
call   1030 <next_char@plt>
mov    %rax,-0x18(%rbp)
mov    -0x24(%rbp),%eax
mov    %al,%cl
mov    -0x8(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x8(%rbp)
mov    %cl,(%rax)
jmp    1138 <char_strcpy+0x18>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<char_strcpy>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
cmp    %rcx,%rdx
jae    116c <char_strcpy+0x4c>
mov    %rcx,%r14
mov    %rdx,%r12
mov    %rsi,%r15
mov    %rdi,%rbx
nopl   0x0(%rax)
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <get_char@plt>
mov    %eax,%ebp
mov    %r15,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <next_char@plt>
mov    %rax,%r12
mov    %bpl,(%rbx)
add    $0x1,%rbx
cmp    %r14,%rax
jb     1140 <char_strcpy+0x20>
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.file_state = type { i32 }
define void @char_strcpy(i8* nocapture writeonly %0, %struct.file_state* %1, i8* %2, i8* readnone %3) {
%5 = icmp ult i8* %2, %3
br i1 %5, label %6, label %14
6: ; preds = %4, %6
%7 = phi i8* [ %12, %6 ], [ %0, %4 ]
%8 = phi i8* [ %10, %6 ], [ %2, %4 ]
%9 = tail call i32 @get_char(%struct.file_state* %1, i8* %8)
%10 = tail call i8* @next_char(%struct.file_state* %1, i8* %8, i32 1)
%11 = trunc i32 %9 to i8
%12 = getelementptr inbounds i8, i8* %7, i64 1
store i8 %11, i8* %7
%13 = icmp ult i8* %10, %3
br i1 %13, label %6, label %14
14: ; preds = %6, %4
ret void
}