#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 time_t;
typedef int /*<<< orphan*/ ntp;

/* Variables and functions */
int O_RDWR;
int O_SYNC;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ read(int, int *, int);
time_t get_ntpsynctime(void) {
  time_t ntp = 0;
  int fd = 0;
  fd = open("/dev/mtd/5", O_RDWR | O_SYNC);
  if (0 > fd) {
    printf("potval: open mtd POT error!\n");
    ntp = 0xffffffff;
  } else {
    lseek(fd, 2048, SEEK_SET);
    read(fd, &ntp, sizeof(ntp));
    close(fd);
  }
  return ntp;
}


x86 assembly (clang, -O0):
<get_ntpsynctime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
mov    0x2e7b(%rip),%rax
mov    (%rax),%esi
mov    0x2e6a(%rip),%rax
or     (%rax),%esi
lea    0xe81(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x8(%rbp)
xor    %eax,%eax
cmp    -0x8(%rbp),%eax
jle    11aa <get_ntpsynctime+0x5a>
lea    0xe72(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11d9 <get_ntpsynctime+0x89>
mov    -0x8(%rbp),%edi
mov    0x2e1c(%rip),%rax
mov    (%rax),%edx
mov    $0x800,%esi
call   1040 <lseek@plt>
mov    -0x8(%rbp),%edi
lea    -0x4(%rbp),%rsi
mov    $0x4,%edx
call   1060 <read@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_ntpsynctime>:
push   %rbx
sub    $0x10,%rsp
movl   $0x0,0xc(%rsp)
mov    0x2e84(%rip),%rax
mov    0x2e75(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe8a(%rip),%rdi
call   1070 <open@plt>
test   %eax,%eax
js     11b4 <get_ntpsynctime+0x64>
mov    %eax,%ebx
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
mov    $0x800,%esi
call   1040 <lseek@plt>
lea    0xc(%rsp),%rsi
mov    %ebx,%edi
mov    $0x4,%edx
call   1060 <read@plt>
mov    %ebx,%edi
call   1050 <close@plt>
mov    0xc(%rsp),%eax
jmp    11c5 <get_ntpsynctime+0x75>
lea    0xe50(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [11 x i8] c"/dev/mtd/5\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@.str.1 = [29 x i8] c"potval: open mtd POT error!\0A\00"
@SEEK_SET = global i32 0
define i32 @get_ntpsynctime() {
%1 = alloca i32
%2 = alloca i32
store i32 0, i32* %1
store i32 0, i32* %2
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_SYNC
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
store i32 %6, i32* %2
%7 = load i32, i32* %2
%8 = icmp sgt i32 0, %7
br i1 %8, label %9, label %11
9: ; preds = %0
%10 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %1
br label %19
11: ; preds = %0
%12 = load i32, i32* %2
%13 = load i32, i32* @SEEK_SET
%14 = call i32 @lseek(i32 %12, i32 2048, i32 %13)
%15 = load i32, i32* %2
%16 = call i32 @read(i32 %15, i32* %1, i32 4)
%17 = load i32, i32* %2
%18 = call i32 @close(i32 %17)
br label %19
19: ; preds = %11, %9
%20 = load i32, i32* %1
ret i32 %20
}

LLVM IR (-O2):
@.str = [11 x i8] c"/dev/mtd/5\00"
@O_RDWR = global i32 0
@O_SYNC = global i32 0
@SEEK_SET = global i32 0
@str = [28 x i8] c"potval: open mtd POT error!\00"
define i32 @get_ntpsynctime() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
store i32 0, i32* %1
%3 = load i32, i32* @O_RDWR
%4 = load i32, i32* @O_SYNC
%5 = or i32 %4, %3
%6 = tail call i32 @open(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([28 x i8], [28 x i8]* @str, i64 0, i64 0))
br label %16
10: ; preds = %0
%11 = load i32, i32* @SEEK_SET
%12 = tail call i32 @lseek(i32 %6, i32 2048, i32 %11)
%13 = call i32 @read(i32 %6, i32* %1, i32 4)
%14 = tail call i32 @close(i32 %6)
%15 = load i32, i32* %1
br label %16
16: ; preds = %10, %8
%17 = phi i32 [ %15, %10 ], [ -1, %8 ]
ret i32 %17
}