#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 *calloc(scalar_t__, int);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
char *strchr(char *, char);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
char *strpbrk(char *, char *);
int /*<<< orphan*/ unescape_url(char *);
int main(int argc, char **argv) {
  char *str = NULL, *s;
  size_t n;
  if (argc < 2)
    getline(&str, &n, stdin);
  else {
    str = calloc(1 + strlen(argv[1]), sizeof(char));
    strcpy(str, argv[1]);
  }
  if ((s = strpbrk(str, "\r\n")))
    *s = 0;
  while ((s = strchr(str, '+')))
    *s = ' ';
  unescape_url(str);
  fputs(str, stdout);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11c3 <main+0x43>
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <getline@plt>
jmp    11f6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1040 <strlen@plt>
mov    %rax,%rdi
add    $0x1,%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1030 <strcpy@plt>
mov    -0x18(%rbp),%rdi
lea    0xdff(%rip),%rsi
call   1090 <strpbrk@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     121b <main+0x9b>
mov    -0x20(%rbp),%rax
movb   $0x0,(%rax)
jmp    1220 <main+0xa0>
mov    -0x18(%rbp),%rdi
mov    $0x2b,%esi
call   1050 <strchr@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
je     1248 <main+0xc8>
mov    -0x20(%rbp),%rax
movb   $0x20,(%rax)
jmp    1220 <main+0xa0>
mov    -0x18(%rbp),%rdi
call   1080 <unescape_url@plt>
mov    -0x18(%rbp),%rdi
mov    0x2d7c(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x18,%rsp
movq   $0x0,0x8(%rsp)
cmp    $0x1,%edi
jg     11b4 <main+0x34>
mov    0x2e4c(%rip),%rax
mov    (%rax),%edx
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   10a0 <getline@plt>
mov    0x8(%rsp),%rbx
jmp    11e2 <main+0x62>
mov    %rsi,%r14
mov    0x8(%rsi),%rdi
call   1040 <strlen@plt>
lea    0x1(%rax),%rdi
mov    $0x1,%esi
call   1070 <calloc@plt>
mov    %rax,%rbx
mov    %rax,0x8(%rsp)
mov    0x8(%r14),%rsi
mov    %rax,%rdi
call   1030 <strcpy@plt>
lea    0xe17(%rip),%rsi
mov    %rbx,%rdi
call   1090 <strpbrk@plt>
test   %rax,%rax
je     1203 <main+0x83>
movb   $0x0,(%rax)
jmp    11fe <main+0x7e>
movb   $0x20,(%rax)
mov    0x8(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x2b,%esi
call   1050 <strchr@plt>
test   %rax,%rax
jne    11fb <main+0x7b>
mov    %rbx,%rdi
call   1080 <unescape_url@plt>
mov    0x8(%rsp),%rdi
mov    0x2daf(%rip),%rax
mov    (%rax),%esi
call   1060 <fputs@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@stdin = global i32 0
@.str = [3 x i8] c"\0D\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i8*
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %6
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 2
br i1 %10, label %11, label %14
11: ; preds = %2
%12 = load i32, i32* @stdin
%13 = call i32 @getline(i8** %6, i64* %8, i32 %12)
br label %26
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = call i64 @strlen(i8* %17)
%19 = add nsw i64 1, %18
%20 = call i8* @calloc(i64 %19, i32 1)
store i8* %20, i8** %6
%21 = load i8*, i8** %6
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = call i32 @strcpy(i8* %21, i8* %24)
br label %26
26: ; preds = %14, %11
%27 = load i8*, i8** %6
%28 = call i8* @strpbrk(i8* %27, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i8* %28, i8** %7
%29 = icmp ne i8* %28, null
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load i8*, i8** %7
store i8 0, i8* %31
br label %32
32: ; preds = %30, %26
br label %33
33: ; preds = %37, %32
%34 = load i8*, i8** %6
%35 = call i8* @strchr(i8* %34, i8 signext 43)
store i8* %35, i8** %7
%36 = icmp ne i8* %35, null
br i1 %36, label %37, label %39
37: ; preds = %33
%38 = load i8*, i8** %7
store i8 32, i8* %38
br label %33
39: ; preds = %33
%40 = load i8*, i8** %6
%41 = call i32 @unescape_url(i8* %40)
%42 = load i8*, i8** %6
%43 = load i32, i32* @stdout
%44 = call i32 @fputs(i8* %42, i32 %43)
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32 0
@.str = [3 x i8] c"\0D\0A\00"
@stdout = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca i8*
%4 = alloca i64
%5 = bitcast i8** %3 to i8*
store i8* null, i8** %3
%6 = bitcast i64* %4 to i8*
%7 = icmp slt i32 %0, 2
br i1 %7, label %8, label %12
8: ; preds = %2
%9 = load i32, i32* @stdin
%10 = call i32 @getline(i8** %3, i64* %4, i32 %9)
%11 = load i8*, i8** %3
br label %20
12: ; preds = %2
%13 = getelementptr inbounds i8*, i8** %1, i64 1
%14 = load i8*, i8** %13
%15 = tail call i64 @strlen(i8* dereferenceable(1) %14)
%16 = add nsw i64 %15, 1
%17 = tail call i8* @calloc(i64 %16, i32 1)
store i8* %17, i8** %3
%18 = load i8*, i8** %13
%19 = tail call i32 @strcpy(i8* %17, i8* %18)
br label %20
20: ; preds = %12, %8
%21 = phi i8* [ %17, %12 ], [ %11, %8 ]
%22 = call i8* @strpbrk(i8* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %26, label %24
24: ; preds = %20
store i8 0, i8* %22
%25 = load i8*, i8** %3
br label %26
26: ; preds = %24, %20
%27 = phi i8* [ %25, %24 ], [ %21, %20 ]
%28 = call i8* @strchr(i8* dereferenceable(1) %27, i8 signext 43)
%29 = icmp eq i8* %28, null
br i1 %29, label %35, label %30
30: ; preds = %26, %30
%31 = phi i8* [ %33, %30 ], [ %28, %26 ]
store i8 32, i8* %31
%32 = load i8*, i8** %3
%33 = call i8* @strchr(i8* dereferenceable(1) %32, i8 signext 43)
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %30
35: ; preds = %30, %26
%36 = phi i8* [ %27, %26 ], [ %32, %30 ]
%37 = call i32 @unescape_url(i8* %36)
%38 = load i8*, i8** %3
%39 = load i32, i32* @stdout
%40 = call i32 @fputs(i8* %38, i32 %39)
ret i32 0
}