#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 */
typedef int /*<<< orphan*/ newstring;
typedef int /*<<< orphan*/ a;

/* Variables and functions */
int /*<<< orphan*/ snprintf(char *, int, char *, ...);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *iWar_Mask_Replace(char *number, char *replace) {
  int i = 0;
  char newstring[30] = {0};
  char modstring[30] = {0};
  char *retbuf = NULL;
  char a[2] = {0};
  snprintf(newstring, sizeof(newstring), "%s", number);
  for (i = 0; i < strlen(newstring); i++) {
    if (newstring[i] == 'X') {
      strcat(modstring, replace);
    } else {
      snprintf(a, sizeof(a), "%c", newstring[i]);
      strcat(modstring, a);
    }
  }
  retbuf = modstring;
  return (retbuf);
}


x86 assembly (clang, -O0):
<iWar_Mask_Replace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
lea    -0x40(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1050 <memset@plt>
lea    -0x60(%rbp),%rdi
xor    %esi,%esi
mov    $0x1e,%edx
call   1050 <memset@plt>
movq   $0x0,-0x68(%rbp)
lea    -0x6a(%rbp),%rdi
xor    %esi,%esi
mov    $0x2,%edx
call   1050 <memset@plt>
lea    -0x40(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x1e,%esi
lea    0xe5d(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
mov    %eax,-0x70(%rbp)
lea    -0x40(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x70(%rbp),%eax
cmp    %ecx,%eax
jge    1231 <iWar_Mask_Replace+0xf1>
movslq -0x14(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%eax
cmp    $0x58,%eax
jne    11f1 <iWar_Mask_Replace+0xb1>
lea    -0x60(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strcat@plt>
jmp    121e <iWar_Mask_Replace+0xde>
lea    -0x6a(%rbp),%rdi
movslq -0x14(%rbp),%rax
movsbl -0x40(%rbp,%rax,1),%ecx
mov    $0x2,%esi
lea    0xdf9(%rip),%rdx
mov    $0x0,%al
call   1040 <snprintf@plt>
lea    -0x60(%rbp),%rdi
lea    -0x6a(%rbp),%rsi
call   1060 <strcat@plt>
jmp    1223 <iWar_Mask_Replace+0xe3>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11b1 <iWar_Mask_Replace+0x71>
lea    -0x60(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x68(%rbp),%rax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<iWar_Mask_Replace>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x58,%rsp
mov    %rsi,%r14
mov    %rdi,%rcx
xorps  %xmm0,%xmm0
movups %xmm0,0x1e(%rsp)
movaps %xmm0,0x10(%rsp)
movups %xmm0,0x3e(%rsp)
movaps %xmm0,0x30(%rsp)
movw   $0x0,0xe(%rsp)
lea    0xe97(%rip),%rdx
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x1e,%esi
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11f2 <iWar_Mask_Replace+0xc2>
lea    0x30(%rsp),%r15
lea    0x10(%rsp),%r13
lea    0xe69(%rip),%r12
lea    0xe(%rsp),%rbx
xor    %ebp,%ebp
jmp    11e0 <iWar_Mask_Replace+0xb0>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    $0x2,%esi
mov    %r12,%rdx
xor    %eax,%eax
call   1040 <snprintf@plt>
mov    %r15,%rdi
mov    %rbx,%rsi
call   1050 <strcat@plt>
add    $0x1,%rbp
mov    %r13,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbp
jge    11f2 <iWar_Mask_Replace+0xc2>
movsbl 0x10(%rsp,%rbp,1),%ecx
cmp    $0x58,%ecx
jne    11b0 <iWar_Mask_Replace+0x80>
mov    %r15,%rdi
mov    %r14,%rsi
jmp    11c8 <iWar_Mask_Replace+0x98>
lea    0x30(%rsp),%rax
add    $0x58,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%c\00"
define i8* @iWar_Mask_Replace(i8* %0, i8* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca [30 x i8]
%7 = alloca [30 x i8]
%8 = alloca i8*
%9 = alloca [2 x i8]
store i8* %0, i8** %3
store i8* %1, i8** %4
store i32 0, i32* %5
%10 = bitcast [30 x i8]* %6 to i8*
%11 = bitcast [30 x i8]* %7 to i8*
store i8* null, i8** %8
%12 = bitcast [2 x i8]* %9 to i8*
%13 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%14 = load i8*, i8** %3
%15 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %13, i32 30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %5
br label %16
16: ; preds = %44, %2
%17 = load i32, i32* %5
%18 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%19 = call i32 @strlen(i8* %18)
%20 = icmp slt i32 %17, %19
br i1 %20, label %21, label %47
21: ; preds = %16
%22 = load i32, i32* %5
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 %23
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp eq i32 %26, 88
br i1 %27, label %28, label %32
28: ; preds = %21
%29 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%30 = load i8*, i8** %4
%31 = call i32 @strcat(i8* %29, i8* %30)
br label %43
32: ; preds = %21
%33 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%34 = load i32, i32* %5
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 %35
%37 = load i8, i8* %36
%38 = sext i8 %37 to i32
%39 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %33, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %38)
%40 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
%41 = getelementptr inbounds [2 x i8], [2 x i8]* %9, i64 0, i64 0
%42 = call i32 @strcat(i8* %40, i8* %41)
br label %43
43: ; preds = %32, %28
br label %44
44: ; preds = %43
%45 = load i32, i32* %5
%46 = add nsw i32 %45, 1
store i32 %46, i32* %5
br label %16
47: ; preds = %16
%48 = getelementptr inbounds [30 x i8], [30 x i8]* %7, i64 0, i64 0
store i8* %48, i8** %8
%49 = load i8*, i8** %8
ret i8* %49
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@.str.1 = [3 x i8] c"%c\00"
define i8* @iWar_Mask_Replace(i8* %0, i8* %1) {
%3 = alloca [30 x i8]
%4 = alloca [30 x i8]
%5 = alloca i16
%6 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%7 = getelementptr inbounds [30 x i8], [30 x i8]* %4, i64 0, i64 0
%8 = bitcast i16* %5 to i8*
store i16 0, i16* %5
%9 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %6, i32 30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %0)
%10 = call i32 @strlen(i8* %6)
%11 = icmp sgt i32 %10, 0
br i1 %11, label %12, label %28
12: ; preds = %2, %23
%13 = phi i64 [ %24, %23 ], [ 0, %2 ]
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 88
br i1 %16, label %17, label %19
17: ; preds = %12
%18 = call i32 @strcat(i8* %7, i8* %1)
br label %23
19: ; preds = %12
%20 = sext i8 %15 to i32
%21 = call i32 (i8*, i32, i8*, ...) @snprintf(i8* %8, i32 2, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i32 %20)
%22 = call i32 @strcat(i8* %7, i8* %8)
br label %23
23: ; preds = %17, %19
%24 = add nuw nsw i64 %13, 1
%25 = call i32 @strlen(i8* %6)
%26 = sext i32 %25 to i64
%27 = icmp slt i64 %24, %26
br i1 %27, label %12, label %28
28: ; preds = %23, %2
ret i8* %7
}