#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *);
int main(int argc, char **argv) {
  FILE *f1, *f2;
  char b[128];
  if (argc < 3)
    return 1;
  f1 = fopen(argv[1], "r");
  f2 = fopen(argv[2], "w");
  if (f1 == NULL || f2 == NULL)
    return 1;
  fgets(b, 128, f1);
  fprintf(f2, "http://bit.ly/ipaw2014\n");
  fclose(f1);
  fclose(f2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    116f <main+0x2f>
movl   $0x1,-0x4(%rbp)
jmp    11ff <main+0xbf>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe82(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    0xe6c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b5 <main+0x75>
cmpq   $0x0,-0x20(%rbp)
jne    11c1 <main+0x81>
movl   $0x1,-0x4(%rbp)
jmp    11ff <main+0xbf>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1040 <fgets@plt>
mov    -0x20(%rbp),%rdi
lea    0xe23(%rip),%rsi
call   1050 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x88,%rsp
mov    $0x1,%ebp
cmp    $0x3,%edi
jl     11c5 <main+0x85>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,%r15
mov    0x10(%rbx),%rdi
lea    0xe8a(%rip),%rsi
call   1050 <fopen@plt>
test   %r15,%r15
je     11c5 <main+0x85>
mov    %rax,%r14
test   %rax,%rax
je     11c5 <main+0x85>
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %r15,%rdx
call   1040 <fgets@plt>
lea    0xe63(%rip),%rdi
mov    $0x17,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1060 <fwrite@plt>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %ebp,%ebp
mov    %ebp,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [24 x i8] c"http://bit.ly/ipaw2014\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
%7 = alloca i32*
%8 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp slt i32 %9, 3
br i1 %10, label %11, label %12
11: ; preds = %2
store i32 1, i32* %3
br label %37
12: ; preds = %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32* @fopen(i8* %15, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %16, i32** %6
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 2
%19 = load i8*, i8** %18
%20 = call i32* @fopen(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %20, i32** %7
%21 = load i32*, i32** %6
%22 = icmp eq i32* %21, null
br i1 %22, label %26, label %23
23: ; preds = %12
%24 = load i32*, i32** %7
%25 = icmp eq i32* %24, null
br i1 %25, label %26, label %27
26: ; preds = %23, %12
store i32 1, i32* %3
br label %37
27: ; preds = %23
%28 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%29 = load i32*, i32** %6
%30 = call i32 @fgets(i8* %28, i32 128, i32* %29)
%31 = load i32*, i32** %7
%32 = call i32 @fprintf(i32* %31, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0))
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
%35 = load i32*, i32** %7
%36 = call i32 @fclose(i32* %35)
store i32 0, i32* %3
br label %37
37: ; preds = %27, %26, %11
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [24 x i8] c"http://bit.ly/ipaw2014\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 3
br i1 %5, label %21, label %6
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = tail call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = getelementptr inbounds i8*, i8** %1, i64 2
%11 = load i8*, i8** %10
%12 = tail call i32* @fopen(i8* %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%13 = icmp eq i32* %9, null
%14 = icmp eq i32* %12, null
%15 = or i1 %13, %14
br i1 %15, label %21, label %16
16: ; preds = %6
%17 = call i32 @fgets(i8* %4, i32 128, i32* %9)
%18 = call i64 @fwrite(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i64 23, i64 1, i32* %12)
%19 = call i32 @fclose(i32* %9)
%20 = call i32 @fclose(i32* %12)
br label %21
21: ; preds = %6, %2, %16
%22 = phi i32 [ 0, %16 ], [ 1, %2 ], [ 1, %6 ]
ret i32 %22
}