#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*/ perform_charset_detection(int /*<<< orphan*/ *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char *argv[]) {
  FILE *fp = NULL;
  if (argc > 1) {
    fp = fopen(argv[1], "rb");
    if (fp) {
      printf("File %s ...\n", argv[1]);
      perform_charset_detection(fp);
      fclose(fp);
    } else {
      printf("Can't open %s\n", argv[1]);
      return 1;
    }
  } else {
    printf("Usage: %s filename\n", argv[0]);
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
cmpl   $0x1,-0x8(%rbp)
jle    11db <main+0x9b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xe89(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11b6 <main+0x76>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe69(%rip),%rdi
call   1040 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1050 <perform_charset_detection@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11d6 <main+0x96>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1201 <main+0xc1>
jmp    11fa <main+0xba>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe36(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    1201 <main+0xc1>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x2,%edi
jl     1188 <main+0x48>
mov    0x8(%rbx),%rdi
lea    0xea9(%rip),%rsi
call   1060 <fopen@plt>
mov    0x8(%rbx),%rsi
test   %rax,%rax
je     1194 <main+0x54>
mov    %rax,%r14
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
mov    %r14,%rdi
call   1050 <perform_charset_detection@plt>
mov    %r14,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
jmp    11a5 <main+0x65>
mov    (%rbx),%rsi
lea    0xe8d(%rip),%rdi
jmp    119b <main+0x5b>
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [13 x i8] c"File %s ...\0A\00"
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@.str.3 = [20 x i8] c"Usage: %s filename\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32* null, i32** %6
%7 = load i32, i32* %4
%8 = icmp sgt i32 %7, 1
br i1 %8, label %9, label %31
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %6
%14 = load i32*, i32** %6
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %25
16: ; preds = %9
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32*, i32** %6
%22 = call i32 @perform_charset_detection(i32* %21)
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
br label %30
25: ; preds = %9
%26 = load i8**, i8*** %5
%27 = getelementptr inbounds i8*, i8** %26, i64 1
%28 = load i8*, i8** %27
%29 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %28)
store i32 1, i32* %3
br label %37
30: ; preds = %16
br label %36
31: ; preds = %2
%32 = load i8**, i8*** %5
%33 = getelementptr inbounds i8*, i8** %32, i64 0
%34 = load i8*, i8** %33
%35 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %34)
store i32 1, i32* %3
br label %37
36: ; preds = %30
store i32 0, i32* %3
br label %37
37: ; preds = %36, %31, %25
%38 = load i32, i32* %3
ret i32 %38
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [13 x i8] c"File %s ...\0A\00"
@.str.2 = [15 x i8] c"Can't open %s\0A\00"
@.str.3 = [20 x i8] c"Usage: %s filename\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %16
4: ; preds = %2
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = tail call i32* @fopen(i8* %6, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%8 = icmp eq i32* %7, null
%9 = load i8*, i8** %5
br i1 %8, label %14, label %10
10: ; preds = %4
%11 = tail call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i8* %9)
%12 = tail call i32 @perform_charset_detection(i32* %7)
%13 = tail call i32 @fclose(i32* %7)
br label %19
14: ; preds = %4
%15 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %9)
br label %19
16: ; preds = %2
%17 = load i8*, i8** %1
%18 = tail call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %10, %16, %14
%20 = phi i32 [ 0, %10 ], [ 1, %14 ], [ 1, %16 ]
ret i32 %20
}