#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 *expand_safe(char *, char, int /*<<< orphan*/, char);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ str2int(char *);
int main(int argc, char *args[]) {
  int i;
  if (argc != 5) {
    printf("Usage: %s A B C D\n");
    printf("-----------------\n");
    printf("Where A is string to be modified.\n");
    printf("      B is one character that is to be replaced.\n");
    printf("      C is number of times to be expanded.\n");
    printf("      D is what it is to be repaced with.\n");
    printf("-------------------------------------------------\n");
    printf("Example: %s 'Expand mex' x 5 X\n");
    return -1;
  }
  printf("Entered string: %s\n", args[1]);
  printf("Expanded string: %s\n",
         expand_safe(args[1], args[2][0], str2int(args[3]), args[4][0]));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11cc <main+0x9c>
lea    0xea9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf7a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xea0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xeb5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xed9(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xef7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf14(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    0xf39(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    123c <main+0x10c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xf37(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    (%rax),%al
mov    %al,-0x15(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <str2int@plt>
mov    -0x20(%rbp),%rdi
mov    -0x15(%rbp),%cl
mov    %eax,%edx
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
movsbl %cl,%esi
movsbl (%rax),%ecx
call   1030 <expand_safe@plt>
mov    %rax,%rsi
lea    0xef8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
cmp    $0x5,%edi
jne    119f <main+0x5f>
mov    %rsi,%rbx
mov    0x8(%rsi),%rsi
lea    0xed9(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x8(%rbx),%r14
mov    0x10(%rbx),%rax
movsbl (%rax),%r15d
mov    0x18(%rbx),%rdi
call   1050 <str2int@plt>
mov    0x20(%rbx),%rcx
movsbl (%rcx),%ecx
mov    %r14,%rdi
mov    %r15d,%esi
mov    %eax,%edx
call   1030 <expand_safe@plt>
lea    0xeb4(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1208 <main+0xc8>
lea    0xe5a(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
lea    0xf70(%rip),%rdi
call   1040 <puts@plt>
lea    0xe9c(%rip),%rdi
call   1040 <puts@plt>
lea    0xeb2(%rip),%rdi
call   1040 <puts@plt>
lea    0xed7(%rip),%rdi
call   1040 <puts@plt>
lea    0xef6(%rip),%rdi
call   1040 <puts@plt>
lea    0xf14(%rip),%rdi
call   1040 <puts@plt>
lea    0xe17(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"Usage: %s A B C D\0A\00"
@.str.1 = [19 x i8] c"-----------------\0A\00"
@.str.2 = [35 x i8] c"Where A is string to be modified.\0A\00"
@.str.3 = [50 x i8] c" B is one character that is to be replaced.\0A\00"
@.str.4 = [44 x i8] c" C is number of times to be expanded.\0A\00"
@.str.5 = [43 x i8] c" D is what it is to be repaced with.\0A\00"
@.str.6 = [51 x i8] c"-------------------------------------------------\0A\00"
@.str.7 = [32 x i8] c"Example: %s 'Expand mex' x 5 X\0A\00"
@.str.8 = [20 x i8] c"Entered string: %s\0A\00"
@.str.9 = [21 x i8] c"Expanded string: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp ne i32 %7, 5
br i1 %8, label %9, label %18
9: ; preds = %2
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0))
%12 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.3, i64 0, i64 0))
%14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.4, i64 0, i64 0))
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.5, i64 0, i64 0))
%16 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.6, i64 0, i64 0))
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %3
br label %42
18: ; preds = %2
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %21)
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 2
%28 = load i8*, i8** %27
%29 = getelementptr inbounds i8, i8* %28, i64 0
%30 = load i8, i8* %29
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 3
%33 = load i8*, i8** %32
%34 = call i32 @str2int(i8* %33)
%35 = load i8**, i8*** %5
%36 = getelementptr inbounds i8*, i8** %35, i64 4
%37 = load i8*, i8** %36
%38 = getelementptr inbounds i8, i8* %37, i64 0
%39 = load i8, i8* %38
%40 = call i8* @expand_safe(i8* %25, i8 signext %30, i32 %34, i8 signext %39)
%41 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %40)
store i32 0, i32* %3
br label %42
42: ; preds = %18, %9
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [19 x i8] c"Usage: %s A B C D\0A\00"
@.str.7 = [32 x i8] c"Example: %s 'Expand mex' x 5 X\0A\00"
@.str.8 = [20 x i8] c"Entered string: %s\0A\00"
@.str.9 = [21 x i8] c"Expanded string: %s\0A\00"
@str = [18 x i8] c"-----------------\00"
@str.10 = [34 x i8] c"Where A is string to be modified.\00"
@str.11 = [49 x i8] c" B is one character that is to be replaced.\00"
@str.12 = [43 x i8] c" C is number of times to be expanded.\00"
@str.13 = [42 x i8] c" D is what it is to be repaced with.\00"
@str.14 = [50 x i8] c"-------------------------------------------------\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 5
br i1 %3, label %13, label %4
4: ; preds = %2
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str, i64 0, i64 0))
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @str.10, i64 0, i64 0))
%8 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([49 x i8], [49 x i8]* @str.11, i64 0, i64 0))
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([43 x i8], [43 x i8]* @str.12, i64 0, i64 0))
%10 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @str.13, i64 0, i64 0))
%11 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.14, i64 0, i64 0))
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.7, i64 0, i64 0))
br label %29
13: ; preds = %2
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.8, i64 0, i64 0), i8* %15)
%17 = load i8*, i8** %14
%18 = getelementptr inbounds i8*, i8** %1, i64 2
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = getelementptr inbounds i8*, i8** %1, i64 3
%22 = load i8*, i8** %21
%23 = tail call i32 @str2int(i8* %22)
%24 = getelementptr inbounds i8*, i8** %1, i64 4
%25 = load i8*, i8** %24
%26 = load i8, i8* %25
%27 = tail call i8* @expand_safe(i8* %17, i8 signext %20, i32 %23, i8 signext %26)
%28 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([21 x i8], [21 x i8]* @.str.9, i64 0, i64 0), i8* %27)
br label %29
29: ; preds = %13, %4
%30 = phi i32 [ -1, %4 ], [ 0, %13 ]
ret i32 %30
}