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

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int ioctl(int, int, int /*<<< orphan*/);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int read(int, unsigned char *, int);
int /*<<< orphan*/ strlen(unsigned char *);
int write(int, unsigned char *, int /*<<< orphan*/);
int main() {
  int fp, ret;
  unsigned char ch[10] = "hello";
  ch[5] = '\0';
  fp = open("/dev/mycdev", O_RDWR);
  printf("fp数值:%d\n", fp);
  ret = ioctl(fp, 0, 0);
  printf("控制0返回 : %d\n", ret);
  ret = ioctl(fp, 1, 0);
  printf("控制1返回 : %d\n", ret);
  ret = write(fp, ch, strlen(ch));
  printf("写入返回 : %d\n", ret);
  unsigned char ch2[3] = "\0";
  ret = lseek(fp, 0, 0);
  printf("新指针位置 : %d\n", ret);
  ret = read(fp, ch2, sizeof(ch2) - 1);
  printf("读出字符数 : %d\n", ret);
  printf("读到数据 :%s\n", ch2);
  ret = read(fp, ch2, sizeof(ch2) - 1);
  printf("读出字符数 : %d\n", ret);
  printf("读到数据 :%s\n", ch2);
  close(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    0xe5a(%rip),%rax
mov    %rax,-0x16(%rbp)
mov    0xe57(%rip),%ax
mov    %ax,-0xe(%rbp)
movb   $0x0,-0x11(%rbp)
mov    0x2e28(%rip),%rax
mov    (%rax),%esi
lea    0xe41(%rip),%rdi
call   10b0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe3b(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1080 <ioctl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe28(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1080 <ioctl@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x2c(%rbp)
lea    -0x16(%rbp),%rax
mov    %rax,-0x28(%rbp)
lea    -0x16(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x2c(%rbp),%edi
mov    -0x28(%rbp),%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x19(%rbp),%rdi
xor    %esi,%esi
mov    $0x3,%edx
call   1070 <memset@plt>
mov    -0x8(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1060 <lseek@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdd7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x2,%edx
call   10a0 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xdc8(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x19(%rbp),%rsi
lea    0xdcc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
lea    -0x19(%rbp),%rsi
mov    $0x2,%edx
call   10a0 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xd91(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0x19(%rbp),%rsi
lea    0xd95(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
movabs $0x6f6c6c6568,%rax
mov    %rax,0x8(%rsp)
movw   $0x0,0x10(%rsp)
movb   $0x0,0xd(%rsp)
mov    0x2e3b(%rip),%rax
mov    (%rax),%esi
lea    0xe54(%rip),%rdi
call   10a0 <open@plt>
mov    %eax,%ebx
lea    0xe52(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <ioctl@plt>
lea    0xe44(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
mov    $0x1,%esi
xor    %edx,%edx
call   1070 <ioctl@plt>
lea    0xe3a(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x8(%rsp),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <write@plt>
lea    0xe25(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
movb   $0x0,0x6(%rsp)
movw   $0x0,0x4(%rsp)
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1060 <lseek@plt>
lea    0xe11(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0x4(%rsp),%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1090 <read@plt>
lea    0xe03(%rip),%r15
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
lea    0xe06(%rip),%r12
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x2,%edx
call   1090 <read@plt>
mov    %r15,%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %ebx,%edi
call   1080 <close@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@__const.main.ch = [10 x i8] c"hello\00\00\00\00\00"
@.str = [12 x i8] c"/dev/mycdev\00"
@O_RDWR = global i32 0
@.str.1 = [13 x i8] c"fp\E6\95\B0\E5\80\BC:%d\0A\00"
@.str.2 = [20 x i8] c"\E6\8E\A7\E5\88\B60\E8\BF\94\E5\9B\9E : %d\0A\00"
@.str.3 = [20 x i8] c"\E6\8E\A7\E5\88\B61\E8\BF\94\E5\9B\9E : %d\0A\00"
@.str.4 = [19 x i8] c"\E5\86\99\E5\85\A5\E8\BF\94\E5\9B\9E : %d\0A\00"
@.str.5 = [22 x i8] c"\E6\96\B0\E6\8C\87\E9\92\88\E4\BD\8D\E7\BD\AE : %d\0A\00"
@.str.6 = [22 x i8] c"\E8\AF\BB\E5\87\BA\E5\AD\97\E7\AC\A6\E6\95\B0 : %d\0A\00"
@.str.7 = [18 x i8] c"\E8\AF\BB\E5\88\B0\E6\95\B0\E6\8D\AE :%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [10 x i8]
%5 = alloca [3 x i8]
store i32 0, i32* %1
%6 = bitcast [10 x i8]* %4 to i8*
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 5
store i8 0, i8* %7
%8 = load i32, i32* @O_RDWR
%9 = call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %2
%10 = load i32, i32* %2
%11 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %10)
%12 = load i32, i32* %2
%13 = call i32 @ioctl(i32 %12, i32 0, i32 0)
store i32 %13, i32* %3
%14 = load i32, i32* %3
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %2
%17 = call i32 @ioctl(i32 %16, i32 1, i32 0)
store i32 %17, i32* %3
%18 = load i32, i32* %3
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %18)
%20 = load i32, i32* %2
%21 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%22 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%23 = call i32 @strlen(i8* %22)
%24 = call i32 @write(i32 %20, i8* %21, i32 %23)
store i32 %24, i32* %3
%25 = load i32, i32* %3
%26 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %25)
%27 = bitcast [3 x i8]* %5 to i8*
%28 = load i32, i32* %2
%29 = call i32 @lseek(i32 %28, i32 0, i32 0)
store i32 %29, i32* %3
%30 = load i32, i32* %3
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %30)
%32 = load i32, i32* %2
%33 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%34 = call i32 @read(i32 %32, i8* %33, i32 2)
store i32 %34, i32* %3
%35 = load i32, i32* %3
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %35)
%37 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%38 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %37)
%39 = load i32, i32* %2
%40 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%41 = call i32 @read(i32 %39, i8* %40, i32 2)
store i32 %41, i32* %3
%42 = load i32, i32* %3
%43 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %42)
%44 = getelementptr inbounds [3 x i8], [3 x i8]* %5, i64 0, i64 0
%45 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %44)
%46 = load i32, i32* %2
%47 = call i32 @close(i32 %46)
ret i32 0
}

LLVM IR (-O2):
@__const.main.ch = [10 x i8] c"hello\00\00\00\00\00"
@.str = [12 x i8] c"/dev/mycdev\00"
@O_RDWR = global i32 0
@.str.1 = [13 x i8] c"fp\E6\95\B0\E5\80\BC:%d\0A\00"
@.str.2 = [20 x i8] c"\E6\8E\A7\E5\88\B60\E8\BF\94\E5\9B\9E : %d\0A\00"
@.str.3 = [20 x i8] c"\E6\8E\A7\E5\88\B61\E8\BF\94\E5\9B\9E : %d\0A\00"
@.str.4 = [19 x i8] c"\E5\86\99\E5\85\A5\E8\BF\94\E5\9B\9E : %d\0A\00"
@.str.5 = [22 x i8] c"\E6\96\B0\E6\8C\87\E9\92\88\E4\BD\8D\E7\BD\AE : %d\0A\00"
@.str.6 = [22 x i8] c"\E8\AF\BB\E5\87\BA\E5\AD\97\E7\AC\A6\E6\95\B0 : %d\0A\00"
@.str.7 = [18 x i8] c"\E8\AF\BB\E5\88\B0\E6\95\B0\E6\8D\AE :%s\0A\00"
define i32 @main() {
%1 = alloca [10 x i8]
%2 = alloca [3 x i8]
%3 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %1, i64 0, i64 5
store i8 0, i8* %4
%5 = load i32, i32* @O_RDWR
%6 = tail call i32 @open(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0), i32 %6)
%8 = tail call i32 @ioctl(i32 %6, i32 0, i32 0)
%9 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %8)
%10 = tail call i32 @ioctl(i32 %6, i32 1, i32 0)
%11 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.3, i64 0, i64 0), i32 %10)
%12 = call i32 @strlen(i8* %3)
%13 = call i32 @write(i32 %6, i8* %3, i32 %12)
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.4, i64 0, i64 0), i32 %13)
%15 = getelementptr inbounds [3 x i8], [3 x i8]* %2, i64 0, i64 0
%16 = call i32 @lseek(i32 %6, i32 0, i32 0)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0), i32 %16)
%18 = call i32 @read(i32 %6, i8* %15, i32 2)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %18)
%20 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %15)
%21 = call i32 @read(i32 %6, i8* %15, i32 2)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str.6, i64 0, i64 0), i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i64 0, i64 0), i8* %15)
%24 = call i32 @close(i32 %6)
ret i32 0
}