#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 fun(char *a, char *b) {
  char t, *p;
  for (p = a; p - a < strlen(b); p++)
    ;
  t = *p;
  strcpy(a, b);
  while (*a)
    a++;
  *a = t;
}


x86 assembly (clang, -O0):
<fun>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rax
mov    -0x8(%rbp),%rcx
sub    %rcx,%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x28(%rbp),%rax
movslq %ecx,%rcx
cmp    %rcx,%rax
jge    1178 <fun+0x58>
jmp    1167 <fun+0x47>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1138 <fun+0x18>
mov    -0x20(%rbp),%rax
mov    (%rax),%al
mov    %al,-0x11(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x8(%rbp),%rax
cmpb   $0x0,(%rax)
je     11ac <fun+0x8c>
mov    -0x8(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x8(%rbp)
jmp    118e <fun+0x6e>
mov    -0x11(%rbp),%cl
mov    -0x8(%rbp),%rax
mov    %cl,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<fun>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%r15
mov    $0xffffffffffffffff,%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %r14,%rdi
call   1040 <strlen@plt>
cltq
add    $0x1,%rbx
cmp    %rax,%rbx
jl     1140 <fun+0x20>
mov    (%r15,%rbx,1),%bl
mov    %r15,%rdi
mov    %r14,%rsi
call   1030 <strcpy@plt>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
cmpb   $0x0,(%r15)
lea    0x1(%r15),%r15
jne    1170 <fun+0x50>
mov    %bl,-0x1(%r15)
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @fun(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i8
%6 = alloca i8*
store i8* %0, i8** %3
store i8* %1, i8** %4
%7 = load i8*, i8** %3
store i8* %7, i8** %6
br label %8
8: ; preds = %19, %2
%9 = load i8*, i8** %6
%10 = load i8*, i8** %3
%11 = ptrtoint i8* %9 to i64
%12 = ptrtoint i8* %10 to i64
%13 = sub i64 %11, %12
%14 = load i8*, i8** %4
%15 = call i32 @strlen(i8* %14)
%16 = sext i32 %15 to i64
%17 = icmp slt i64 %13, %16
br i1 %17, label %18, label %22
18: ; preds = %8
br label %19
19: ; preds = %18
%20 = load i8*, i8** %6
%21 = getelementptr inbounds i8, i8* %20, i32 1
store i8* %21, i8** %6
br label %8
22: ; preds = %8
%23 = load i8*, i8** %6
%24 = load i8, i8* %23
store i8 %24, i8* %5
%25 = load i8*, i8** %3
%26 = load i8*, i8** %4
%27 = call i32 @strcpy(i8* %25, i8* %26)
br label %28
28: ; preds = %32, %22
%29 = load i8*, i8** %3
%30 = load i8, i8* %29
%31 = icmp ne i8 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %28
%33 = load i8*, i8** %3
%34 = getelementptr inbounds i8, i8* %33, i32 1
store i8* %34, i8** %3
br label %28
35: ; preds = %28
%36 = load i8, i8* %5
%37 = load i8*, i8** %3
store i8 %36, i8* %37
ret void
}

LLVM IR (-O2):
define void @fun(i8* %0, i8* %1) {
%3 = ptrtoint i8* %0 to i64
br label %4
4: ; preds = %4, %2
%5 = phi i8* [ %0, %2 ], [ %11, %4 ]
%6 = ptrtoint i8* %5 to i64
%7 = sub i64 %6, %3
%8 = tail call i32 @strlen(i8* %1)
%9 = sext i32 %8 to i64
%10 = icmp slt i64 %7, %9
%11 = getelementptr inbounds i8, i8* %5, i64 1
br i1 %10, label %4, label %12
12: ; preds = %4
%13 = load i8, i8* %5
%14 = tail call i32 @strcpy(i8* %0, i8* %1)
br label %15
15: ; preds = %15, %12
%16 = phi i8* [ %0, %12 ], [ %19, %15 ]
%17 = load i8, i8* %16
%18 = icmp eq i8 %17, 0
%19 = getelementptr inbounds i8, i8* %16, i64 1
br i1 %18, label %20, label %15
20: ; preds = %15
store i8 %13, i8* %16
ret void
}