#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*/ buf;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
scalar_t__ WEOF;
int /*<<< orphan*/ err_quit(char *, char *);
int /*<<< orphan*/ err_sys(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
scalar_t__ fgetwc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fwide(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int main(int argc, char *argv[]) {
  FILE *fp;
  int stream_orientation;
  char buf[128];
  if (argc < 2)
    err_quit("usage: %s <filepath>", argv[0]);
  if ((fp = fopen(argv[1], "r")) == NULL)
    err_sys("fopen error");
  if (fgets(buf, sizeof(buf), fp) == NULL)
    err_sys("fgets error");
  stream_orientation = fwide(fp, 0);
  fclose(fp);
  if (stream_orientation > 0)
    puts("wide-character orientation");
  else if (stream_orientation < 0)
    puts("byte orientation");
  else
    puts("none orientation");
  if ((fp = fopen(argv[1], "r")) == NULL)
    err_sys("fopen error");
  if (fgetwc(fp) == WEOF)
    err_sys("fgetwc error");
  stream_orientation = fwide(fp, 0);
  fclose(fp);
  if (stream_orientation > 0)
    puts("wide-character orientation");
  else if (stream_orientation < 0)
    puts("byte orientation");
  else
    puts("none orientation");
  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   $0x2,-0x8(%rbp)
jge    11b6 <main+0x36>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe4f(%rip),%rdi
call   1070 <err_quit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xeb0(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e4 <main+0x64>
lea    0xe36(%rip),%rdi
call   1040 <err_sys@plt>
lea    -0xa0(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x80,%esi
call   1080 <fgets@plt>
cmp    $0x0,%rax
jne    120f <main+0x8f>
lea    0xe17(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1090 <fwide@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    1241 <main+0xc1>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
jmp    126d <main+0xed>
cmpl   $0x0,-0x1c(%rbp)
jge    125c <main+0xdc>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
jmp    1268 <main+0xe8>
lea    0xdf6(%rip),%rdi
call   1030 <puts@plt>
jmp    126d <main+0xed>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    0xdf9(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    129b <main+0x11b>
lea    0xd7f(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x18(%rbp),%rdi
call   1050 <fgetwc@plt>
mov    0x2d35(%rip),%rcx
cmp    (%rcx),%rax
jne    12c0 <main+0x140>
lea    0xdaf(%rip),%rdi
call   1040 <err_sys@plt>
mov    -0x18(%rbp),%rdi
xor    %esi,%esi
call   1090 <fwide@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%rdi
call   1060 <fclose@plt>
cmpl   $0x0,-0x1c(%rbp)
jle    12f2 <main+0x172>
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
jmp    131e <main+0x19e>
cmpl   $0x0,-0x1c(%rbp)
jge    130d <main+0x18d>
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
jmp    1319 <main+0x199>
lea    0xd45(%rip),%rdi
call   1030 <puts@plt>
jmp    131e <main+0x19e>
xor    %eax,%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x88,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     11a8 <main+0x28>
mov    (%r14),%rsi
lea    0xe5d(%rip),%rdi
call   1070 <err_quit@plt>
mov    0x8(%r14),%rdi
lea    0xec2(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    11cc <main+0x4c>
lea    0xe4e(%rip),%rdi
call   1040 <err_sys@plt>
mov    %rsp,%rdi
mov    $0x80,%esi
mov    %rbx,%rdx
call   1080 <fgets@plt>
test   %rax,%rax
jne    11ed <main+0x6d>
lea    0xe39(%rip),%rdi
call   1040 <err_sys@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fwide@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %ebp,%ebp
lea    0xe3e(%rip),%r12
lea    0xe48(%rip),%r15
mov    %r15,%rdi
cmovs  %r12,%rdi
lea    0xe0e(%rip),%r13
cmovg  %r13,%rdi
call   1030 <puts@plt>
mov    0x8(%r14),%rdi
lea    0xe42(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    124c <main+0xcc>
lea    0xdce(%rip),%rdi
call   1040 <err_sys@plt>
mov    %rbx,%rdi
call   1050 <fgetwc@plt>
mov    0x2d85(%rip),%rcx
cmp    (%rcx),%rax
jne    126c <main+0xec>
lea    0xe03(%rip),%rdi
call   1040 <err_sys@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fwide@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1060 <fclose@plt>
test   %ebp,%ebp
cmovs  %r12,%r15
cmovg  %r13,%r15
mov    %r15,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x88,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [21 x i8] c"usage: %s <filepath>\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"fopen error\00"
@.str.3 = [12 x i8] c"fgets error\00"
@.str.4 = [27 x i8] c"wide-character orientation\00"
@.str.5 = [17 x i8] c"byte orientation\00"
@.str.6 = [17 x i8] c"none orientation\00"
@WEOF = global i64 0
@.str.7 = [13 x i8] c"fgetwc error\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, 2
br i1 %10, label %11, label %16
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 @err_quit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %16
16: ; preds = %11, %2
%17 = load i8**, i8*** %5
%18 = getelementptr inbounds i8*, i8** %17, i64 1
%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** %6
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %24
22: ; preds = %16
%23 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %24
24: ; preds = %22, %16
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %8, i64 0, i64 0
%26 = load i32*, i32** %6
%27 = call i32* @fgets(i8* %25, i32 128, i32* %26)
%28 = icmp eq i32* %27, null
br i1 %28, label %29, label %31
29: ; preds = %24
%30 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %31
31: ; preds = %29, %24
%32 = load i32*, i32** %6
%33 = call i32 @fwide(i32* %32, i32 0)
store i32 %33, i32* %7
%34 = load i32*, i32** %6
%35 = call i32 @fclose(i32* %34)
%36 = load i32, i32* %7
%37 = icmp sgt i32 %36, 0
br i1 %37, label %38, label %40
38: ; preds = %31
%39 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %48
40: ; preds = %31
%41 = load i32, i32* %7
%42 = icmp slt i32 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %40
%44 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %47
45: ; preds = %40
%46 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %47
47: ; preds = %45, %43
br label %48
48: ; preds = %47, %38
%49 = load i8**, i8*** %5
%50 = getelementptr inbounds i8*, i8** %49, i64 1
%51 = load i8*, i8** %50
%52 = call i32* @fopen(i8* %51, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %52, i32** %6
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %56
54: ; preds = %48
%55 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %56
56: ; preds = %54, %48
%57 = load i32*, i32** %6
%58 = call i64 @fgetwc(i32* %57)
%59 = load i64, i64* @WEOF
%60 = icmp eq i64 %58, %59
br i1 %60, label %61, label %63
61: ; preds = %56
%62 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %63
63: ; preds = %61, %56
%64 = load i32*, i32** %6
%65 = call i32 @fwide(i32* %64, i32 0)
store i32 %65, i32* %7
%66 = load i32*, i32** %6
%67 = call i32 @fclose(i32* %66)
%68 = load i32, i32* %7
%69 = icmp sgt i32 %68, 0
br i1 %69, label %70, label %72
70: ; preds = %63
%71 = call i32 @puts(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0))
br label %80
72: ; preds = %63
%73 = load i32, i32* %7
%74 = icmp slt i32 %73, 0
br i1 %74, label %75, label %77
75: ; preds = %72
%76 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
br label %79
77: ; preds = %72
%78 = call i32 @puts(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0))
br label %79
79: ; preds = %77, %75
br label %80
80: ; preds = %79, %70
ret i32 0
}

LLVM IR (-O2):
@.str = [21 x i8] c"usage: %s <filepath>\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [12 x i8] c"fopen error\00"
@.str.3 = [12 x i8] c"fgets error\00"
@.str.4 = [27 x i8] c"wide-character orientation\00"
@.str.5 = [17 x i8] c"byte orientation\00"
@.str.6 = [17 x i8] c"none orientation\00"
@WEOF = global i64 0
@.str.7 = [13 x i8] c"fgetwc error\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, 2
br i1 %5, label %6, label %9
6: ; preds = %2
%7 = load i8*, i8** %1
%8 = tail call i32 @err_quit(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %9
9: ; preds = %6, %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%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* %12, null
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = tail call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %16
16: ; preds = %14, %9
%17 = call i32* @fgets(i8* %4, i32 128, i32* %12)
%18 = icmp eq i32* %17, null
br i1 %18, label %19, label %21
19: ; preds = %16
%20 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
br label %21
21: ; preds = %19, %16
%22 = call i32 @fwide(i32* %12, i32 0)
%23 = call i32 @fclose(i32* %12)
%24 = icmp sgt i32 %22, 0
%25 = icmp slt i32 %22, 0
%26 = select i1 %25, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0)
%27 = select i1 %24, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %26
%28 = call i32 @puts(i8* dereferenceable(1) %27)
%29 = load i8*, i8** %10
%30 = call i32* @fopen(i8* %29, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%31 = icmp eq i32* %30, null
br i1 %31, label %32, label %34
32: ; preds = %21
%33 = call i32 @err_sys(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %34
34: ; preds = %32, %21
%35 = call i64 @fgetwc(i32* %30)
%36 = load i64, i64* @WEOF
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %34
%39 = call i32 @err_sys(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.7, i64 0, i64 0))
br label %40
40: ; preds = %38, %34
%41 = call i32 @fwide(i32* %30, i32 0)
%42 = call i32 @fclose(i32* %30)
%43 = icmp sgt i32 %41, 0
%44 = icmp slt i32 %41, 0
%45 = select i1 %44, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.6, i64 0, i64 0)
%46 = select i1 %43, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i64 0, i64 0), i8* %45
%47 = call i32 @puts(i8* dereferenceable(1) %46)
ret i32 0
}