#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *, char *, char *,
                           char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ perror(char *);
int main(int argc, char **argv) {
  char str[1024];
  char *pre = "<a href=\"http://";
  char *mid = "\" target=\"_blank\">";
  char *end = "</a>";
  FILE *in, *out;
  in = fopen(argv[1], "r");
  out = fopen(argv[2], "w");
  if (!in || !out) {
    perror("Open failed");
    return -1;
  }
  while (fscanf(in, "%s", str)) {
    fprintf(out, "%s%s%s%s%s\n", pre, str, mid, str, end);
  }
  fclose(in);
  fclose(out);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe90(%rip),%rax
mov    %rax,-0x418(%rbp)
lea    0xe93(%rip),%rax
mov    %rax,-0x420(%rbp)
lea    0xe98(%rip),%rax
mov    %rax,-0x428(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe87(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x430(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x430(%rbp)
je     11e5 <main+0x95>
cmpq   $0x0,-0x438(%rbp)
jne    11fd <main+0xad>
lea    0xe41(%rip),%rdi
call   1070 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1284 <main+0x134>
jmp    1202 <main+0xb2>
mov    -0x430(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xe22(%rip),%rsi
call   1040 <fscanf@plt>
cmp    $0x0,%rax
je     1265 <main+0x115>
mov    -0x438(%rbp),%rdi
mov    -0x418(%rbp),%rdx
lea    -0x410(%rbp),%rcx
mov    -0x420(%rbp),%r8
lea    -0x410(%rbp),%r9
mov    -0x428(%rbp),%rax
lea    0xde5(%rip),%rsi
mov    %rax,(%rsp)
call   1050 <fprintf@plt>
jmp    1202 <main+0xb2>
mov    -0x430(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x438(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x418,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xeba(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r14
mov    0x10(%rbx),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
test   %r14,%r14
je     122d <main+0xdd>
mov    %rax,%rbx
test   %rax,%rax
je     122d <main+0xdd>
lea    0xe96(%rip),%rsi
lea    0x10(%rsp),%rdx
mov    %r14,%rdi
call   1040 <fscanf@plt>
test   %rax,%rax
je     1209 <main+0xb9>
lea    0xe44(%rip),%r12
lea    0xe4e(%rip),%r13
lea    0x10(%rsp),%rbp
lea    0xe6a(%rip),%r15
nop
lea    0xe4d(%rip),%rax
mov    %rax,(%rsp)
mov    %rbx,%rdi
lea    0xe57(%rip),%rsi
mov    %r12,%rdx
mov    %rbp,%rcx
mov    %r13,%r8
mov    %rbp,%r9
call   1050 <fprintf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
test   %rax,%rax
jne    11d0 <main+0x80>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x418,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdf9(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%eax
jmp    121b <main+0xcb>

LLVM IR (-O0):
@.str = [17 x i8] c"<a href=\22http://\00"
@.str.1 = [19 x i8] c"\22 target=\22_blank\22>\00"
@.str.2 = [5 x i8] c"</a>\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [12 x i8] c"Open failed\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [12 x i8] c"%s%s%s%s%s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i32*
%11 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8** %7
store i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8** %8
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %9
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %15, i32** %10
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 2
%18 = load i8*, i8** %17
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
store i32* %19, i32** %11
%20 = load i32*, i32** %10
%21 = icmp ne i32* %20, null
br i1 %21, label %22, label %25
22: ; preds = %2
%23 = load i32*, i32** %11
%24 = icmp ne i32* %23, null
br i1 %24, label %27, label %25
25: ; preds = %22, %2
%26 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %46
27: ; preds = %22
br label %28
28: ; preds = %33, %27
%29 = load i32*, i32** %10
%30 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%31 = call i64 @fscanf(i32* %29, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %41
33: ; preds = %28
%34 = load i32*, i32** %11
%35 = load i8*, i8** %7
%36 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%37 = load i8*, i8** %8
%38 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%39 = load i8*, i8** %9
%40 = call i32 @fprintf(i32* %34, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* %35, i8* %36, i8* %37, i8* %38, i8* %39)
br label %28
41: ; preds = %28
%42 = load i32*, i32** %10
%43 = call i32 @fclose(i32* %42)
%44 = load i32*, i32** %11
%45 = call i32 @fclose(i32* %44)
store i32 0, i32* %3
br label %46
46: ; preds = %41, %25
%47 = load i32, i32* %3
ret i32 %47
}

LLVM IR (-O2):
@.str = [17 x i8] c"<a href=\22http://\00"
@.str.1 = [19 x i8] c"\22 target=\22_blank\22>\00"
@.str.2 = [5 x i8] c"</a>\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c"w\00"
@.str.5 = [12 x i8] c"Open failed\00"
@.str.6 = [3 x i8] c"%s\00"
@.str.7 = [12 x i8] c"%s%s%s%s%s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = tail call i32* @fopen(i8* %9, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%11 = icmp ne i32* %7, null
%12 = icmp ne i32* %10, null
%13 = and i1 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %2
%15 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%16 = icmp eq i64 %15, 0
br i1 %16, label %23, label %19
17: ; preds = %2
%18 = tail call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.5, i64 0, i64 0))
br label %26
19: ; preds = %14, %19
%20 = call i32 @fprintf(i32* %10, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i8* %4, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
%21 = call i64 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %19
23: ; preds = %19, %14
%24 = call i32 @fclose(i32* %7)
%25 = call i32 @fclose(i32* %10)
br label %26
26: ; preds = %23, %17
%27 = phi i32 [ 0, %23 ], [ -1, %17 ]
ret i32 %27
}