#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*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ free(char *);
int getopt(int, char **, char *);
char *optarg;
int optind;
int /*<<< orphan*/ print_usage_and_exit(char *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ set_ewget_read_buffer_size(int);
int /*<<< orphan*/ set_ewget_timeout_seconds(int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdout;
scalar_t__ strcmp(char *, char *);
char *strdup(char *);
int write_url_to_stream(char *, char *, int /*<<< orphan*/ *,
                        int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int main(int argc, char **argv) {
  int c;
  char *user_agent = NULL;
  char *out_file = strdup("-");
  while ((c = getopt(argc, argv, "O:U:")) != -1) {
    switch (c) {
    case 'O':
      free(out_file);
      out_file = strdup(optarg);
      break;
    case 'U':
      user_agent = strdup(optarg);
      break;
    default:
      print_usage_and_exit(argv[0]);
    }
  }
  if (optind == argc) {
    fprintf(stderr, "ERROR: No URL specified\n\n");
    print_usage_and_exit(argv[0]);
  } else {
    FILE *out_stream =
        strcmp(out_file, "-") == 0 ? stdout : fopen(out_file, "w");
    int ret;
    set_ewget_timeout_seconds(10);
    set_ewget_read_buffer_size(512);
    ret = write_url_to_stream(argv[optind], user_agent, NULL, out_stream, NULL);
    fclose(out_stream);
    if (ret == 1) {
      fprintf(stderr, "Could Not Fetch URL\n");
    }
  }
  printf("\n");
  exit(0);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe0b(%rip),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x28(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xdf6(%rip),%rdx
call   10b0 <getopt@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     128c <main+0xbc>
mov    -0x14(%rbp),%eax
mov    %eax,-0x38(%rbp)
sub    $0x4f,%eax
je     1242 <main+0x72>
jmp    1231 <main+0x61>
mov    -0x38(%rbp),%eax
sub    $0x55,%eax
je     1263 <main+0x93>
jmp    127b <main+0xab>
mov    -0x28(%rbp),%rdi
call   1030 <free@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x28(%rbp)
jmp    1287 <main+0xb7>
mov    0x2d8e(%rip),%rax
mov    (%rax),%rdi
call   10f0 <strdup@plt>
mov    %rax,-0x20(%rbp)
jmp    1287 <main+0xb7>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <print_usage_and_exit@plt>
jmp    11fe <main+0x2e>
mov    0x2d4d(%rip),%rax
mov    (%rax),%eax
cmp    -0x8(%rbp),%eax
jne    12c4 <main+0xf4>
mov    0x2d2b(%rip),%rax
mov    (%rax),%edi
lea    0xd59(%rip),%rsi
call   1090 <fprintf@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <print_usage_and_exit@plt>
jmp    1378 <main+0x1a8>
mov    -0x28(%rbp),%rdi
lea    0xd31(%rip),%rsi
call   1080 <strcmp@plt>
cmp    $0x0,%rax
jne    12f1 <main+0x121>
mov    0x2ce3(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
jmp    1305 <main+0x135>
mov    -0x28(%rbp),%rdi
lea    0xd25(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    $0xa,%edi
call   1040 <set_ewget_timeout_seconds@plt>
mov    $0x200,%edi
call   10c0 <set_ewget_read_buffer_size@plt>
mov    -0x10(%rbp),%rax
mov    0x2cb4(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x30(%rbp),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %r8,%rdx
call   10e0 <write_url_to_stream@plt>
mov    %eax,-0x34(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x1,-0x34(%rbp)
jne    1373 <main+0x1a3>
mov    0x2c6b(%rip),%rax
mov    (%rax),%edi
lea    0xcb5(%rip),%rsi
call   1090 <fprintf@plt>
jmp    1378 <main+0x1a8>
lea    0xca0(%rip),%rdi
call   1060 <printf@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
lea    0xe19(%rip),%rdi
call   10f0 <strdup@plt>
mov    %rax,%r15
xor    %r14d,%r14d
lea    0xe09(%rip),%r12
mov    0x2df8(%rip),%r13
jmp    1210 <main+0x40>
mov    0x0(%r13),%rdi
call   10f0 <strdup@plt>
mov    %rax,%r14
xchg   %ax,%ax
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r12,%rdx
call   10b0 <getopt@plt>
cmp    $0x4f,%eax
je     1236 <main+0x66>
cmp    $0x55,%eax
je     1202 <main+0x32>
cmp    $0xffffffff,%eax
je     124c <main+0x7c>
mov    (%rbx),%rdi
call   1070 <print_usage_and_exit@plt>
jmp    1210 <main+0x40>
mov    %r15,%rdi
call   1030 <free@plt>
mov    0x0(%r13),%rdi
call   10f0 <strdup@plt>
mov    %rax,%r15
jmp    1210 <main+0x40>
mov    0x2d8d(%rip),%r12
cmp    %ebp,(%r12)
jne    127b <main+0xab>
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
lea    0xd9e(%rip),%rsi
call   1090 <fprintf@plt>
mov    (%rbx),%rdi
call   1070 <print_usage_and_exit@plt>
jmp    12fd <main+0x12d>
lea    0xd7e(%rip),%rsi
mov    %r15,%rdi
call   1080 <strcmp@plt>
test   %rax,%rax
jne    129b <main+0xcb>
mov    0x2d32(%rip),%rax
mov    (%rax),%rbp
jmp    12ad <main+0xdd>
lea    0xd7f(%rip),%rsi
mov    %r15,%rdi
call   10a0 <fopen@plt>
mov    %rax,%rbp
mov    $0xa,%edi
call   1050 <set_ewget_timeout_seconds@plt>
mov    $0x200,%edi
call   10c0 <set_ewget_read_buffer_size@plt>
movslq (%r12),%rax
mov    (%rbx,%rax,8),%rdi
mov    %r14,%rsi
xor    %edx,%edx
mov    %rbp,%rcx
xor    %r8d,%r8d
call   10e0 <write_url_to_stream@plt>
mov    %eax,%ebx
mov    %rbp,%rdi
call   1060 <fclose@plt>
cmp    $0x1,%ebx
jne    12fd <main+0x12d>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xd2b(%rip),%rsi
call   1090 <fprintf@plt>
mov    $0xa,%edi
call   1040 <putchar@plt>
xor    %edi,%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"-\00"
@.str.1 = [5 x i8] c"O:U:\00"
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"ERROR: No URL specified\0A\0A\00"
@stdout = global i32* null
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"Could Not Fetch URL\0A\00"
@.str.5 = [2 x i8] c"\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* null, i8** %7
%11 = call i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i8* %11, i8** %8
br label %12
12: ; preds = %32, %2
%13 = load i32, i32* %4
%14 = load i8**, i8*** %5
%15 = call i32 @getopt(i32 %13, i8** %14, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
store i32 %15, i32* %6
%16 = icmp ne i32 %15, -1
br i1 %16, label %17, label %33
17: ; preds = %12
%18 = load i32, i32* %6
switch i32 %18, label %27 [
i32 79, label %19
i32 85, label %24
]
19: ; preds = %17
%20 = load i8*, i8** %8
%21 = call i32 @free(i8* %20)
%22 = load i8*, i8** @optarg
%23 = call i8* @strdup(i8* %22)
store i8* %23, i8** %8
br label %32
24: ; preds = %17
%25 = load i8*, i8** @optarg
%26 = call i8* @strdup(i8* %25)
store i8* %26, i8** %7
br label %32
27: ; preds = %17
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 0
%30 = load i8*, i8** %29
%31 = call i32 @print_usage_and_exit(i8* %30)
br label %32
32: ; preds = %27, %24, %19
br label %12
33: ; preds = %12
%34 = load i32, i32* @optind
%35 = load i32, i32* %4
%36 = icmp eq i32 %34, %35
br i1 %36, label %37, label %44
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 @fprintf(i32 %38, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = call i32 @print_usage_and_exit(i8* %42)
br label %73
44: ; preds = %33
%45 = load i8*, i8** %8
%46 = call i64 @strcmp(i8* %45, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%47 = icmp eq i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = load i32*, i32** @stdout
br label %53
50: ; preds = %44
%51 = load i8*, i8** %8
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %53
53: ; preds = %50, %48
%54 = phi i32* [ %49, %48 ], [ %52, %50 ]
store i32* %54, i32** %9
%55 = call i32 @set_ewget_timeout_seconds(i32 10)
%56 = call i32 @set_ewget_read_buffer_size(i32 512)
%57 = load i8**, i8*** %5
%58 = load i32, i32* @optind
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds i8*, i8** %57, i64 %59
%61 = load i8*, i8** %60
%62 = load i8*, i8** %7
%63 = load i32*, i32** %9
%64 = call i32 @write_url_to_stream(i8* %61, i8* %62, i32* null, i32* %63, i32* null)
store i32 %64, i32* %10
%65 = load i32*, i32** %9
%66 = call i32 @fclose(i32* %65)
%67 = load i32, i32* %10
%68 = icmp eq i32 %67, 1
br i1 %68, label %69, label %72
69: ; preds = %53
%70 = load i32, i32* @stderr
%71 = call i32 @fprintf(i32 %70, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %72
72: ; preds = %69, %53
br label %73
73: ; preds = %72, %37
%74 = call i32 @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%75 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [2 x i8] c"-\00"
@.str.1 = [5 x i8] c"O:U:\00"
@optarg = global i8* null
@optind = global i32 0
@stderr = global i32 0
@.str.2 = [26 x i8] c"ERROR: No URL specified\0A\0A\00"
@stdout = global i32* null
@.str.3 = [2 x i8] c"w\00"
@.str.4 = [21 x i8] c"Could Not Fetch URL\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = tail call dereferenceable_or_null(2) i8* @strdup(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %4
4: ; preds = %11, %2
%5 = phi i8* [ %14, %11 ], [ %3, %2 ]
%6 = phi i8* [ %8, %11 ], [ null, %2 ]
br label %7
7: ; preds = %4, %15
%8 = phi i8* [ %6, %4 ], [ %17, %15 ]
br label %9
9: ; preds = %7, %18
%10 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
switch i32 %10, label %18 [
i32 -1, label %21
i32 79, label %11
i32 85, label %15
]
11: ; preds = %9
%12 = tail call i32 @free(i8* %5)
%13 = load i8*, i8** @optarg
%14 = tail call i8* @strdup(i8* %13)
br label %4
15: ; preds = %9
%16 = load i8*, i8** @optarg
%17 = tail call i8* @strdup(i8* %16)
br label %7
18: ; preds = %9
%19 = load i8*, i8** %1
%20 = tail call i32 @print_usage_and_exit(i8* %19)
br label %9
21: ; preds = %9
%22 = load i32, i32* @optind
%23 = icmp eq i32 %22, %0
br i1 %23, label %24, label %29
24: ; preds = %21
%25 = load i32, i32* @stderr
%26 = tail call i32 @fprintf(i32 %25, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%27 = load i8*, i8** %1
%28 = tail call i32 @print_usage_and_exit(i8* %27)
br label %50
29: ; preds = %21
%30 = tail call i64 @strcmp(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = load i32*, i32** @stdout
br label %36
34: ; preds = %29
%35 = tail call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %34, %32
%37 = phi i32* [ %33, %32 ], [ %35, %34 ]
%38 = tail call i32 @set_ewget_timeout_seconds(i32 10)
%39 = tail call i32 @set_ewget_read_buffer_size(i32 512)
%40 = load i32, i32* @optind
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8*, i8** %1, i64 %41
%43 = load i8*, i8** %42
%44 = tail call i32 @write_url_to_stream(i8* %43, i8* %8, i32* null, i32* %37, i32* null)
%45 = tail call i32 @fclose(i32* %37)
%46 = icmp eq i32 %44, 1
br i1 %46, label %47, label %50
47: ; preds = %36
%48 = load i32, i32* @stderr
%49 = tail call i32 @fprintf(i32 %48, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str.4, i64 0, i64 0))
br label %50
50: ; preds = %36, %47, %24
%51 = tail call i32 @putchar(i32 10)
%52 = tail call i32 @exit(i32 0)
unreachable
}