#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 EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ SEEK_END;
scalar_t__ convert(int /*<<< orphan*/ *, char *, long);
scalar_t__ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ info(char *, ...);
int /*<<< orphan*/ usage();
int main(int argc, char **argv) {
  char *fname = NULL;
  if (argc == 2 && argv[1]) {
    fname = argv[1];
    FILE *fh = fopen(fname, "r");
    if ((!fh)) {
      info("file open failed\n");
      return EXIT_FAILURE;
    }
    if ((fseek(fh, 0, SEEK_END))) {
      info("seek failed\n");
      return EXIT_FAILURE;
    }
    long fs = ftell(fh);
    if ((fs == -1)) {
      info("seek failed\n");
      return EXIT_FAILURE;
    }
    info("converting \"%s\" - %ld bytes ...\n", fname, fs);
    if ((convert(fh, fname, fs))) {
      info("convert failed\n");
      return EXIT_FAILURE;
    }
    if ((fclose(fh))) {
      info("close failed\n");
      return EXIT_FAILURE;
    }
    info("done.\n");
  } else
    usage();
  return EXIT_SUCCESS;
}


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)
jne    12fa <main+0x18a>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     12fa <main+0x18a>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe42(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f1 <main+0x81>
lea    0xe29(%rip),%rdi
mov    $0x0,%al
call   1090 <info@plt>
mov    0x2df1(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    -0x20(%rbp),%rdi
mov    0x2dec(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <fseek@plt>
cmp    $0x0,%rax
je     122e <main+0xbe>
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1090 <info@plt>
mov    0x2db4(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    1265 <main+0xf5>
lea    0xdc7(%rip),%rdi
mov    $0x0,%al
call   1090 <info@plt>
mov    0x2d7d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
lea    0xdad(%rip),%rdi
mov    $0x0,%al
call   1090 <info@plt>
mov    -0x20(%rbp),%rdi
mov    -0x18(%rbp),%rsi
mov    -0x28(%rbp),%rdx
call   1030 <convert@plt>
cmp    $0x0,%rax
je     12b5 <main+0x145>
lea    0xda5(%rip),%rdi
mov    $0x0,%al
call   1090 <info@plt>
mov    0x2d2d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130d <main+0x19d>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
cmp    $0x0,%rax
je     12e7 <main+0x177>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1090 <info@plt>
mov    0x2cfb(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    130d <main+0x19d>
lea    0xd72(%rip),%rdi
mov    $0x0,%al
call   1090 <info@plt>
jmp    1301 <main+0x191>
mov    $0x0,%al
call   1070 <usage@plt>
mov    0x2cc8(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
cmp    $0x2,%edi
jne    11bb <main+0x4b>
mov    0x8(%rsi),%rbx
test   %rbx,%rbx
je     11bb <main+0x4b>
lea    0xe76(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11cb <main+0x5b>
mov    %rax,%r14
mov    0x2e47(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1060 <fseek@plt>
test   %rax,%rax
je     11e8 <main+0x78>
lea    0xe5b(%rip),%rdi
jmp    11d2 <main+0x62>
xor    %eax,%eax
call   1070 <usage@plt>
mov    0x2e07(%rip),%rax
jmp    11e0 <main+0x70>
lea    0xe30(%rip),%rdi
xor    %eax,%eax
call   1090 <info@plt>
mov    0x2df8(%rip),%rax
mov    (%rax),%eax
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %r14,%rdi
call   1050 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     11b2 <main+0x42>
mov    %rax,%r15
lea    0xe21(%rip),%rdi
mov    %rbx,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1090 <info@plt>
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r15,%rdx
call   1030 <convert@plt>
test   %rax,%rax
je     1229 <main+0xb9>
lea    0xe1b(%rip),%rdi
jmp    11d2 <main+0x62>
mov    %r14,%rdi
call   1040 <fclose@plt>
test   %rax,%rax
je     123f <main+0xcf>
lea    0xe15(%rip),%rdi
jmp    11d2 <main+0x62>
lea    0xe1a(%rip),%rdi
xor    %eax,%eax
call   1090 <info@plt>
jmp    11c2 <main+0x52>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"file open failed\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.2 = [13 x i8] c"seek failed\0A\00"
@.str.3 = [33 x i8] c"converting \22%s\22 - %ld bytes ...\0A\00"
@.str.4 = [16 x i8] c"convert failed\0A\00"
@.str.5 = [14 x i8] c"close failed\0A\00"
@.str.6 = [7 x i8] c"done.\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 i8*
%7 = alloca i32*
%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 eq i32 %9, 2
br i1 %10, label %11, label %64
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %64
16: ; preds = %11
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
store i8* %19, i8** %6
%20 = load i8*, i8** %6
%21 = call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %21, i32** %7
%22 = load i32*, i32** %7
%23 = icmp ne i32* %22, null
br i1 %23, label %27, label %24
24: ; preds = %16
%25 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
store i32 %26, i32* %3
br label %68
27: ; preds = %16
%28 = load i32*, i32** %7
%29 = load i32, i32* @SEEK_END
%30 = call i64 @fseek(i32* %28, i32 0, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %27
%33 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @EXIT_FAILURE
store i32 %34, i32* %3
br label %68
35: ; preds = %27
%36 = load i32*, i32** %7
%37 = call i64 @ftell(i32* %36)
store i64 %37, i64* %8
%38 = load i64, i64* %8
%39 = icmp eq i64 %38, -1
br i1 %39, label %40, label %43
40: ; preds = %35
%41 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
%42 = load i32, i32* @EXIT_FAILURE
store i32 %42, i32* %3
br label %68
43: ; preds = %35
%44 = load i8*, i8** %6
%45 = load i64, i64* %8
%46 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %44, i64 %45)
%47 = load i32*, i32** %7
%48 = load i8*, i8** %6
%49 = load i64, i64* %8
%50 = call i64 @convert(i32* %47, i8* %48, i64 %49)
%51 = icmp ne i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %43
%53 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
%54 = load i32, i32* @EXIT_FAILURE
store i32 %54, i32* %3
br label %68
55: ; preds = %43
%56 = load i32*, i32** %7
%57 = call i64 @fclose(i32* %56)
%58 = icmp ne i64 %57, 0
br i1 %58, label %59, label %62
59: ; preds = %55
%60 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%61 = load i32, i32* @EXIT_FAILURE
store i32 %61, i32* %3
br label %68
62: ; preds = %55
%63 = call i32 (i8*, ...) @info(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %66
64: ; preds = %11, %2
%65 = call i32 (...) @usage()
br label %66
66: ; preds = %64, %62
%67 = load i32, i32* @EXIT_SUCCESS
store i32 %67, i32* %3
br label %68
68: ; preds = %66, %59, %52, %40, %32, %24
%69 = load i32, i32* %3
ret i32 %69
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"file open failed\0A\00"
@EXIT_FAILURE = global i32 0
@SEEK_END = global i32 0
@.str.2 = [13 x i8] c"seek failed\0A\00"
@.str.3 = [33 x i8] c"converting \22%s\22 - %ld bytes ...\0A\00"
@.str.4 = [16 x i8] c"convert failed\0A\00"
@.str.5 = [14 x i8] c"close failed\0A\00"
@.str.6 = [7 x i8] c"done.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %4, label %37
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = icmp eq i8* %6, null
br i1 %7, label %37, label %8
8: ; preds = %4
%9 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %8
%12 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0))
br label %39
13: ; preds = %8
%14 = load i32, i32* @SEEK_END
%15 = tail call i64 @fseek(i32* %9, i32 0, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %19, label %17
17: ; preds = %13
%18 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %39
19: ; preds = %13
%20 = tail call i64 @ftell(i32* %9)
%21 = icmp eq i64 %20, -1
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %39
24: ; preds = %19
%25 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0), i8* %6, i64 %20)
%26 = tail call i64 @convert(i32* %9, i8* %6, i64 %20)
%27 = icmp eq i64 %26, 0
br i1 %27, label %30, label %28
28: ; preds = %24
%29 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.4, i64 0, i64 0))
br label %39
30: ; preds = %24
%31 = tail call i64 @fclose(i32* %9)
%32 = icmp eq i64 %31, 0
br i1 %32, label %35, label %33
33: ; preds = %30
%34 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
br label %39
35: ; preds = %30
%36 = tail call i32 (i8*, ...) @info(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0))
br label %39
37: ; preds = %4, %2
%38 = tail call i32 (...) @usage()
br label %39
39: ; preds = %37, %35, %33, %28, %22, %11, %17
%40 = phi i32* [ @EXIT_FAILURE, %33 ], [ @EXIT_FAILURE, %28 ], [ @EXIT_FAILURE, %22 ], [ @EXIT_FAILURE, %11 ], [ @EXIT_FAILURE, %17 ], [ @EXIT_SUCCESS, %35 ], [ @EXIT_SUCCESS, %37 ]
%41 = load i32, i32* %40
ret i32 %41
}