#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_right(char *field_contents, char character,
                             int position) {
  char tmp[1024];
  char *tmp_ptr;
  char *field_contents_ptr;
  int field_contents_len;
  field_contents_len = strlen(field_contents);
  if (position > field_contents_len) {
    return;
  }
  tmp_ptr = tmp + field_contents_len + 1;
  field_contents_ptr = field_contents + field_contents_len;
  *tmp_ptr-- = *field_contents_ptr--;
  while (position) {
    *tmp_ptr-- = *field_contents_ptr--;
    position--;
  }
  *tmp_ptr-- = character;
  while (field_contents_ptr != field_contents - 1)
    *tmp_ptr-- = *field_contents_ptr--;
  strcpy(field_contents, tmp);
}


x86 assembly (clang, -O0):
<do_work_on_buffer_right>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %sil,%al
mov    %rdi,-0x8(%rbp)
mov    %al,-0x9(%rbp)
mov    %edx,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x424(%rbp)
mov    -0x10(%rbp),%eax
cmp    -0x424(%rbp),%eax
jle    115b <do_work_on_buffer_right+0x3b>
jmp    1275 <do_work_on_buffer_right+0x155>
lea    -0x410(%rbp),%rax
movslq -0x424(%rbp),%rcx
add    %rcx,%rax
add    $0x1,%rax
mov    %rax,-0x418(%rbp)
mov    -0x8(%rbp),%rax
movslq -0x424(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x420(%rbp)
mov    -0x420(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x420(%rbp)
mov    (%rax),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
cmpl   $0x0,-0x10(%rbp)
je     1200 <do_work_on_buffer_right+0xe0>
mov    -0x420(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x420(%rbp)
mov    (%rax),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    11ba <do_work_on_buffer_right+0x9a>
mov    -0x9(%rbp),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
mov    -0x420(%rbp),%rax
mov    -0x8(%rbp),%rcx
add    $0xffffffffffffffff,%rcx
cmp    %rcx,%rax
je     1265 <do_work_on_buffer_right+0x145>
mov    -0x420(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x420(%rbp)
mov    (%rax),%cl
mov    -0x418(%rbp),%rax
mov    %rax,%rdx
add    $0xffffffffffffffff,%rdx
mov    %rdx,-0x418(%rbp)
mov    %cl,(%rax)
jmp    121a <do_work_on_buffer_right+0xfa>
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_right>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x400,%rsp
mov    %edx,%ebx
mov    %esi,%r14d
mov    %rdi,%r15
call   1040 <strlen@plt>
cmp    %ebx,%eax
jl     11b8 <do_work_on_buffer_right+0x88>
movslq %eax,%rbp
mov    (%r15,%rbp,1),%al
mov    %al,0x1(%rsp,%rbp,1)
lea    -0x1(%rbp),%r12
test   %ebx,%ebx
je     1188 <do_work_on_buffer_right+0x58>
lea    -0x1(%rbx),%eax
sub    %rax,%rbp
lea    (%rsp,%rbp,1),%rdi
sub    %rax,%r12
lea    (%r15,%r12,1),%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
lea    (%rsp,%r12,1),%rdi
add    $0xfffffffffffffffe,%rbp
mov    %rbp,%r12
jmp    118c <do_work_on_buffer_right+0x5c>
lea    (%rsp,%rbp,1),%rdi
mov    %r14b,(%rdi)
cmp    $0xffffffffffffffff,%r12
je     11ad <do_work_on_buffer_right+0x7d>
mov    %r12,%rax
not    %rax
add    %rax,%rdi
add    $0x1,%r12
mov    %r15,%rsi
mov    %r12,%rdx
call   1050 <memcpy@plt>
mov    %rsp,%rsi
mov    %r15,%rdi
call   1030 <strcpy@plt>
add    $0x400,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @do_work_on_buffer_right(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*
%10 = alloca i32
store i8* %0, i8** %4
store i8 %1, i8* %5
store i32 %2, i32* %6
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* %11)
store i32 %12, i32* %10
%13 = load i32, i32* %6
%14 = load i32, i32* %10
%15 = icmp sgt i32 %13, %14
br i1 %15, label %16, label %17
16: ; preds = %3
br label %62
17: ; preds = %3
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* %10
%20 = sext i32 %19 to i64
%21 = getelementptr inbounds i8, i8* %18, i64 %20
%22 = getelementptr inbounds i8, i8* %21, i64 1
store i8* %22, i8** %8
%23 = load i8*, i8** %4
%24 = load i32, i32* %10
%25 = sext i32 %24 to i64
%26 = getelementptr inbounds i8, i8* %23, i64 %25
store i8* %26, i8** %9
%27 = load i8*, i8** %9
%28 = getelementptr inbounds i8, i8* %27, i32 -1
store i8* %28, i8** %9
%29 = load i8, i8* %27
%30 = load i8*, i8** %8
%31 = getelementptr inbounds i8, i8* %30, i32 -1
store i8* %31, i8** %8
store i8 %29, i8* %30
br label %32
32: ; preds = %35, %17
%33 = load i32, i32* %6
%34 = icmp ne i32 %33, 0
br i1 %34, label %35, label %43
35: ; preds = %32
%36 = load i8*, i8** %9
%37 = getelementptr inbounds i8, i8* %36, i32 -1
store i8* %37, i8** %9
%38 = load i8, i8* %36
%39 = load i8*, i8** %8
%40 = getelementptr inbounds i8, i8* %39, i32 -1
store i8* %40, i8** %8
store i8 %38, i8* %39
%41 = load i32, i32* %6
%42 = add nsw i32 %41, -1
store i32 %42, i32* %6
br label %32
43: ; preds = %32
%44 = load i8, i8* %5
%45 = load i8*, i8** %8
%46 = getelementptr inbounds i8, i8* %45, i32 -1
store i8* %46, i8** %8
store i8 %44, i8* %45
br label %47
47: ; preds = %52, %43
%48 = load i8*, i8** %9
%49 = load i8*, i8** %4
%50 = getelementptr inbounds i8, i8* %49, i64 -1
%51 = icmp ne i8* %48, %50
br i1 %51, label %52, label %58
52: ; preds = %47
%53 = load i8*, i8** %9
%54 = getelementptr inbounds i8, i8* %53, i32 -1
store i8* %54, i8** %9
%55 = load i8, i8* %53
%56 = load i8*, i8** %8
%57 = getelementptr inbounds i8, i8* %56, i32 -1
store i8* %57, i8** %8
store i8 %55, i8* %56
br label %47
58: ; preds = %47
%59 = load i8*, i8** %4
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%61 = call i32 @strcpy(i8* %59, i8* %60)
br label %62
62: ; preds = %58, %16
ret void
}

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