#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
scalar_t__ S_ISCHR(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstat(int, struct stat *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ play_from_file(int);
int /*<<< orphan*/ play_from_stdin(int);
int /*<<< orphan*/ stderr;
int play(int argc, char *argv[]) {
  int fd;
  struct stat st;
  if (argc != 2) {
    fprintf(stderr, "Usage: %s <device>|<recording>\n", argv[0]);
    fprintf(stderr, "\n");
    fprintf(stderr, "If the argument is an input event node,\n"
                    "event data is read from standard input.\n");
    fprintf(stderr, "If the argument is an evemu recording,\n"
                    "the device is created and the event data is"
                    "read from the same device.\n");
    return -1;
  }
  fd = open(argv[1], O_RDWR);
  if (fd < 0) {
    fprintf(stderr, "error: could not open file or device (%m)\n");
    return -1;
  }
  if (fstat(fd, &st) == -1) {
    fprintf(stderr, "error: failed to look at file (%m)\n");
    return -1;
  }
  if (S_ISCHR(st.st_mode))
    play_from_stdin(fd);
  else
    play_from_file(fd);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<play>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     11f8 <play+0x88>
mov    0x2e48(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe60(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
lea    0xf51(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    0x2dfc(%rip),%rax
mov    (%rax),%edi
lea    0xe8c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <play+0x13c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2de1(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    123e <play+0xce>
mov    0x2db6(%rip),%rax
mov    (%rax),%edi
lea    0xeb4(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <play+0x13c>
mov    -0x14(%rbp),%edi
lea    -0x18(%rbp),%rsi
call   1090 <fstat@plt>
cmp    $0xffffffff,%eax
jne    1276 <play+0x106>
mov    0x2d7e(%rip),%rax
mov    (%rax),%edi
lea    0xea7(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12ac <play+0x13c>
mov    -0x18(%rbp),%edi
call   1060 <S_ISCHR@plt>
cmp    $0x0,%rax
je     1295 <play+0x125>
mov    -0x14(%rbp),%edi
call   1040 <play_from_stdin@plt>
jmp    129d <play+0x12d>
mov    -0x14(%rbp),%edi
call   1080 <play_from_file@plt>
mov    -0x14(%rbp),%edi
call   1030 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<play>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x2,%edi
jne    11be <play+0x4e>
mov    0x8(%rsi),%rdi
mov    0x2e63(%rip),%rax
mov    (%rax),%esi
call   1070 <open@plt>
test   %eax,%eax
js     1203 <play+0x93>
mov    %eax,%ebx
lea    0x8(%rsp),%rsi
mov    %eax,%edi
call   1090 <fstat@plt>
cmp    $0xffffffff,%eax
je     1215 <play+0xa5>
mov    0x8(%rsp),%edi
call   1060 <S_ISCHR@plt>
mov    %ebx,%edi
test   %rax,%rax
je     1237 <play+0xc7>
call   1040 <play_from_stdin@plt>
jmp    123c <play+0xcc>
mov    0x2e13(%rip),%rbx
mov    (%rbx),%edi
mov    (%rsi),%rdx
lea    0xe2f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xf27(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe2f(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xe70(%rip),%rsi
jmp    1225 <play+0xb5>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xecc(%rip),%rsi
jmp    1225 <play+0xb5>
mov    0x2dbc(%rip),%rax
mov    (%rax),%edi
lea    0xee5(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret
call   1080 <play_from_file@plt>
mov    %ebx,%edi
call   1030 <close@plt>
xor    %eax,%eax
jmp    1231 <play+0xc1>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s <device>|<recording>\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [81 x i8] c"If the argument is an input event node,\0Aevent data is read from standard input.\0A\00"
@.str.3 = [110 x i8] c"If the argument is an evemu recording,\0Athe device is created and the event data isread from the same device.\0A\00"
@O_RDWR = global i32 0
@.str.4 = [43 x i8] c"error: could not open file or device (%m)\0A\00"
@.str.5 = [36 x i8] c"error: failed to look at file (%m)\0A\00"
define i32 @play(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca %struct.stat
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @stderr
%19 = call i32 (i32, i8*, ...) @fprintf(i32 %18, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32, i32* @stderr
%21 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.3, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
22: ; preds = %2
%23 = load i8**, i8*** %5
%24 = getelementptr inbounds i8*, i8** %23, i64 1
%25 = load i8*, i8** %24
%26 = load i32, i32* @O_RDWR
%27 = call i32 @open(i8* %25, i32 %26)
store i32 %27, i32* %6
%28 = load i32, i32* %6
%29 = icmp slt i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %22
%31 = load i32, i32* @stderr
%32 = call i32 (i32, i8*, ...) @fprintf(i32 %31, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
33: ; preds = %22
%34 = load i32, i32* %6
%35 = call i32 @fstat(i32 %34, %struct.stat* %7)
%36 = icmp eq i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* @stderr
%39 = call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %3
br label %54
40: ; preds = %33
%41 = getelementptr inbounds %struct.stat, %struct.stat* %7, i32 0, i32 0
%42 = load i32, i32* %41
%43 = call i64 @S_ISCHR(i32 %42)
%44 = icmp ne i64 %43, 0
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* %6
%47 = call i32 @play_from_stdin(i32 %46)
br label %51
48: ; preds = %40
%49 = load i32, i32* %6
%50 = call i32 @play_from_file(i32 %49)
br label %51
51: ; preds = %48, %45
%52 = load i32, i32* %6
%53 = call i32 @close(i32 %52)
store i32 0, i32* %3
br label %54
54: ; preds = %51, %37, %30, %10
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [32 x i8] c"Usage: %s <device>|<recording>\0A\00"
@.str.1 = [2 x i8] c"\0A\00"
@.str.2 = [81 x i8] c"If the argument is an input event node,\0Aevent data is read from standard input.\0A\00"
@.str.3 = [110 x i8] c"If the argument is an evemu recording,\0Athe device is created and the event data isread from the same device.\0A\00"
@O_RDWR = global i32 0
@.str.4 = [43 x i8] c"error: could not open file or device (%m)\0A\00"
@.str.5 = [36 x i8] c"error: failed to look at file (%m)\0A\00"
define i32 @play(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.stat
%4 = bitcast %struct.stat* %3 to i8*
%5 = icmp eq i32 %0, 2
br i1 %5, label %16, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), i8* %8)
%10 = load i32, i32* @stderr
%11 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = load i32, i32* @stderr
%13 = tail call i32 (i32, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([81 x i8], [81 x i8]* @.str.2, i64 0, i64 0))
%14 = load i32, i32* @stderr
%15 = tail call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([110 x i8], [110 x i8]* @.str.3, i64 0, i64 0))
br label %42
16: ; preds = %2
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDWR
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = tail call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.4, i64 0, i64 0))
br label %42
25: ; preds = %16
%26 = call i32 @fstat(i32 %20, %struct.stat* %3)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %31
28: ; preds = %25
%29 = load i32, i32* @stderr
%30 = tail call i32 (i32, i8*, ...) @fprintf(i32 %29, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.5, i64 0, i64 0))
br label %42
31: ; preds = %25
%32 = getelementptr inbounds %struct.stat, %struct.stat* %3, i64 0, i32 0
%33 = load i32, i32* %32
%34 = tail call i64 @S_ISCHR(i32 %33)
%35 = icmp eq i64 %34, 0
br i1 %35, label %38, label %36
36: ; preds = %31
%37 = tail call i32 @play_from_stdin(i32 %20)
br label %40
38: ; preds = %31
%39 = tail call i32 @play_from_file(i32 %20)
br label %40
40: ; preds = %38, %36
%41 = tail call i32 @close(i32 %20)
br label %42
42: ; preds = %40, %28, %22, %6
%43 = phi i32 [ -1, %6 ], [ -1, %22 ], [ -1, %28 ], [ 0, %40 ]
ret i32 %43
}