#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;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ exit(int);
void *ioctl(int, int, ...);
int /*<<< orphan*/ lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, long);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int /*<<< orphan*/ write(int, unsigned char *, int);
int main(int argc, char **argv) {
  unsigned char buf[512];
  long frames;
  char startcode;
  int f;
  f = open("/dev/usbdmx0", O_RDWR);
  if (f == -1) {
    char str[128];
    sprintf(str, "Error open device \"%s\"", "/dev/usbdmx0");
    perror(str);
    exit(1);
  }
  ioctl(f, 17, 0);
  ioctl(f, 1, ((1 << 2) | 0));
  lseek(f, 0, SEEK_SET);
  read(f, buf, sizeof(buf));
  ioctl(f, 17, 1);
  ioctl(f, 1, ((2 << 2) | 0));
  lseek(f, 0, SEEK_SET);
  write(f, buf, sizeof(buf));
  frames = ioctl(f, 7);
  printf("usbdmx transmitter frame counter: %ld\n", frames);
  startcode = ioctl(f, 9);
  ioctl(f, 6, startcode);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2a0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
lea    0xe47(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0x220(%rbp)
cmpl   $0xffffffff,-0x220(%rbp)
jne    1201 <main+0x71>
lea    -0x2a0(%rbp),%rdi
lea    0xe2e(%rip),%rsi
lea    0xe1a(%rip),%rdx
call   10a0 <sprintf@plt>
lea    -0x2a0(%rbp),%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>
mov    -0x220(%rbp),%edi
mov    $0x11,%esi
xor    %edx,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    -0x220(%rbp),%edi
mov    $0x1,%esi
mov    $0x4,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    -0x220(%rbp),%edi
mov    0x2d9f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x220(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    -0x220(%rbp),%edi
mov    $0x11,%esi
mov    $0x1,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    -0x220(%rbp),%edi
mov    $0x1,%esi
mov    $0x8,%edx
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    -0x220(%rbp),%edi
mov    0x2d44(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x220(%rbp),%edi
lea    -0x210(%rbp),%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    -0x220(%rbp),%edi
mov    $0x7,%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %rax,-0x218(%rbp)
mov    -0x218(%rbp),%rsi
lea    0xd49(%rip),%rdi
call   1040 <printf@plt>
mov    -0x220(%rbp),%edi
mov    $0x9,%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
mov    %al,-0x219(%rbp)
mov    -0x220(%rbp),%edi
movsbl -0x219(%rbp),%edx
mov    $0x6,%esi
mov    $0x0,%al
call   1060 <ioctl@plt>
xor    %eax,%eax
add    $0x2a0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x200,%rsp
mov    0x2e45(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1290 <main+0x100>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x11,%esi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x4,%edx
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    0x2df2(%rip),%r15
mov    (%r15),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1070 <read@plt>
mov    %ebx,%edi
mov    $0x11,%esi
mov    $0x1,%edx
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    %ebx,%edi
mov    $0x1,%esi
mov    $0x8,%edx
xor    %eax,%eax
call   1060 <ioctl@plt>
mov    (%r15),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x200,%edx
call   1030 <write@plt>
mov    %ebx,%edi
mov    $0x7,%esi
xor    %eax,%eax
call   1060 <ioctl@plt>
lea    0xdca(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    %ebx,%edi
mov    $0x9,%esi
xor    %eax,%eax
call   1060 <ioctl@plt>
movsbl %al,%edx
mov    %ebx,%edi
mov    $0x6,%esi
xor    %eax,%eax
call   1060 <ioctl@plt>
xor    %eax,%eax
add    $0x200,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd76(%rip),%rsi
lea    0xd62(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
call   10a0 <sprintf@plt>
mov    %rbx,%rdi
call   1090 <perror@plt>
mov    $0x1,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [13 x i8] c"/dev/usbdmx0\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Error open device \22%s\22\00"
@SEEK_SET = global i32 0
@.str.2 = [39 x i8] c"usbdmx transmitter frame counter: %ld\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [512 x i8]
%7 = alloca i64
%8 = alloca i8
%9 = alloca i32
%10 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %9
%13 = load i32, i32* %9
%14 = icmp eq i32 %13, -1
br i1 %14, label %15, label %21
15: ; preds = %2
%16 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%17 = call i32 @sprintf(i8* %16, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%19 = call i32 @perror(i8* %18)
%20 = call i32 @exit(i32 1)
unreachable
21: ; preds = %2
%22 = load i32, i32* %9
%23 = call i8* (i32, i32, ...) @ioctl(i32 %22, i32 17, i32 0)
%24 = load i32, i32* %9
%25 = call i8* (i32, i32, ...) @ioctl(i32 %24, i32 1, i32 4)
%26 = load i32, i32* %9
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @lseek(i32 %26, i32 0, i32 %27)
%29 = load i32, i32* %9
%30 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%31 = call i32 @read(i32 %29, i8* %30, i32 512)
%32 = load i32, i32* %9
%33 = call i8* (i32, i32, ...) @ioctl(i32 %32, i32 17, i32 1)
%34 = load i32, i32* %9
%35 = call i8* (i32, i32, ...) @ioctl(i32 %34, i32 1, i32 8)
%36 = load i32, i32* %9
%37 = load i32, i32* @SEEK_SET
%38 = call i32 @lseek(i32 %36, i32 0, i32 %37)
%39 = load i32, i32* %9
%40 = getelementptr inbounds [512 x i8], [512 x i8]* %6, i64 0, i64 0
%41 = call i32 @write(i32 %39, i8* %40, i32 512)
%42 = load i32, i32* %9
%43 = call i8* (i32, i32, ...) @ioctl(i32 %42, i32 7)
%44 = ptrtoint i8* %43 to i64
store i64 %44, i64* %7
%45 = load i64, i64* %7
%46 = call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %45)
%47 = load i32, i32* %9
%48 = call i8* (i32, i32, ...) @ioctl(i32 %47, i32 9)
%49 = ptrtoint i8* %48 to i8
store i8 %49, i8* %8
%50 = load i32, i32* %9
%51 = load i8, i8* %8
%52 = sext i8 %51 to i32
%53 = call i8* (i32, i32, ...) @ioctl(i32 %50, i32 6, i32 %52)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"/dev/usbdmx0\00"
@O_RDWR = global i32 0
@.str.1 = [23 x i8] c"Error open device \22%s\22\00"
@SEEK_SET = global i32 0
@.str.2 = [39 x i8] c"usbdmx transmitter frame counter: %ld\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [512 x i8]
%4 = alloca [128 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %3, i64 0, i64 0
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%11 = call i32 @sprintf(i8* %10, i8* dereferenceable(1) getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%12 = call i32 @perror(i8* %10)
%13 = tail call i32 @exit(i32 1)
unreachable
14: ; preds = %2
%15 = tail call i8* (i32, i32, ...) @ioctl(i32 %7, i32 17, i32 0)
%16 = tail call i8* (i32, i32, ...) @ioctl(i32 %7, i32 1, i32 4)
%17 = load i32, i32* @SEEK_SET
%18 = tail call i32 @lseek(i32 %7, i32 0, i32 %17)
%19 = call i32 @read(i32 %7, i8* %5, i32 512)
%20 = tail call i8* (i32, i32, ...) @ioctl(i32 %7, i32 17, i32 1)
%21 = tail call i8* (i32, i32, ...) @ioctl(i32 %7, i32 1, i32 8)
%22 = load i32, i32* @SEEK_SET
%23 = tail call i32 @lseek(i32 %7, i32 0, i32 %22)
%24 = call i32 @write(i32 %7, i8* %5, i32 512)
%25 = tail call i8* (i32, i32, ...) @ioctl(i32 %7, i32 7)
%26 = ptrtoint i8* %25 to i64
%27 = tail call i32 @printf(i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.2, i64 0, i64 0), i64 %26)
%28 = tail call i8* (i32, i32, ...) @ioctl(i32 %7, i32 9)
%29 = ptrtoint i8* %28 to i64
%30 = trunc i64 %29 to i32
%31 = shl i32 %30, 24
%32 = ashr exact i32 %31, 24
%33 = tail call i8* (i32, i32, ...) @ioctl(i32 %7, i32 6, i32 %32)
ret i32 0
}