#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 */
scalar_t__ ERANGE;
int EXIT_FAILURE;
int EXIT_SUCCESS;
char *calloc(long, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ isinteger(char *);
int /*<<< orphan*/ isstring(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
char *strerror(scalar_t__);
long strlen(char *);
long strtol(char *, int /*<<< orphan*/ *, int);
int main(int argc, char *argv[]) {
  if (argc < 3 || !isstring(argv[1]) || !isinteger(argv[2])) {
    fprintf(
        stderr,
        "Please enter a string then a postive integer on the command line\n");
    return EXIT_FAILURE;
  }
  errno = 0;
  long length = strtol(argv[2], NULL, 10);
  if (errno == ERANGE) {
    fprintf(stderr, "%s: %s: %s\n", argv[0], argv[2], strerror(errno));
    return EXIT_FAILURE;
  }
  char *s = calloc(length + 1, sizeof(char));
  long l = strlen(argv[1]);
  long c = 0;
  for (size_t i = 0; i < l - c; i++) {
    if (argv[1][i] == ' ') {
      s[i + c + 0] = '%';
      s[i + c + 1] = '2';
      s[i + c + 2] = '0';
      c += 2;
    } else {
      s[i + c + 0] = argv[1][i];
    }
  }
  fprintf(stdout, "%s\n", s);
  free(s);
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jl     11cc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1090 <isstring@plt>
cmp    $0x0,%eax
je     11cc <main+0x4c>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <isinteger@plt>
cmp    $0x0,%eax
jne    11f4 <main+0x74>
mov    0x2e05(%rip),%rax
mov    (%rax),%edi
lea    0xe24(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2dde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <main+0x221>
mov    0x2dd5(%rip),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    %rax,-0x18(%rbp)
mov    0x2dad(%rip),%rax
mov    (%rax),%rax
mov    0x2dbb(%rip),%rcx
cmp    (%rcx),%rax
jne    1295 <main+0x115>
mov    0x2d9b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    0x2d70(%rip),%rax
mov    (%rax),%rdi
call   10a0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    -0x48(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    %rax,%r8
lea    0xdc5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    0x2d3d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    13a1 <main+0x221>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1050 <strlen@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
movq   $0x0,-0x38(%rbp)
mov    -0x38(%rbp),%rax
mov    -0x28(%rbp),%rcx
sub    -0x30(%rbp),%rcx
cmp    %rcx,%rax
jae    1371 <main+0x1f1>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x38(%rbp),%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0x20,%eax
jne    133d <main+0x1bd>
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    -0x30(%rbp),%rcx
movb   $0x25,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    -0x30(%rbp),%rcx
movb   $0x32,0x1(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    -0x30(%rbp),%rcx
movb   $0x30,0x2(%rax,%rcx,1)
mov    -0x30(%rbp),%rax
add    $0x2,%rax
mov    %rax,-0x30(%rbp)
jmp    135b <main+0x1db>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    -0x38(%rbp),%rcx
mov    (%rax,%rcx,1),%dl
mov    -0x20(%rbp),%rax
mov    -0x38(%rbp),%rcx
add    -0x30(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
jmp    1360 <main+0x1e0>
mov    -0x38(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x38(%rbp)
jmp    12cc <main+0x14c>
mov    0x2c48(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xcc5(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    0x2c1c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x3,%edi
jl     1204 <main+0x84>
mov    %rsi,%r15
mov    0x8(%rsi),%rdi
call   1090 <isstring@plt>
test   %eax,%eax
je     1204 <main+0x84>
mov    0x10(%r15),%rdi
call   1040 <isinteger@plt>
test   %eax,%eax
je     1204 <main+0x84>
mov    0x2e22(%rip),%rbx
movq   $0x0,(%rbx)
mov    0x10(%r15),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <strtol@plt>
mov    (%rbx),%rdi
mov    0x2e19(%rip),%rcx
cmp    (%rcx),%rdi
jne    122a <main+0xaa>
mov    0x2dfd(%rip),%rax
mov    (%rax),%ebx
mov    (%r15),%r14
mov    0x10(%r15),%r15
call   10a0 <strerror@plt>
lea    0xe52(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %r15,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1070 <fprintf@plt>
jmp    121b <main+0x9b>
mov    0x2dcd(%rip),%rax
mov    (%rax),%edi
lea    0xdec(%rip),%rsi
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
add    $0x1,%rax
mov    %rax,%rdi
mov    $0x1,%esi
call   1060 <calloc@plt>
mov    %rax,%r14
mov    0x8(%r15),%rbx
mov    %rbx,%rdi
call   1050 <strlen@plt>
test   %rax,%rax
je     1299 <main+0x119>
mov    $0x1,%ecx
xor    %edx,%edx
cs nopw 0x0(%rax,%rax,1)
movzbl -0x1(%rbx,%rcx,1),%ebx
lea    (%r14,%rdx,1),%rsi
cmp    $0x20,%bl
jne    1280 <main+0x100>
movb   $0x25,-0x1(%rsi,%rcx,1)
movw   $0x3032,(%rcx,%rsi,1)
add    $0x2,%rdx
jmp    1284 <main+0x104>
nop
mov    %bl,-0x1(%rsi,%rcx,1)
mov    %rax,%rsi
sub    %rdx,%rsi
cmp    %rsi,%rcx
jae    1299 <main+0x119>
mov    0x8(%r15),%rbx
add    $0x1,%rcx
jmp    1260 <main+0xe0>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
lea    0xda1(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1070 <fprintf@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    0x2cf6(%rip),%rax
jmp    1222 <main+0xa2>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [66 x i8] c"Please enter a string then a postive integer on the command line\0A\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [12 x i8] c"%s: %s: %s\0A\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i64
%7 = alloca i8*
%8 = alloca i64
%9 = alloca i64
%10 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %25, label %13
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 1
%16 = load i8*, i8** %15
%17 = call i32 @isstring(i8* %16)
%18 = icmp ne i32 %17, 0
br i1 %18, label %19, label %25
19: ; preds = %13
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 2
%22 = load i8*, i8** %21
%23 = call i32 @isinteger(i8* %22)
%24 = icmp ne i32 %23, 0
br i1 %24, label %29, label %25
25: ; preds = %19, %13, %2
%26 = load i32, i32* @stderr
%27 = call i32 (i32, i8*, ...) @fprintf(i32 %26, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
%28 = load i32, i32* @EXIT_FAILURE
store i32 %28, i32* %3
br label %117
29: ; preds = %19
store i64 0, i64* @errno
%30 = load i8**, i8*** %5
%31 = getelementptr inbounds i8*, i8** %30, i64 2
%32 = load i8*, i8** %31
%33 = call i64 @strtol(i8* %32, i32* null, i32 10)
store i64 %33, i64* %6
%34 = load i64, i64* @errno
%35 = load i64, i64* @ERANGE
%36 = icmp eq i64 %34, %35
br i1 %36, label %37, label %49
37: ; preds = %29
%38 = load i32, i32* @stderr
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 0
%41 = load i8*, i8** %40
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 2
%44 = load i8*, i8** %43
%45 = load i64, i64* @errno
%46 = call i8* @strerror(i64 %45)
%47 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %41, i8* %44, i8* %46)
%48 = load i32, i32* @EXIT_FAILURE
store i32 %48, i32* %3
br label %117
49: ; preds = %29
%50 = load i64, i64* %6
%51 = add nsw i64 %50, 1
%52 = call i8* @calloc(i64 %51, i32 1)
store i8* %52, i8** %7
%53 = load i8**, i8*** %5
%54 = getelementptr inbounds i8*, i8** %53, i64 1
%55 = load i8*, i8** %54
%56 = call i64 @strlen(i8* %55)
store i64 %56, i64* %8
store i64 0, i64* %9
store i64 0, i64* %10
br label %57
57: ; preds = %107, %49
%58 = load i64, i64* %10
%59 = load i64, i64* %8
%60 = load i64, i64* %9
%61 = sub nsw i64 %59, %60
%62 = icmp ult i64 %58, %61
br i1 %62, label %63, label %110
63: ; preds = %57
%64 = load i8**, i8*** %5
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = load i64, i64* %10
%68 = getelementptr inbounds i8, i8* %66, i64 %67
%69 = load i8, i8* %68
%70 = sext i8 %69 to i32
%71 = icmp eq i32 %70, 32
br i1 %71, label %72, label %93
72: ; preds = %63
%73 = load i8*, i8** %7
%74 = load i64, i64* %10
%75 = load i64, i64* %9
%76 = add i64 %74, %75
%77 = add i64 %76, 0
%78 = getelementptr inbounds i8, i8* %73, i64 %77
store i8 37, i8* %78
%79 = load i8*, i8** %7
%80 = load i64, i64* %10
%81 = load i64, i64* %9
%82 = add i64 %80, %81
%83 = add i64 %82, 1
%84 = getelementptr inbounds i8, i8* %79, i64 %83
store i8 50, i8* %84
%85 = load i8*, i8** %7
%86 = load i64, i64* %10
%87 = load i64, i64* %9
%88 = add i64 %86, %87
%89 = add i64 %88, 2
%90 = getelementptr inbounds i8, i8* %85, i64 %89
store i8 48, i8* %90
%91 = load i64, i64* %9
%92 = add nsw i64 %91, 2
store i64 %92, i64* %9
br label %106
93: ; preds = %63
%94 = load i8**, i8*** %5
%95 = getelementptr inbounds i8*, i8** %94, i64 1
%96 = load i8*, i8** %95
%97 = load i64, i64* %10
%98 = getelementptr inbounds i8, i8* %96, i64 %97
%99 = load i8, i8* %98
%100 = load i8*, i8** %7
%101 = load i64, i64* %10
%102 = load i64, i64* %9
%103 = add i64 %101, %102
%104 = add i64 %103, 0
%105 = getelementptr inbounds i8, i8* %100, i64 %104
store i8 %99, i8* %105
br label %106
106: ; preds = %93, %72
br label %107
107: ; preds = %106
%108 = load i64, i64* %10
%109 = add i64 %108, 1
store i64 %109, i64* %10
br label %57
110: ; preds = %57
%111 = load i32, i32* @stdout
%112 = load i8*, i8** %7
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %111, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %112)
%114 = load i8*, i8** %7
%115 = call i32 @free(i8* %114)
%116 = load i32, i32* @EXIT_SUCCESS
store i32 %116, i32* %3
br label %117
117: ; preds = %110, %37, %25
%118 = load i32, i32* %3
ret i32 %118
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [66 x i8] c"Please enter a string then a postive integer on the command line\0A\00"
@EXIT_FAILURE = global i32 0
@errno = global i64 0
@ERANGE = global i64 0
@.str.1 = [12 x i8] c"%s: %s: %s\0A\00"
@stdout = global i32 0
@.str.2 = [4 x i8] c"%s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %14, label %4
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32 @isstring(i8* %6)
%8 = icmp eq i32 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %4
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32 @isinteger(i8* %11)
%13 = icmp eq i32 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %9, %4, %2
%15 = load i32, i32* @stderr
%16 = tail call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([66 x i8], [66 x i8]* @.str, i64 0, i64 0))
br label %62
17: ; preds = %9
store i64 0, i64* @errno
%18 = load i8*, i8** %10
%19 = tail call i64 @strtol(i8* nocapture %18, i32* null, i32 10)
%20 = load i64, i64* @errno
%21 = load i64, i64* @ERANGE
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %29
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = load i8*, i8** %10
%27 = tail call i8* @strerror(i64 %20)
%28 = tail call i32 (i32, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i8* %25, i8* %26, i8* %27)
br label %62
29: ; preds = %17
%30 = add nsw i64 %19, 1
%31 = tail call i8* @calloc(i64 %30, i32 1)
%32 = load i8*, i8** %5
%33 = tail call i64 @strlen(i8* dereferenceable(1) %32)
%34 = icmp eq i64 %33, 0
br i1 %34, label %35, label %39
35: ; preds = %55, %29
%36 = load i32, i32* @stdout
%37 = tail call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %31)
%38 = tail call i32 @free(i8* %31)
br label %62
39: ; preds = %29, %60
%40 = phi i8* [ %61, %60 ], [ %32, %29 ]
%41 = phi i64 [ %57, %60 ], [ 0, %29 ]
%42 = phi i64 [ %56, %60 ], [ 0, %29 ]
%43 = getelementptr inbounds i8, i8* %40, i64 %41
%44 = load i8, i8* %43
%45 = icmp eq i8 %44, 32
%46 = add i64 %41, %42
%47 = getelementptr inbounds i8, i8* %31, i64 %46
br i1 %45, label %48, label %54
48: ; preds = %39
store i8 37, i8* %47
%49 = add i64 %46, 1
%50 = getelementptr inbounds i8, i8* %31, i64 %49
store i8 50, i8* %50
%51 = add i64 %46, 2
%52 = getelementptr inbounds i8, i8* %31, i64 %51
store i8 48, i8* %52
%53 = add nsw i64 %42, 2
br label %55
54: ; preds = %39
store i8 %44, i8* %47
br label %55
55: ; preds = %48, %54
%56 = phi i64 [ %53, %48 ], [ %42, %54 ]
%57 = add nuw i64 %41, 1
%58 = sub nsw i64 %33, %56
%59 = icmp ult i64 %57, %58
br i1 %59, label %60, label %35
60: ; preds = %55
%61 = load i8*, i8** %5
br label %39
62: ; preds = %23, %35, %14
%63 = phi i32* [ @EXIT_FAILURE, %14 ], [ @EXIT_FAILURE, %23 ], [ @EXIT_SUCCESS, %35 ]
%64 = load i32, i32* %63
ret i32 %64
}