#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*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
main(int argc, char *argv[]) {
  int testdev;
  int i;
  char buf[10];
  int pos = 0;
  testdev = open(argv[1], O_RDWR);
  if (testdev == -1) {
    printf("can not open file %s\n", argv[1]);
    exit(0);
  }
  printf("open device %s ok \n", argv[1]);
  pos = lseek(testdev, 0, SEEK_SET);
  read(testdev, buf, 10);
  printf("_______________the buff is  ________\n");
  for (i = 0; i < 10; i++)
    printf("%c", buf[i]);
  printf("\n");
  printf("sizeof(buf)=%d\n", sizeof(buf));
  memset(buf, 0, sizeof(buf));
  pos = lseek(testdev, 0, SEEK_SET);
  write(testdev, "123456", 6);
  pos = lseek(testdev, 0, SEEK_SET);
  read(testdev, buf, 7);
  printf("_______________the  NEW buff is  as follows________\n");
  for (i = 0; i < 10; i++)
    printf("%c", buf[i]);
  printf("\n");
  close(testdev);
}


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)
movl   $0x0,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e3c(%rip),%rax
mov    (%rax),%esi
call   1090 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    11dd <main+0x5d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe31(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <exit@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2ddb(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0xa,%edx
call   1080 <read@plt>
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    125e <main+0xde>
movslq -0x18(%rbp),%rax
movsbl -0x22(%rbp,%rax,1),%esi
lea    0xe07(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    122f <main+0xaf>
lea    0xdc3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xde0(%rip),%rdi
mov    $0xa,%esi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x22(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <memset@plt>
mov    -0x14(%rbp),%edi
mov    0x2d3f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    0xdb4(%rip),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
mov    0x2d15(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x22(%rbp),%rsi
mov    $0x7,%edx
call   1080 <read@plt>
lea    0xd83(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0xa,-0x18(%rbp)
jge    1324 <main+0x1a4>
movslq -0x18(%rbp),%rax
movsbl -0x22(%rbp,%rax,1),%esi
lea    0xd41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    12f5 <main+0x175>
lea    0xcfd(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
call   10b0 <open@plt>
mov    0x8(%rbx),%rsi
cmp    $0xffffffff,%eax
je     1360 <main+0x1c0>
mov    %eax,%ebp
lea    0xe43(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x2df7(%rip),%rbx
mov    (%rbx),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
lea    0x6(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0xa,%edx
call   10a0 <read@plt>
lea    0xe3a(%rip),%rdi
call   1040 <puts@plt>
movsbl 0x6(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x8(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x9(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xa(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xb(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xc(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xd(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xe(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xf(%rsp),%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
lea    0xda9(%rip),%rdi
mov    $0xa,%esi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1080 <memset@plt>
mov    (%rbx),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
lea    0xd8c(%rip),%rsi
mov    %ebp,%edi
mov    $0x6,%edx
call   1050 <write@plt>
mov    (%rbx),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x7,%edx
call   10a0 <read@plt>
lea    0xd8b(%rip),%rdi
call   1040 <puts@plt>
movsbl 0x6(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x7(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x8(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0x9(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xa(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xb(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xc(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xd(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xe(%rsp),%edi
call   1030 <putchar@plt>
movsbl 0xf(%rsp),%edi
call   1030 <putchar@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    %ebp,%edi
call   1090 <close@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xc99(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
xor    %edi,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@O_RDWR = global i32 0
@.str = [22 x i8] c"can not open file %s\0A\00"
@.str.1 = [20 x i8] c"open device %s ok \0A\00"
@SEEK_SET = global i32 0
@.str.2 = [38 x i8] c"_______________the buff is ________\0A\00"
@.str.3 = [3 x i8] c"%c\00"
@.str.4 = [2 x i8] c"\0A\00"
@.str.5 = [16 x i8] c"sizeof(buf)=%d\0A\00"
@.str.6 = [7 x i8] c"123456\00"
@.str.7 = [53 x i8] c"_______________the NEW buff is as follows________\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [10 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %9
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = call i32 @open(i8* %12, i32 %13)
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = icmp eq i32 %15, -1
br i1 %16, label %17, label %23
17: ; preds = %2
%18 = load i8**, i8*** %5
%19 = getelementptr inbounds i8*, i8** %18, i64 1
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %20)
%22 = call i32 @exit(i32 0)
unreachable
23: ; preds = %2
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 1
%26 = load i8*, i8** %25
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %26)
%28 = load i32, i32* %6
%29 = load i32, i32* @SEEK_SET
%30 = call i32 @lseek(i32 %28, i32 0, i32 %29)
store i32 %30, i32* %9
%31 = load i32, i32* %6
%32 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%33 = call i32 @read(i32 %31, i8* %32, i32 10)
%34 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.2, i64 0, i64 0))
store i32 0, i32* %7
br label %35
35: ; preds = %45, %23
%36 = load i32, i32* %7
%37 = icmp slt i32 %36, 10
br i1 %37, label %38, label %48
38: ; preds = %35
%39 = load i32, i32* %7
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %43)
br label %45
45: ; preds = %38
%46 = load i32, i32* %7
%47 = add nsw i32 %46, 1
store i32 %47, i32* %7
br label %35
48: ; preds = %35
%49 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%50 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i64 10)
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%52 = call i32 @memset(i8* %51, i32 0, i32 10)
%53 = load i32, i32* %6
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @lseek(i32 %53, i32 0, i32 %54)
store i32 %55, i32* %9
%56 = load i32, i32* %6
%57 = call i32 @write(i32 %56, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%58 = load i32, i32* %6
%59 = load i32, i32* @SEEK_SET
%60 = call i32 @lseek(i32 %58, i32 0, i32 %59)
store i32 %60, i32* %9
%61 = load i32, i32* %6
%62 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%63 = call i32 @read(i32 %61, i8* %62, i32 7)
%64 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.7, i64 0, i64 0))
store i32 0, i32* %7
br label %65
65: ; preds = %75, %48
%66 = load i32, i32* %7
%67 = icmp slt i32 %66, 10
br i1 %67, label %68, label %78
68: ; preds = %65
%69 = load i32, i32* %7
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32 %73)
br label %75
75: ; preds = %68
%76 = load i32, i32* %7
%77 = add nsw i32 %76, 1
store i32 %77, i32* %7
br label %65
78: ; preds = %65
%79 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%80 = load i32, i32* %6
%81 = call i32 @close(i32 %80)
%82 = load i32, i32* %3
ret i32 %82
}

LLVM IR (-O2):
@O_RDWR = global i32 0
@.str = [22 x i8] c"can not open file %s\0A\00"
@.str.1 = [20 x i8] c"open device %s ok \0A\00"
@SEEK_SET = global i32 0
@.str.5 = [16 x i8] c"sizeof(buf)=%d\0A\00"
@.str.6 = [7 x i8] c"123456\00"
@str = [37 x i8] c"_______________the buff is ________\00"
@str.8 = [52 x i8] c"_______________the NEW buff is as follows________\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [10 x i8]
%4 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 0
%5 = getelementptr inbounds i8*, i8** %1, i64 1
%6 = load i8*, i8** %5
%7 = load i32, i32* @O_RDWR
%8 = tail call i32 @open(i8* %6, i32 %7)
%9 = icmp eq i32 %8, -1
%10 = load i8*, i8** %5
br i1 %9, label %11, label %14
11: ; preds = %2
%12 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @.str, i64 0, i64 0), i8* %10)
%13 = tail call i32 @exit(i32 0)
unreachable
14: ; preds = %2
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0), i8* %10)
%16 = load i32, i32* @SEEK_SET
%17 = tail call i32 @lseek(i32 %8, i32 0, i32 %16)
%18 = call i32 @read(i32 %8, i8* %4, i32 10)
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str, i64 0, i64 0))
%20 = load i8, i8* %4
%21 = sext i8 %20 to i32
%22 = tail call i32 @putchar(i32 %21)
%23 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 1
%24 = load i8, i8* %23
%25 = sext i8 %24 to i32
%26 = tail call i32 @putchar(i32 %25)
%27 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 2
%28 = load i8, i8* %27
%29 = sext i8 %28 to i32
%30 = tail call i32 @putchar(i32 %29)
%31 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 3
%32 = load i8, i8* %31
%33 = sext i8 %32 to i32
%34 = tail call i32 @putchar(i32 %33)
%35 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 4
%36 = load i8, i8* %35
%37 = sext i8 %36 to i32
%38 = tail call i32 @putchar(i32 %37)
%39 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 5
%40 = load i8, i8* %39
%41 = sext i8 %40 to i32
%42 = tail call i32 @putchar(i32 %41)
%43 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 6
%44 = load i8, i8* %43
%45 = sext i8 %44 to i32
%46 = tail call i32 @putchar(i32 %45)
%47 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 7
%48 = load i8, i8* %47
%49 = sext i8 %48 to i32
%50 = tail call i32 @putchar(i32 %49)
%51 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 8
%52 = load i8, i8* %51
%53 = sext i8 %52 to i32
%54 = tail call i32 @putchar(i32 %53)
%55 = getelementptr inbounds [10 x i8], [10 x i8]* %3, i64 0, i64 9
%56 = load i8, i8* %55
%57 = sext i8 %56 to i32
%58 = tail call i32 @putchar(i32 %57)
%59 = tail call i32 @putchar(i32 10)
%60 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.5, i64 0, i64 0), i64 10)
%61 = call i32 @memset(i8* %4, i32 0, i32 10)
%62 = load i32, i32* @SEEK_SET
%63 = call i32 @lseek(i32 %8, i32 0, i32 %62)
%64 = call i32 @write(i32 %8, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i32 6)
%65 = load i32, i32* @SEEK_SET
%66 = call i32 @lseek(i32 %8, i32 0, i32 %65)
%67 = call i32 @read(i32 %8, i8* %4, i32 7)
%68 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([52 x i8], [52 x i8]* @str.8, i64 0, i64 0))
%69 = load i8, i8* %4
%70 = sext i8 %69 to i32
%71 = call i32 @putchar(i32 %70)
%72 = load i8, i8* %23
%73 = sext i8 %72 to i32
%74 = call i32 @putchar(i32 %73)
%75 = load i8, i8* %27
%76 = sext i8 %75 to i32
%77 = call i32 @putchar(i32 %76)
%78 = load i8, i8* %31
%79 = sext i8 %78 to i32
%80 = call i32 @putchar(i32 %79)
%81 = load i8, i8* %35
%82 = sext i8 %81 to i32
%83 = call i32 @putchar(i32 %82)
%84 = load i8, i8* %39
%85 = sext i8 %84 to i32
%86 = call i32 @putchar(i32 %85)
%87 = load i8, i8* %43
%88 = sext i8 %87 to i32
%89 = call i32 @putchar(i32 %88)
%90 = load i8, i8* %47
%91 = sext i8 %90 to i32
%92 = call i32 @putchar(i32 %91)
%93 = load i8, i8* %51
%94 = sext i8 %93 to i32
%95 = call i32 @putchar(i32 %94)
%96 = load i8, i8* %55
%97 = sext i8 %96 to i32
%98 = call i32 @putchar(i32 %97)
%99 = call i32 @putchar(i32 10)
%100 = call i32 @close(i32 %8)
ret i32 0
}