#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 dmx_stc {
  int stc;
  int base;
  scalar_t__ num;
};

/* Variables and functions */
int /*<<< orphan*/ DMX_GET_STC;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
char *getenv(char *);
int ioctl(int, int /*<<< orphan*/, struct dmx_stc *);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, int, int, int);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ usage();
int main(int argc, char *argv[]) {
  int dmxfd;
  char *dmxdev = "/dev/dvb/adapter0/demux0";
  struct dmx_stc stc;
  if (argc != 1 || argv[1])
    usage();
  if (getenv("DEMUX"))
    dmxdev = getenv("DEMUX");
  fprintf(stderr, "test_stc: using '%s'\n", dmxdev);
  if ((dmxfd = open(dmxdev, O_RDWR)) < 0) {
    perror("open");
    return 1;
  }
  stc.num = 0;
  if (ioctl(dmxfd, DMX_GET_STC, &stc) == -1) {
    perror("DMX_GET_STC");
    return 1;
  }
  printf("STC = %llu (%llu / %u)\n", stc.stc / stc.base, stc.stc, stc.base);
  close(dmxfd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe63(%rip),%rax
mov    %rax,-0x20(%rbp)
cmpl   $0x1,-0x8(%rbp)
jne    11ba <main+0x3a>
mov    -0x10(%rbp),%rax
cmpq   $0x0,0x8(%rax)
je     11c1 <main+0x41>
mov    $0x0,%al
call   1080 <usage@plt>
lea    0xe51(%rip),%rdi
call   1030 <getenv@plt>
cmp    $0x0,%rax
je     11e7 <main+0x67>
lea    0xe3b(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x20(%rbp)
mov    0x2dea(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
lea    0xe24(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2ddd(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmp    $0x0,%eax
jge    1236 <main+0xb6>
lea    0xe10(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    129e <main+0x11e>
movq   $0x0,-0x28(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2d88(%rip),%rax
mov    (%rax),%esi
lea    -0x30(%rbp),%rdx
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
jne    1274 <main+0xf4>
lea    0xdd7(%rip),%rdi
call   10a0 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    129e <main+0x11e>
mov    -0x30(%rbp),%eax
cltd
idivl  -0x2c(%rbp)
mov    %eax,%esi
mov    -0x30(%rbp),%edx
mov    -0x2c(%rbp),%ecx
lea    0xdbc(%rip),%rdi
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
cmp    $0x1,%edi
jne    1192 <main+0x12>
cmpq   $0x0,0x8(%rsi)
je     1199 <main+0x19>
xor    %eax,%eax
call   1080 <usage@plt>
lea    0xe79(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
lea    0xe51(%rip),%rbx
cmovne %rax,%rbx
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
lea    0xe5c(%rip),%rsi
mov    %rbx,%rdx
call   1070 <fprintf@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1090 <open@plt>
test   %eax,%eax
js     1232 <main+0xb2>
mov    %eax,%ebp
movq   $0x0,0x10(%rsp)
mov    0x2dde(%rip),%rax
mov    (%rax),%esi
lea    0x8(%rsp),%rdx
mov    %ebp,%edi
call   1050 <ioctl@plt>
cmp    $0xffffffff,%eax
je     123b <main+0xbb>
mov    0x8(%rsp),%ebx
mov    0xc(%rsp),%ecx
mov    %ebx,%eax
cltd
idiv   %ecx
lea    0xe2d(%rip),%rdi
mov    %eax,%esi
mov    %ebx,%edx
call   1040 <printf@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xdfc(%rip),%rdi
jmp    1242 <main+0xc2>
lea    0xdf8(%rip),%rdi
call   10a0 <perror@plt>
mov    $0x1,%eax
jmp    122b <main+0xab>

LLVM IR (-O0):
%struct.dmx_stc = type { i32, i32, i64 }
@.str = [25 x i8] c"/dev/dvb/adapter0/demux0\00"
@.str.1 = [6 x i8] c"DEMUX\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"test_stc: using '%s'\0A\00"
@O_RDWR = global i32 0
@.str.3 = [5 x i8] c"open\00"
@DMX_GET_STC = global i32 0
@.str.4 = [12 x i8] c"DMX_GET_STC\00"
@.str.5 = [24 x i8] c"STC = %llu (%llu / %u)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i8*
%8 = alloca %struct.dmx_stc
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8** %7
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 1
br i1 %10, label %16, label %11
11: ; preds = %2
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 1
%14 = load i8*, i8** %13
%15 = icmp ne i8* %14, null
br i1 %15, label %16, label %18
16: ; preds = %11, %2
%17 = call i32 (...) @usage()
br label %18
18: ; preds = %16, %11
%19 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%20 = icmp ne i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
store i8* %22, i8** %7
br label %23
23: ; preds = %21, %18
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %7
%26 = call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i8*, i8** %7
%28 = load i32, i32* @O_RDWR
%29 = call i32 @open(i8* %27, i32 %28)
store i32 %29, i32* %6
%30 = icmp slt i32 %29, 0
br i1 %30, label %31, label %33
31: ; preds = %23
%32 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
br label %54
33: ; preds = %23
%34 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %8, i32 0, i32 2
store i64 0, i64* %34
%35 = load i32, i32* %6
%36 = load i32, i32* @DMX_GET_STC
%37 = call i32 @ioctl(i32 %35, i32 %36, %struct.dmx_stc* %8)
%38 = icmp eq i32 %37, -1
br i1 %38, label %39, label %41
39: ; preds = %33
%40 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
store i32 1, i32* %3
br label %54
41: ; preds = %33
%42 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %8, i32 0, i32 0
%43 = load i32, i32* %42
%44 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %8, i32 0, i32 1
%45 = load i32, i32* %44
%46 = sdiv i32 %43, %45
%47 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %8, i32 0, i32 0
%48 = load i32, i32* %47
%49 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %8, i32 0, i32 1
%50 = load i32, i32* %49
%51 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %46, i32 %48, i32 %50)
%52 = load i32, i32* %6
%53 = call i32 @close(i32 %52)
store i32 0, i32* %3
br label %54
54: ; preds = %41, %39, %31
%55 = load i32, i32* %3
ret i32 %55
}

LLVM IR (-O2):
%struct.dmx_stc = type { i32, i32, i64 }
@.str = [25 x i8] c"/dev/dvb/adapter0/demux0\00"
@.str.1 = [6 x i8] c"DEMUX\00"
@stderr = global i32 0
@.str.2 = [22 x i8] c"test_stc: using '%s'\0A\00"
@O_RDWR = global i32 0
@.str.3 = [5 x i8] c"open\00"
@DMX_GET_STC = global i32 0
@.str.4 = [12 x i8] c"DMX_GET_STC\00"
@.str.5 = [24 x i8] c"STC = %llu (%llu / %u)\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca %struct.dmx_stc
%4 = bitcast %struct.dmx_stc* %3 to i8*
%5 = icmp eq i32 %0, 1
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = load i8*, i8** %7
%9 = icmp eq i8* %8, null
br i1 %9, label %12, label %10
10: ; preds = %6, %2
%11 = tail call i32 (...) @usage()
br label %12
12: ; preds = %10, %6
%13 = tail call i8* @getenv(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%14 = icmp eq i8* %13, null
%15 = select i1 %14, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0), i8* %13
%16 = load i32, i32* @stderr
%17 = tail call i32 @fprintf(i32 %16, i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.2, i64 0, i64 0), i8* %15)
%18 = load i32, i32* @O_RDWR
%19 = tail call i32 @open(i8* %15, i32 %18)
%20 = icmp slt i32 %19, 0
br i1 %20, label %21, label %23
21: ; preds = %12
%22 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
br label %38
23: ; preds = %12
%24 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %3, i64 0, i32 2
store i64 0, i64* %24
%25 = load i32, i32* @DMX_GET_STC
%26 = call i32 @ioctl(i32 %19, i32 %25, %struct.dmx_stc* %3)
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %30
28: ; preds = %23
%29 = call i32 @perror(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0))
br label %38
30: ; preds = %23
%31 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %3, i64 0, i32 0
%32 = load i32, i32* %31
%33 = getelementptr inbounds %struct.dmx_stc, %struct.dmx_stc* %3, i64 0, i32 1
%34 = load i32, i32* %33
%35 = sdiv i32 %32, %34
%36 = call i32 @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.5, i64 0, i64 0), i32 %35, i32 %32, i32 %34)
%37 = call i32 @close(i32 %19)
br label %38
38: ; preds = %30, %28, %21
%39 = phi i32 [ 1, %21 ], [ 1, %28 ], [ 0, %30 ]
ret i32 %39
}