#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ err_msg(char *, char *);
int /*<<< orphan*/ err_ret(char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ isastream(int);
int open(char *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int i, fd;
  for (i = 1; i < argc; i++) {
    if ((fd = open(argv[i], O_RDONLY)) < 0) {
      err_ret("%s: can't open", argv[i]);
      continue;
    }
    if ((isastream(fd) == 0)) {
      err_ret("%s: not a stream", argv[i]);
    } else {
      err_msg("%s: streams device", argv[i]);
    }
  }
  exit(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)
movl   $0x1,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1216 <main+0xc6>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    0x2e5c(%rip),%rax
mov    (%rax),%esi
call   1030 <open@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x0,%eax
jge    11bc <main+0x6c>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe4e(%rip),%rdi
call   1050 <err_ret@plt>
jmp    1208 <main+0xb8>
mov    -0x18(%rbp),%edi
call   1070 <isastream@plt>
cmp    $0x0,%rax
jne    11eb <main+0x9b>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe2e(%rip),%rdi
call   1050 <err_ret@plt>
jmp    1203 <main+0xb3>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
lea    0xe22(%rip),%rdi
call   1040 <err_msg@plt>
jmp    1208 <main+0xb8>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    116d <main+0x1d>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
cmp    $0x2,%edi
jl     11d9 <main+0x89>
mov    %rsi,%rbx
mov    %edi,%r13d
mov    $0x1,%ebp
mov    0x2e76(%rip),%r15
lea    0xe87(%rip),%r14
lea    0xea0(%rip),%r12
jmp    11a5 <main+0x55>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    (%rbx,%rbp,8),%rsi
mov    %r14,%rdi
call   1050 <err_ret@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     11d9 <main+0x89>
mov    (%rbx,%rbp,8),%rdi
mov    (%r15),%esi
call   1030 <open@plt>
test   %eax,%eax
js     1190 <main+0x40>
mov    %eax,%edi
call   1070 <isastream@plt>
mov    (%rbx,%rbp,8),%rsi
test   %rax,%rax
je     11d0 <main+0x80>
mov    %r12,%rdi
call   1040 <err_msg@plt>
jmp    119c <main+0x4c>
nop
lea    0xe38(%rip),%rdi
jmp    1197 <main+0x47>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@.str = [15 x i8] c"%s: can't open\00"
@.str.1 = [17 x i8] c"%s: not a stream\00"
@.str.2 = [19 x i8] c"%s: streams device\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %6
br label %8
8: ; preds = %47, %2
%9 = load i32, i32* %6
%10 = load i32, i32* %4
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %50
12: ; preds = %8
%13 = load i8**, i8*** %5
%14 = load i32, i32* %6
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds i8*, i8** %13, i64 %15
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDONLY
%19 = call i32 @open(i8* %17, i32 %18)
store i32 %19, i32* %7
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %28
21: ; preds = %12
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32 @err_ret(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %47
28: ; preds = %12
%29 = load i32, i32* %7
%30 = call i64 @isastream(i32 %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %39
32: ; preds = %28
%33 = load i8**, i8*** %5
%34 = load i32, i32* %6
%35 = sext i32 %34 to i64
%36 = getelementptr inbounds i8*, i8** %33, i64 %35
%37 = load i8*, i8** %36
%38 = call i32 @err_ret(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %37)
br label %46
39: ; preds = %28
%40 = load i8**, i8*** %5
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds i8*, i8** %40, i64 %42
%44 = load i8*, i8** %43
%45 = call i32 @err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %44)
br label %46
46: ; preds = %39, %32
br label %47
47: ; preds = %46, %21
%48 = load i32, i32* %6
%49 = add nsw i32 %48, 1
store i32 %49, i32* %6
br label %8
50: ; preds = %8
%51 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@.str = [15 x i8] c"%s: can't open\00"
@.str.1 = [17 x i8] c"%s: not a stream\00"
@.str.2 = [19 x i8] c"%s: streams device\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %27
4: ; preds = %2
%5 = zext i32 %0 to i64
br label %6
6: ; preds = %4, %24
%7 = phi i64 [ 1, %4 ], [ %25, %24 ]
%8 = getelementptr inbounds i8*, i8** %1, i64 %7
%9 = load i8*, i8** %8
%10 = load i32, i32* @O_RDONLY
%11 = tail call i32 @open(i8* %9, i32 %10)
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %6
%14 = load i8*, i8** %8
%15 = tail call i32 @err_ret(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), i8* %14)
br label %24
16: ; preds = %6
%17 = tail call i64 @isastream(i32 %11)
%18 = icmp eq i64 %17, 0
%19 = load i8*, i8** %8
br i1 %18, label %20, label %22
20: ; preds = %16
%21 = tail call i32 @err_ret(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i8* %19)
br label %24
22: ; preds = %16
%23 = tail call i32 @err_msg(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.2, i64 0, i64 0), i8* %19)
br label %24
24: ; preds = %20, %22, %13
%25 = add nuw nsw i64 %7, 1
%26 = icmp eq i64 %25, %5
br i1 %26, label %27, label %6
27: ; preds = %24, %2
%28 = tail call i32 @exit(i32 0)
unreachable
}