#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 timeval {
  int dummy;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ O_SYNC;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ check_buf_test(unsigned int, int, int /*<<< orphan*/);
int /*<<< orphan*/ clear_buf_test(unsigned int, int, int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
long lseek(int, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, unsigned char *, int);
int /*<<< orphan*/ sprintf(unsigned char *, char *, unsigned long);
int /*<<< orphan*/ sscanf(unsigned char *, char *, ...);
int /*<<< orphan*/ strlen(unsigned char *);
int /*<<< orphan*/ write(int, unsigned char *, int /*<<< orphan*/);
void main() {
  int fd;
  unsigned char attr[1024];
  unsigned char *buf;
  unsigned int buf_size;
  unsigned long phys_addr;
  unsigned long debug_vma = 0;
  unsigned long sync_mode = 2;
  int error_count;
  struct timeval start_time, end_time;
  if ((fd = open("/sys/class/u-dma-buf/udmabuf0/phys_addr", O_RDONLY)) != -1) {
    read(fd, attr, 1024);
    sscanf(attr, "%x", &phys_addr);
    close(fd);
  }
  if ((fd = open("/sys/class/u-dma-buf/udmabuf0/size", O_RDONLY)) != -1) {
    read(fd, attr, 1024);
    sscanf(attr, "%d", &buf_size);
    close(fd);
  }
  if ((fd = open("/sys/class/u-dma-buf/udmabuf0/sync_mode", O_WRONLY)) != -1) {
    sprintf(attr, "%d", sync_mode);
    write(fd, attr, strlen(attr));
    close(fd);
  }
  if ((fd = open("/sys/class/u-dma-buf/udmabuf0/debug_vma", O_WRONLY)) != -1) {
    sprintf(attr, "%d", debug_vma);
    write(fd, attr, strlen(attr));
    close(fd);
  }
  printf("phys_addr=0x%x\n", phys_addr);
  printf("size=%d\n", buf_size);
  if ((fd = open("/dev/udmabuf0", O_RDWR)) != -1) {
    long last_pos = lseek(fd, 0, 2);
    if (last_pos == -1) {
      printf("lseek error\n");
      exit(-1);
    }
    close(fd);
  }
  printf("check_buf()\n", buf_size);
  check_buf_test(buf_size, 0, 0);
  check_buf_test(buf_size, 0, O_SYNC);
  check_buf_test(buf_size, 1, 0);
  check_buf_test(buf_size, 1, O_SYNC);
  check_buf_test(buf_size, 2, 0);
  check_buf_test(buf_size, 2, O_SYNC);
  check_buf_test(buf_size, 3, 0);
  check_buf_test(buf_size, 3, O_SYNC);
  check_buf_test(buf_size, 4, 0);
  check_buf_test(buf_size, 4, O_SYNC);
  check_buf_test(buf_size, 5, 0);
  check_buf_test(buf_size, 5, O_SYNC);
  check_buf_test(buf_size, 6, 0);
  check_buf_test(buf_size, 6, O_SYNC);
  check_buf_test(buf_size, 7, 0);
  check_buf_test(buf_size, 7, O_SYNC);
  printf("clear_buf()\n", buf_size);
  clear_buf_test(buf_size, 0, 0);
  clear_buf_test(buf_size, 0, O_SYNC);
  clear_buf_test(buf_size, 1, 0);
  clear_buf_test(buf_size, 1, O_SYNC);
  clear_buf_test(buf_size, 2, 0);
  clear_buf_test(buf_size, 2, O_SYNC);
  clear_buf_test(buf_size, 3, 0);
  clear_buf_test(buf_size, 3, O_SYNC);
  clear_buf_test(buf_size, 4, 0);
  clear_buf_test(buf_size, 4, O_SYNC);
  clear_buf_test(buf_size, 5, 0);
  clear_buf_test(buf_size, 5, O_SYNC);
  clear_buf_test(buf_size, 6, 0);
  clear_buf_test(buf_size, 6, O_SYNC);
  clear_buf_test(buf_size, 7, 0);
  clear_buf_test(buf_size, 7, O_SYNC);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x470,%rsp
movq   $0x0,-0x430(%rbp)
movq   $0x2,-0x438(%rbp)
mov    0x2df0(%rip),%rax
mov    (%rax),%esi
lea    0xe0f(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
je     123a <main+0x7a>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
lea    -0x410(%rbp),%rdi
lea    0xe04(%rip),%rsi
lea    -0x428(%rbp),%rdx
mov    $0x0,%al
call   10b0 <sscanf@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
mov    0x2d97(%rip),%rax
mov    (%rax),%esi
lea    0xde1(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
je     1293 <main+0xd3>
mov    -0x4(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1090 <read@plt>
lea    -0x410(%rbp),%rdi
lea    0xdd1(%rip),%rsi
lea    -0x41c(%rbp),%rdx
mov    $0x0,%al
call   10b0 <sscanf@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
mov    0x2d26(%rip),%rax
mov    (%rax),%esi
lea    0xdae(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
je     130d <main+0x14d>
lea    -0x410(%rbp),%rdi
mov    -0x438(%rbp),%rdx
lea    0xd85(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x45c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x458(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x45c(%rbp),%edi
mov    -0x458(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
mov    0x2cac(%rip),%rax
mov    (%rax),%esi
lea    0xd5c(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
je     1387 <main+0x1c7>
lea    -0x410(%rbp),%rdi
mov    -0x430(%rbp),%rdx
lea    0xd0b(%rip),%rsi
call   10d0 <sprintf@plt>
mov    -0x4(%rbp),%eax
mov    %eax,-0x46c(%rbp)
lea    -0x410(%rbp),%rax
mov    %rax,-0x468(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <strlen@plt>
mov    -0x46c(%rbp),%edi
mov    -0x468(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
mov    -0x428(%rbp),%rsi
lea    0xd0c(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x41c(%rbp),%esi
lea    0xd08(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    0x2c31(%rip),%rax
mov    (%rax),%esi
lea    0xcfa(%rip),%rdi
call   10c0 <open@plt>
mov    %eax,-0x4(%rbp)
cmp    $0xffffffff,%eax
je     1415 <main+0x255>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
mov    $0x2,%edx
call   1070 <lseek@plt>
mov    %rax,-0x450(%rbp)
cmpq   $0xffffffffffffffff,-0x450(%rbp)
ff
jne    140d <main+0x24d>
lea    0xccc(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    $0xffffffff,%edi
call   10e0 <exit@plt>
mov    -0x4(%rbp),%edi
call   1080 <close@plt>
mov    -0x41c(%rbp),%esi
lea    0xcb3(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x41c(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2b9b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2b73(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x2,%esi
xor    %edx,%edx
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2b48(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x3,%esi
xor    %edx,%edx
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2b1d(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x4,%esi
xor    %edx,%edx
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2af2(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2ac7(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x6,%esi
xor    %edx,%edx
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2a9c(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x7,%esi
xor    %edx,%edx
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2a71(%rip),%rax
mov    (%rax),%edx
mov    $0x7,%esi
call   10a0 <check_buf_test@plt>
mov    -0x41c(%rbp),%esi
lea    0xb5a(%rip),%rdi
mov    $0x0,%al
call   1060 <printf@plt>
mov    -0x41c(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2a35(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2a0d(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x29e2(%rip),%rax
mov    (%rax),%edx
mov    $0x2,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x29b7(%rip),%rax
mov    (%rax),%edx
mov    $0x3,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x298c(%rip),%rax
mov    (%rax),%edx
mov    $0x4,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2961(%rip),%rax
mov    (%rax),%edx
mov    $0x5,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x6,%esi
xor    %edx,%edx
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x2936(%rip),%rax
mov    (%rax),%edx
mov    $0x6,%esi
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    $0x7,%esi
xor    %edx,%edx
call   1040 <clear_buf_test@plt>
mov    -0x41c(%rbp),%edi
mov    0x290b(%rip),%rax
mov    (%rax),%edx
mov    $0x7,%esi
call   1040 <clear_buf_test@plt>
add    $0x470,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x410,%rsp
mov    0x2df5(%rip),%r15
mov    (%r15),%esi
lea    0xe13(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     122a <main+0x5a>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
lea    0xe14(%rip),%rsi
lea    0x8(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <sscanf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    (%r15),%esi
lea    0xdf7(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1271 <main+0xa1>
mov    %eax,%ebx
lea    0x10(%rsp),%r14
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x400,%edx
call   10a0 <read@plt>
lea    0xdf3(%rip),%rsi
lea    0x4(%rsp),%rdx
mov    %r14,%rdi
xor    %eax,%eax
call   10c0 <sscanf@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x2d48(%rip),%r15
mov    (%r15),%esi
lea    0xdcf(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     12c2 <main+0xf2>
mov    %eax,%ebx
lea    0xdb9(%rip),%rsi
lea    0x10(%rsp),%r14
mov    $0x2,%edx
mov    %r14,%rdi
call   10e0 <sprintf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    (%r15),%esi
lea    0xdad(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1309 <main+0x139>
mov    %eax,%ebx
lea    0xd6f(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   10e0 <sprintf@plt>
mov    %r14,%rdi
call   1060 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    %ebx,%edi
call   1090 <close@plt>
mov    0x8(%rsp),%rsi
lea    0xd8c(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x4(%rsp),%esi
lea    0xd8a(%rip),%rdi
xor    %eax,%eax
call   1070 <printf@plt>
mov    0x2cb3(%rip),%rax
mov    (%rax),%esi
lea    0xd7c(%rip),%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1369 <main+0x199>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
mov    $0x2,%edx
call   1080 <lseek@plt>
cmp    $0xffffffffffffffff,%rax
je     1589 <main+0x3b9>
mov    %ebx,%edi
call   1090 <close@plt>
lea    0xd58(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    0x2c53(%rip),%rbx
mov    (%rbx),%edx
xor    %esi,%esi
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x1,%esi
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x2,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x2,%esi
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x3,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x3,%esi
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x4,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x4,%esi
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x5,%esi
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x6,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x6,%esi
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x7,%esi
xor    %edx,%edx
call   10b0 <check_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x7,%esi
call   10b0 <check_buf_test@plt>
lea    0xc57(%rip),%rdi
call   1030 <puts@plt>
mov    0x4(%rsp),%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
xor    %esi,%esi
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x1,%esi
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x2,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x2,%esi
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x3,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x3,%esi
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x4,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x4,%esi
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x5,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x5,%esi
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x6,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x6,%esi
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    $0x7,%esi
xor    %edx,%edx
call   1050 <clear_buf_test@plt>
mov    0x4(%rsp),%edi
mov    (%rbx),%edx
mov    $0x7,%esi
call   1050 <clear_buf_test@plt>
add    $0x410,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xb50(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
%struct.timeval = type { i32 }
@.str = [40 x i8] c"/sys/class/u-dma-buf/udmabuf0/phys_addr\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [35 x i8] c"/sys/class/u-dma-buf/udmabuf0/size\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [40 x i8] c"/sys/class/u-dma-buf/udmabuf0/sync_mode\00"
@O_WRONLY = global i32 0
@.str.5 = [40 x i8] c"/sys/class/u-dma-buf/udmabuf0/debug_vma\00"
@.str.6 = [16 x i8] c"phys_addr=0x%x\0A\00"
@.str.7 = [9 x i8] c"size=%d\0A\00"
@.str.8 = [14 x i8] c"/dev/udmabuf0\00"
@O_RDWR = global i32 0
@.str.9 = [13 x i8] c"lseek error\0A\00"
@.str.10 = [13 x i8] c"check_buf()\0A\00"
@O_SYNC = global i32 0
@.str.11 = [13 x i8] c"clear_buf()\0A\00"
define void @main() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i64
%6 = alloca i64
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.timeval
%10 = alloca %struct.timeval
%11 = alloca i64
store i64 0, i64* %6
store i64 2, i64* %7
%12 = load i32, i32* @O_RDONLY
%13 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %12)
store i32 %13, i32* %1
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %23
15: ; preds = %0
%16 = load i32, i32* %1
%17 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%18 = call i32 @read(i32 %16, i8* %17, i32 1024)
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %19, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %5)
%21 = load i32, i32* %1
%22 = call i32 @close(i32 %21)
br label %23
23: ; preds = %15, %0
%24 = load i32, i32* @O_RDONLY
%25 = call i32 @open(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %24)
store i32 %25, i32* %1
%26 = icmp ne i32 %25, -1
br i1 %26, label %27, label %35
27: ; preds = %23
%28 = load i32, i32* %1
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%30 = call i32 @read(i32 %28, i8* %29, i32 1024)
%31 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%32 = call i32 (i8*, i8*, ...) @sscanf(i8* %31, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %4)
%33 = load i32, i32* %1
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %27, %23
%36 = load i32, i32* @O_WRONLY
%37 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %36)
store i32 %37, i32* %1
%38 = icmp ne i32 %37, -1
br i1 %38, label %39, label %50
39: ; preds = %35
%40 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%41 = load i64, i64* %7
%42 = call i32 @sprintf(i8* %40, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 %41)
%43 = load i32, i32* %1
%44 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%45 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%46 = call i32 @strlen(i8* %45)
%47 = call i32 @write(i32 %43, i8* %44, i32 %46)
%48 = load i32, i32* %1
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %39, %35
%51 = load i32, i32* @O_WRONLY
%52 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %51)
store i32 %52, i32* %1
%53 = icmp ne i32 %52, -1
br i1 %53, label %54, label %65
54: ; preds = %50
%55 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%56 = load i64, i64* %6
%57 = call i32 @sprintf(i8* %55, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 %56)
%58 = load i32, i32* %1
%59 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%60 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%61 = call i32 @strlen(i8* %60)
%62 = call i32 @write(i32 %58, i8* %59, i32 %61)
%63 = load i32, i32* %1
%64 = call i32 @close(i32 %63)
br label %65
65: ; preds = %54, %50
%66 = load i64, i64* %5
%67 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64 %66)
%68 = load i32, i32* %4
%69 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %68)
%70 = load i32, i32* @O_RDWR
%71 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %70)
store i32 %71, i32* %1
%72 = icmp ne i32 %71, -1
br i1 %72, label %73, label %84
73: ; preds = %65
%74 = load i32, i32* %1
%75 = call i64 @lseek(i32 %74, i32 0, i32 2)
store i64 %75, i64* %11
%76 = load i64, i64* %11
%77 = icmp eq i64 %76, -1
br i1 %77, label %78, label %81
78: ; preds = %73
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.9, i64 0, i64 0))
%80 = call i32 @exit(i32 -1)
unreachable
81: ; preds = %73
%82 = load i32, i32* %1
%83 = call i32 @close(i32 %82)
br label %84
84: ; preds = %81, %65
%85 = load i32, i32* %4
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.10, i64 0, i64 0), i32 %85)
%87 = load i32, i32* %4
%88 = call i32 @check_buf_test(i32 %87, i32 0, i32 0)
%89 = load i32, i32* %4
%90 = load i32, i32* @O_SYNC
%91 = call i32 @check_buf_test(i32 %89, i32 0, i32 %90)
%92 = load i32, i32* %4
%93 = call i32 @check_buf_test(i32 %92, i32 1, i32 0)
%94 = load i32, i32* %4
%95 = load i32, i32* @O_SYNC
%96 = call i32 @check_buf_test(i32 %94, i32 1, i32 %95)
%97 = load i32, i32* %4
%98 = call i32 @check_buf_test(i32 %97, i32 2, i32 0)
%99 = load i32, i32* %4
%100 = load i32, i32* @O_SYNC
%101 = call i32 @check_buf_test(i32 %99, i32 2, i32 %100)
%102 = load i32, i32* %4
%103 = call i32 @check_buf_test(i32 %102, i32 3, i32 0)
%104 = load i32, i32* %4
%105 = load i32, i32* @O_SYNC
%106 = call i32 @check_buf_test(i32 %104, i32 3, i32 %105)
%107 = load i32, i32* %4
%108 = call i32 @check_buf_test(i32 %107, i32 4, i32 0)
%109 = load i32, i32* %4
%110 = load i32, i32* @O_SYNC
%111 = call i32 @check_buf_test(i32 %109, i32 4, i32 %110)
%112 = load i32, i32* %4
%113 = call i32 @check_buf_test(i32 %112, i32 5, i32 0)
%114 = load i32, i32* %4
%115 = load i32, i32* @O_SYNC
%116 = call i32 @check_buf_test(i32 %114, i32 5, i32 %115)
%117 = load i32, i32* %4
%118 = call i32 @check_buf_test(i32 %117, i32 6, i32 0)
%119 = load i32, i32* %4
%120 = load i32, i32* @O_SYNC
%121 = call i32 @check_buf_test(i32 %119, i32 6, i32 %120)
%122 = load i32, i32* %4
%123 = call i32 @check_buf_test(i32 %122, i32 7, i32 0)
%124 = load i32, i32* %4
%125 = load i32, i32* @O_SYNC
%126 = call i32 @check_buf_test(i32 %124, i32 7, i32 %125)
%127 = load i32, i32* %4
%128 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.11, i64 0, i64 0), i32 %127)
%129 = load i32, i32* %4
%130 = call i32 @clear_buf_test(i32 %129, i32 0, i32 0)
%131 = load i32, i32* %4
%132 = load i32, i32* @O_SYNC
%133 = call i32 @clear_buf_test(i32 %131, i32 0, i32 %132)
%134 = load i32, i32* %4
%135 = call i32 @clear_buf_test(i32 %134, i32 1, i32 0)
%136 = load i32, i32* %4
%137 = load i32, i32* @O_SYNC
%138 = call i32 @clear_buf_test(i32 %136, i32 1, i32 %137)
%139 = load i32, i32* %4
%140 = call i32 @clear_buf_test(i32 %139, i32 2, i32 0)
%141 = load i32, i32* %4
%142 = load i32, i32* @O_SYNC
%143 = call i32 @clear_buf_test(i32 %141, i32 2, i32 %142)
%144 = load i32, i32* %4
%145 = call i32 @clear_buf_test(i32 %144, i32 3, i32 0)
%146 = load i32, i32* %4
%147 = load i32, i32* @O_SYNC
%148 = call i32 @clear_buf_test(i32 %146, i32 3, i32 %147)
%149 = load i32, i32* %4
%150 = call i32 @clear_buf_test(i32 %149, i32 4, i32 0)
%151 = load i32, i32* %4
%152 = load i32, i32* @O_SYNC
%153 = call i32 @clear_buf_test(i32 %151, i32 4, i32 %152)
%154 = load i32, i32* %4
%155 = call i32 @clear_buf_test(i32 %154, i32 5, i32 0)
%156 = load i32, i32* %4
%157 = load i32, i32* @O_SYNC
%158 = call i32 @clear_buf_test(i32 %156, i32 5, i32 %157)
%159 = load i32, i32* %4
%160 = call i32 @clear_buf_test(i32 %159, i32 6, i32 0)
%161 = load i32, i32* %4
%162 = load i32, i32* @O_SYNC
%163 = call i32 @clear_buf_test(i32 %161, i32 6, i32 %162)
%164 = load i32, i32* %4
%165 = call i32 @clear_buf_test(i32 %164, i32 7, i32 0)
%166 = load i32, i32* %4
%167 = load i32, i32* @O_SYNC
%168 = call i32 @clear_buf_test(i32 %166, i32 7, i32 %167)
ret void
}

LLVM IR (-O2):
@.str = [40 x i8] c"/sys/class/u-dma-buf/udmabuf0/phys_addr\00"
@O_RDONLY = global i32 0
@.str.1 = [3 x i8] c"%x\00"
@.str.2 = [35 x i8] c"/sys/class/u-dma-buf/udmabuf0/size\00"
@.str.3 = [3 x i8] c"%d\00"
@.str.4 = [40 x i8] c"/sys/class/u-dma-buf/udmabuf0/sync_mode\00"
@O_WRONLY = global i32 0
@.str.5 = [40 x i8] c"/sys/class/u-dma-buf/udmabuf0/debug_vma\00"
@.str.6 = [16 x i8] c"phys_addr=0x%x\0A\00"
@.str.7 = [9 x i8] c"size=%d\0A\00"
@.str.8 = [14 x i8] c"/dev/udmabuf0\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@str = [12 x i8] c"check_buf()\00"
@str.12 = [12 x i8] c"clear_buf()\00"
@str.13 = [12 x i8] c"lseek error\00"
define void @main() {
%1 = alloca [1024 x i8]
%2 = alloca i32
%3 = alloca i64
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%5 = bitcast i32* %2 to i8*
%6 = bitcast i64* %3 to i8*
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %14, label %10
10: ; preds = %0
%11 = call i32 @read(i32 %8, i8* %4, i32 1024)
%12 = call i32 (i8*, i8*, ...) @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i64* %3)
%13 = call i32 @close(i32 %8)
br label %14
14: ; preds = %10, %0
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.2, i64 0, i64 0), i32 %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %22, label %18
18: ; preds = %14
%19 = call i32 @read(i32 %16, i8* %4, i32 1024)
%20 = call i32 (i8*, i8*, ...) @sscanf(i8* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%21 = call i32 @close(i32 %16)
br label %22
22: ; preds = %18, %14
%23 = load i32, i32* @O_WRONLY
%24 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.4, i64 0, i64 0), i32 %23)
%25 = icmp eq i32 %24, -1
br i1 %25, label %31, label %26
26: ; preds = %22
%27 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 2)
%28 = call i32 @strlen(i8* %4)
%29 = call i32 @write(i32 %24, i8* %4, i32 %28)
%30 = call i32 @close(i32 %24)
br label %31
31: ; preds = %26, %22
%32 = load i32, i32* @O_WRONLY
%33 = call i32 @open(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str.5, i64 0, i64 0), i32 %32)
%34 = icmp eq i32 %33, -1
br i1 %34, label %40, label %35
35: ; preds = %31
%36 = call i32 @sprintf(i8* %4, i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i64 0)
%37 = call i32 @strlen(i8* %4)
%38 = call i32 @write(i32 %33, i8* %4, i32 %37)
%39 = call i32 @close(i32 %33)
br label %40
40: ; preds = %35, %31
%41 = load i64, i64* %3
%42 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i64 %41)
%43 = load i32, i32* %2
%44 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.7, i64 0, i64 0), i32 %43)
%45 = load i32, i32* @O_RDWR
%46 = call i32 @open(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.8, i64 0, i64 0), i32 %45)
%47 = icmp eq i32 %46, -1
br i1 %47, label %56, label %48
48: ; preds = %40
%49 = call i64 @lseek(i32 %46, i32 0, i32 2)
%50 = icmp eq i64 %49, -1
br i1 %50, label %51, label %54
51: ; preds = %48
%52 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.13, i64 0, i64 0))
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %48
%55 = call i32 @close(i32 %46)
br label %56
56: ; preds = %54, %40
%57 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%58 = load i32, i32* %2
%59 = call i32 @check_buf_test(i32 %58, i32 0, i32 0)
%60 = load i32, i32* %2
%61 = load i32, i32* @O_SYNC
%62 = call i32 @check_buf_test(i32 %60, i32 0, i32 %61)
%63 = load i32, i32* %2
%64 = call i32 @check_buf_test(i32 %63, i32 1, i32 0)
%65 = load i32, i32* %2
%66 = load i32, i32* @O_SYNC
%67 = call i32 @check_buf_test(i32 %65, i32 1, i32 %66)
%68 = load i32, i32* %2
%69 = call i32 @check_buf_test(i32 %68, i32 2, i32 0)
%70 = load i32, i32* %2
%71 = load i32, i32* @O_SYNC
%72 = call i32 @check_buf_test(i32 %70, i32 2, i32 %71)
%73 = load i32, i32* %2
%74 = call i32 @check_buf_test(i32 %73, i32 3, i32 0)
%75 = load i32, i32* %2
%76 = load i32, i32* @O_SYNC
%77 = call i32 @check_buf_test(i32 %75, i32 3, i32 %76)
%78 = load i32, i32* %2
%79 = call i32 @check_buf_test(i32 %78, i32 4, i32 0)
%80 = load i32, i32* %2
%81 = load i32, i32* @O_SYNC
%82 = call i32 @check_buf_test(i32 %80, i32 4, i32 %81)
%83 = load i32, i32* %2
%84 = call i32 @check_buf_test(i32 %83, i32 5, i32 0)
%85 = load i32, i32* %2
%86 = load i32, i32* @O_SYNC
%87 = call i32 @check_buf_test(i32 %85, i32 5, i32 %86)
%88 = load i32, i32* %2
%89 = call i32 @check_buf_test(i32 %88, i32 6, i32 0)
%90 = load i32, i32* %2
%91 = load i32, i32* @O_SYNC
%92 = call i32 @check_buf_test(i32 %90, i32 6, i32 %91)
%93 = load i32, i32* %2
%94 = call i32 @check_buf_test(i32 %93, i32 7, i32 0)
%95 = load i32, i32* %2
%96 = load i32, i32* @O_SYNC
%97 = call i32 @check_buf_test(i32 %95, i32 7, i32 %96)
%98 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str.12, i64 0, i64 0))
%99 = load i32, i32* %2
%100 = call i32 @clear_buf_test(i32 %99, i32 0, i32 0)
%101 = load i32, i32* %2
%102 = load i32, i32* @O_SYNC
%103 = call i32 @clear_buf_test(i32 %101, i32 0, i32 %102)
%104 = load i32, i32* %2
%105 = call i32 @clear_buf_test(i32 %104, i32 1, i32 0)
%106 = load i32, i32* %2
%107 = load i32, i32* @O_SYNC
%108 = call i32 @clear_buf_test(i32 %106, i32 1, i32 %107)
%109 = load i32, i32* %2
%110 = call i32 @clear_buf_test(i32 %109, i32 2, i32 0)
%111 = load i32, i32* %2
%112 = load i32, i32* @O_SYNC
%113 = call i32 @clear_buf_test(i32 %111, i32 2, i32 %112)
%114 = load i32, i32* %2
%115 = call i32 @clear_buf_test(i32 %114, i32 3, i32 0)
%116 = load i32, i32* %2
%117 = load i32, i32* @O_SYNC
%118 = call i32 @clear_buf_test(i32 %116, i32 3, i32 %117)
%119 = load i32, i32* %2
%120 = call i32 @clear_buf_test(i32 %119, i32 4, i32 0)
%121 = load i32, i32* %2
%122 = load i32, i32* @O_SYNC
%123 = call i32 @clear_buf_test(i32 %121, i32 4, i32 %122)
%124 = load i32, i32* %2
%125 = call i32 @clear_buf_test(i32 %124, i32 5, i32 0)
%126 = load i32, i32* %2
%127 = load i32, i32* @O_SYNC
%128 = call i32 @clear_buf_test(i32 %126, i32 5, i32 %127)
%129 = load i32, i32* %2
%130 = call i32 @clear_buf_test(i32 %129, i32 6, i32 0)
%131 = load i32, i32* %2
%132 = load i32, i32* @O_SYNC
%133 = call i32 @clear_buf_test(i32 %131, i32 6, i32 %132)
%134 = load i32, i32* %2
%135 = call i32 @clear_buf_test(i32 %134, i32 7, i32 0)
%136 = load i32, i32* %2
%137 = load i32, i32* @O_SYNC
%138 = call i32 @clear_buf_test(i32 %136, i32 7, i32 %137)
ret void
}