#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 */
char *memchr(char const *, char, int);
int /*<<< orphan*/ memcpy(char *, char const *, int);
int /*<<< orphan*/ printa(char *, int);
int strlen(char const *);
int main() {
  const char src[256] = "mao%40mao.it";
  char substitute[] = "@";
  char dest[256];
  char *ret;
  int len;
  int diff;
  len = strlen(src);
  ret = memchr(src, '%', len);
  diff = ret - src;
  memcpy(dest, src, diff);
  printa(dest, diff);
  memcpy(dest + diff, substitute, 1);
  printa(dest, diff + 1);
  memcpy(dest + diff + 1, ret + 3, len - diff - 3);
  printa(dest, len - 3 + 1);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    0xea0(%rip),%rsi
mov    $0x100,%edx
call   1050 <memcpy@plt>
mov    0xf8f(%rip),%ax
mov    %ax,-0x112(%rbp)
lea    -0x110(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,-0x22c(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x22c(%rbp),%edx
mov    $0x25,%esi
call   1040 <memchr@plt>
mov    %rax,-0x228(%rbp)
mov    -0x228(%rbp),%rax
lea    -0x110(%rbp),%rcx
sub    %rcx,%rax
mov    %eax,-0x230(%rbp)
lea    -0x220(%rbp),%rdi
lea    -0x110(%rbp),%rsi
mov    -0x230(%rbp),%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
mov    -0x230(%rbp),%esi
call   1060 <printa@plt>
lea    -0x220(%rbp),%rdi
movslq -0x230(%rbp),%rax
add    %rax,%rdi
lea    -0x112(%rbp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
mov    -0x230(%rbp),%esi
add    $0x1,%esi
call   1060 <printa@plt>
lea    -0x220(%rbp),%rdi
movslq -0x230(%rbp),%rax
add    %rax,%rdi
add    $0x1,%rdi
mov    -0x228(%rbp),%rsi
add    $0x3,%rsi
mov    -0x22c(%rbp),%edx
sub    -0x230(%rbp),%edx
sub    $0x3,%edx
call   1050 <memcpy@plt>
lea    -0x220(%rbp),%rdi
mov    -0x22c(%rbp),%esi
sub    $0x3,%esi
add    $0x1,%esi
call   1060 <printa@plt>
xor    %eax,%eax
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x210,%rsp
lea    0xeaa(%rip),%rsi
lea    0x110(%rsp),%r15
mov    $0x100,%edx
mov    %r15,%rdi
call   1050 <memcpy@plt>
movw   $0x40,0xe(%rsp)
mov    %r15,%rdi
call   1030 <strlen@plt>
mov    %eax,%r12d
mov    %r15,%rdi
mov    $0x25,%esi
mov    %eax,%edx
call   1040 <memchr@plt>
mov    %rax,%rbp
mov    %rax,%rbx
sub    %r15,%rbx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    %r15,%rsi
mov    %ebx,%edx
call   1050 <memcpy@plt>
mov    %r14,%rdi
mov    %ebx,%esi
call   1060 <printa@plt>
movslq %ebx,%rbx
lea    (%rsp,%rbx,1),%rdi
add    $0x10,%rdi
lea    0xe(%rsp),%rsi
mov    $0x1,%edx
call   1050 <memcpy@plt>
lea    0x1(%rbx),%esi
mov    %r14,%rdi
call   1060 <printa@plt>
lea    (%rsp,%rbx,1),%rdi
add    $0x11,%rdi
add    $0x3,%rbp
mov    %r12d,%edx
sub    %ebx,%edx
add    $0xfffffffd,%edx
mov    %rbp,%rsi
call   1050 <memcpy@plt>
add    $0xfffffffe,%r12d
mov    %r14,%rdi
mov    %r12d,%esi
call   1060 <printa@plt>
xor    %eax,%eax
add    $0x210,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@__const.main.src = [256 x i8] c"mao%40mao.it\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
@__const.main.substitute = [2 x i8] c"@\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca [2 x i8]
%4 = alloca [256 x i8]
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
%8 = bitcast [256 x i8]* %2 to i8*
%9 = bitcast [2 x i8]* %3 to i8*
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
store i32 %11, i32* %6
%12 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%13 = load i32, i32* %6
%14 = call i8* @memchr(i8* %12, i8 signext 37, i32 %13)
store i8* %14, i8** %5
%15 = load i8*, i8** %5
%16 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%17 = ptrtoint i8* %15 to i64
%18 = ptrtoint i8* %16 to i64
%19 = sub i64 %17, %18
%20 = trunc i64 %19 to i32
store i32 %20, i32* %7
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%23 = load i32, i32* %7
%24 = call i32 @memcpy(i8* %21, i8* %22, i32 %23)
%25 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%26 = load i32, i32* %7
%27 = call i32 @printa(i8* %25, i32 %26)
%28 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%29 = load i32, i32* %7
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %28, i64 %30
%32 = getelementptr inbounds [2 x i8], [2 x i8]* %3, i64 0, i64 0
%33 = call i32 @memcpy(i8* %31, i8* %32, i32 1)
%34 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 1
%37 = call i32 @printa(i8* %34, i32 %36)
%38 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8, i8* %38, i64 %40
%42 = getelementptr inbounds i8, i8* %41, i64 1
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 3
%45 = load i32, i32* %6
%46 = load i32, i32* %7
%47 = sub nsw i32 %45, %46
%48 = sub nsw i32 %47, 3
%49 = call i32 @memcpy(i8* %42, i8* %44, i32 %48)
%50 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%51 = load i32, i32* %6
%52 = sub nsw i32 %51, 3
%53 = add nsw i32 %52, 1
%54 = call i32 @printa(i8* %50, i32 %53)
ret i32 0
}

LLVM IR (-O2):
@__const.main.src = [256 x i8] c"mao%40mao.it\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00"
define i32 @main() {
%1 = alloca [256 x i8]
%2 = alloca i16
%3 = alloca [256 x i8]
%4 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%5 = bitcast i16* %2 to i8*
store i16 64, i16* %2
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = call i32 @strlen(i8* %4)
%8 = call i8* @memchr(i8* %4, i8 signext 37, i32 %7)
%9 = ptrtoint i8* %8 to i64
%10 = ptrtoint [256 x i8]* %1 to i64
%11 = sub i64 %9, %10
%12 = trunc i64 %11 to i32
%13 = call i32 @memcpy(i8* %6, i8* %4, i32 %12)
%14 = call i32 @printa(i8* %6, i32 %12)
%15 = shl i64 %11, 32
%16 = ashr exact i64 %15, 32
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 %16
%18 = call i32 @memcpy(i8* %17, i8* %5, i32 1)
%19 = add nsw i32 %12, 1
%20 = call i32 @printa(i8* %6, i32 %19)
%21 = getelementptr inbounds i8, i8* %17, i64 1
%22 = getelementptr inbounds i8, i8* %8, i64 3
%23 = add i32 %7, -3
%24 = sub i32 %23, %12
%25 = call i32 @memcpy(i8* %21, i8* %22, i32 %24)
%26 = add nsw i32 %7, -2
%27 = call i32 @printa(i8* %6, i32 %26)
ret i32 0
}