#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 */
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
void do_work_on_buffer_left(char *field_contents, char character,
                            int position) {
  char tmp[1024];
  char *tmp_ptr = tmp;
  char *field_contents_ptr = field_contents;
  if (position > strlen(field_contents)) {
    return;
  }
  while (position) {
    *tmp_ptr++ = *field_contents_ptr++;
    position--;
  }
  *tmp_ptr++ = character;
  while (*field_contents_ptr)
    *tmp_ptr++ = *field_contents_ptr++;
  *tmp_ptr = '\0';
  strcpy(field_contents, tmp);
}


x86 assembly (clang, -O0):
<do_work_on_buffer_left>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x418(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x420(%rbp)
mov    -0x10(%rbp),%eax
mov    %eax,-0x424(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x424(%rbp),%eax
cmp    %ecx,%eax
jle    1178 <do_work_on_buffer_left+0x58>
jmp    123a <do_work_on_buffer_left+0x11a>
jmp    117d <do_work_on_buffer_left+0x5d>
cmpl   $0x0,-0x10(%rbp)
je     11c3 <do_work_on_buffer_left+0xa3>
mov    -0x420(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x420(%rbp)
mov    (%rax),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    117d <do_work_on_buffer_left+0x5d>
mov    -0x9(%rbp),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
mov    -0x420(%rbp),%rax
cmpb   $0x0,(%rax)
je     1220 <do_work_on_buffer_left+0x100>
mov    -0x420(%rbp),%rax
mov    %rax,%rcx
add    $0x1,%rcx
mov    %rcx,-0x420(%rbp)
mov    (%rax),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0x1,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
jmp    11dd <do_work_on_buffer_left+0xbd>
mov    -0x418(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    -0x410(%rbp),%rsi
call   1030 <strcpy@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_work_on_buffer_left>:
push   %rbp
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %edx,%ebp
mov    %esi,%r14d
mov    %rdi,%rbx
call   1040 <strlen@plt>
cmp    %ebp,%eax
jl     11af <do_work_on_buffer_left+0x7f>
test   %ebp,%ebp
je     1172 <do_work_on_buffer_left+0x42>
mov    %ebp,%edx
mov    %rsp,%rdi
mov    %rbx,%rsi
call   1050 <memcpy@plt>
add    $0xffffffff,%ebp
lea    (%rbx,%rbp,1),%rcx
add    $0x1,%rcx
lea    (%rsp,%rbp,1),%rax
add    $0x1,%rax
jmp    1178 <do_work_on_buffer_left+0x48>
mov    %rsp,%rax
mov    %rbx,%rcx
mov    %r14b,(%rax)
add    $0x1,%rax
mov    (%rcx),%dl
test   %dl,%dl
je     11a1 <do_work_on_buffer_left+0x71>
add    $0x1,%rcx
nopl   0x0(%rax)
mov    %dl,(%rax)
add    $0x1,%rax
movzbl (%rcx),%edx
add    $0x1,%rcx
test   %dl,%dl
jne    1190 <do_work_on_buffer_left+0x60>
movb   $0x0,(%rax)
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

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

LLVM IR (-O2):
define void @do_work_on_buffer_left(i8* %0, i8 signext %1, i32 %2) {
%4 = alloca [1024 x i8]
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%6 = getelementptr inbounds [1024 x i8], [1024 x i8]* %4, i64 0, i64 0
%7 = tail call i32 @strlen(i8* %0)
%8 = icmp slt i32 %7, %2
br i1 %8, label %35, label %9
9: ; preds = %3
%10 = icmp eq i32 %2, 0
br i1 %10, label %18, label %11
11: ; preds = %9
%12 = zext i32 %2 to i64
%13 = add i32 %2, -1
%14 = zext i32 %13 to i64
%15 = add nuw nsw i64 %14, 1
%16 = getelementptr i8, i8* %0, i64 %15
%17 = getelementptr [1024 x i8], [1024 x i8]* %4, i64 0, i64 %15
br label %18
18: ; preds = %11, %9
%19 = phi i8* [ %6, %9 ], [ %17, %11 ]
%20 = phi i8* [ %0, %9 ], [ %16, %11 ]
store i8 %1, i8* %19
%21 = getelementptr inbounds i8, i8* %19, i64 1
%22 = load i8, i8* %20
%23 = icmp eq i8 %22, 0
br i1 %23, label %32, label %24
24: ; preds = %18, %24
%25 = phi i8 [ %30, %24 ], [ %22, %18 ]
%26 = phi i8* [ %29, %24 ], [ %21, %18 ]
%27 = phi i8* [ %28, %24 ], [ %20, %18 ]
%28 = getelementptr inbounds i8, i8* %27, i64 1
store i8 %25, i8* %26
%29 = getelementptr inbounds i8, i8* %26, i64 1
%30 = load i8, i8* %28
%31 = icmp eq i8 %30, 0
br i1 %31, label %32, label %24
32: ; preds = %24, %18
%33 = phi i8* [ %21, %18 ], [ %29, %24 ]
store i8 0, i8* %33
%34 = call i32 @strcpy(i8* %0, i8* %6)
br label %35
35: ; preds = %3, %32
ret void
}