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

/* Variables and functions */
int read_attr(char *, int, int);
unsigned long long strtoull(char *, char **, int /*<<< orphan*/);
unsigned long long read_sync_completed(int fd) {
  unsigned long long val;
  char buf[50];
  int n;
  char *ep;
  n = read_attr(buf, 50, fd);
  if (n <= 0)
    return 0;
  buf[n] = 0;
  val = strtoull(buf, &ep, 0);
  if (ep == buf || (*ep != 0 && *ep != '\n' && *ep != ' '))
    return 0;
  return val;
}


x86 assembly (clang, -O0):
<read_sync_completed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %edi,-0xc(%rbp)
lea    -0x50(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    $0x32,%esi
call   1040 <read_attr@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jg     1156 <read_sync_completed+0x36>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <read_sync_completed+0xa8>
movslq -0x54(%rbp),%rax
movb   $0x0,-0x50(%rbp,%rax,1)
lea    -0x50(%rbp),%rdi
lea    -0x60(%rbp),%rsi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    %rax,-0x18(%rbp)
mov    -0x60(%rbp),%rax
lea    -0x50(%rbp),%rcx
cmp    %rcx,%rax
je     11b3 <read_sync_completed+0x93>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     11c0 <read_sync_completed+0xa0>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0xa,%eax
je     11c0 <read_sync_completed+0xa0>
mov    -0x60(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x20,%eax
je     11c0 <read_sync_completed+0xa0>
movq   $0x0,-0x8(%rbp)
jmp    11c8 <read_sync_completed+0xa8>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_sync_completed>:
push   %r14
push   %rbx
sub    $0x48,%rsp
mov    %edi,%edx
lea    0x10(%rsp),%r14
mov    %r14,%rdi
mov    $0x32,%esi
call   1040 <read_attr@plt>
test   %eax,%eax
jle    1181 <read_sync_completed+0x61>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
lea    0x8(%rsp),%rsi
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %edx,%edx
call   1030 <strtoull@plt>
mov    0x8(%rsp),%rcx
cmp    %r14,%rcx
je     1183 <read_sync_completed+0x63>
movzbl (%rcx),%ecx
xor    %ebx,%ebx
cmp    $0x20,%rcx
ja     1183 <read_sync_completed+0x63>
movabs $0x100000401,%rdx
bt     %rcx,%rdx
jae    1183 <read_sync_completed+0x63>
mov    %rax,%rbx
jmp    1183 <read_sync_completed+0x63>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x48,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
define i64 @read_sync_completed(i32 %0) {
%2 = alloca i64
%3 = alloca i32
%4 = alloca i64
%5 = alloca [50 x i8]
%6 = alloca i32
%7 = alloca i8*
store i32 %0, i32* %3
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%9 = load i32, i32* %3
%10 = call i32 @read_attr(i8* %8, i32 50, i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp sle i32 %11, 0
br i1 %12, label %13, label %14
13: ; preds = %1
store i64 0, i64* %2
br label %41
14: ; preds = %1
%15 = load i32, i32* %6
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%19 = call i64 @strtoull(i8* %18, i8** %7, i32 0)
store i64 %19, i64* %4
%20 = load i8*, i8** %7
%21 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%22 = icmp eq i8* %20, %21
br i1 %22, label %38, label %23
23: ; preds = %14
%24 = load i8*, i8** %7
%25 = load i8, i8* %24
%26 = sext i8 %25 to i32
%27 = icmp ne i32 %26, 0
br i1 %27, label %28, label %39
28: ; preds = %23
%29 = load i8*, i8** %7
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp ne i32 %31, 10
br i1 %32, label %33, label %39
33: ; preds = %28
%34 = load i8*, i8** %7
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 32
br i1 %37, label %38, label %39
38: ; preds = %33, %14
store i64 0, i64* %2
br label %41
39: ; preds = %33, %28, %23
%40 = load i64, i64* %4
store i64 %40, i64* %2
br label %41
41: ; preds = %39, %38, %13
%42 = load i64, i64* %2
ret i64 %42
}

LLVM IR (-O2):
define i64 @read_sync_completed(i32 %0) {
%2 = alloca [50 x i8]
%3 = alloca i8*
%4 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%5 = bitcast i8** %3 to i8*
%6 = call i32 @read_attr(i8* %4, i32 50, i32 %0)
%7 = icmp slt i32 %6, 1
br i1 %7, label %17, label %8
8: ; preds = %1
%9 = zext i32 %6 to i64
%10 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 %9
store i8 0, i8* %10
%11 = call i64 @strtoull(i8* %4, i8** %3, i32 0)
%12 = load i8*, i8** %3
%13 = icmp eq i8* %12, %4
br i1 %13, label %17, label %14
14: ; preds = %8
%15 = load i8, i8* %12
switch i8 %15, label %17 [
i8 0, label %16
i8 10, label %16
i8 32, label %16
]
16: ; preds = %14, %14, %14
br label %17
17: ; preds = %8, %14, %1, %16
%18 = phi i64 [ %11, %16 ], [ 0, %1 ], [ 0, %14 ], [ 0, %8 ]
ret i64 %18
}