#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 uint64_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int EINVAL;
int htonll(int);
char *strsep(char **, char *);
int strtoul(char *, int /*<<< orphan*/, int);
int sys_read_string(char *, char *, char *, int);
int sys_read_guid(char *dir_name, char *file_name, uint64_t *net_guid) {
  char buf[32], *str, *s;
  uint64_t guid;
  int r, i;
  if ((r = sys_read_string(dir_name, file_name, buf, sizeof(buf))) < 0)
    return r;
  guid = 0;
  for (s = buf, i = 0; i < 4; i++) {
    if (!(str = strsep(&s, ": \t\n")))
      return -EINVAL;
    guid = (guid << 16) | (strtoul(str, 0, 16) & 0xffff);
  }
  *net_guid = htonll(guid);
  return 0;
}


x86 assembly (clang, -O0):
<sys_read_guid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x18(%rbp),%rsi
lea    -0x40(%rbp),%rdx
mov    $0x20,%ecx
call   1050 <sys_read_string@plt>
mov    %eax,-0x58(%rbp)
cmp    $0x0,%eax
jge    1181 <sys_read_guid+0x41>
mov    -0x58(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <sys_read_guid+0xe0>
movl   $0x0,-0x54(%rbp)
lea    -0x40(%rbp),%rax
mov    %rax,-0x50(%rbp)
movl   $0x0,-0x5c(%rbp)
cmpl   $0x4,-0x5c(%rbp)
jge    1209 <sys_read_guid+0xc9>
lea    -0x50(%rbp),%rdi
lea    0xe54(%rip),%rsi
call   1030 <strsep@plt>
mov    %rax,-0x48(%rbp)
cmp    $0x0,%rax
jne    11d2 <sys_read_guid+0x92>
xor    %eax,%eax
mov    0x2e18(%rip),%rcx
sub    (%rcx),%eax
mov    %eax,-0x4(%rbp)
jmp    1220 <sys_read_guid+0xe0>
mov    -0x54(%rbp),%eax
shl    $0x10,%eax
mov    %eax,-0x60(%rbp)
mov    -0x48(%rbp),%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,%ecx
mov    -0x60(%rbp),%eax
and    $0xffff,%ecx
or     %ecx,%eax
mov    %eax,-0x54(%rbp)
mov    -0x5c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x5c(%rbp)
jmp    1197 <sys_read_guid+0x57>
mov    -0x54(%rbp),%edi
call   1060 <htonll@plt>
mov    %eax,%ecx
mov    -0x20(%rbp),%rax
mov    %ecx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_read_guid>:
push   %rbp
push   %r14
push   %rbx
sub    $0x30,%rsp
mov    %rdx,%r14
lea    0x10(%rsp),%rbx
mov    %rbx,%rdx
mov    $0x20,%ecx
call   1050 <sys_read_string@plt>
test   %eax,%eax
js     1225 <sys_read_guid+0xe5>
mov    %rbx,0x8(%rsp)
lea    0xe8f(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <strsep@plt>
test   %rax,%rax
je     1218 <sys_read_guid+0xd8>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
lea    0xe66(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <strsep@plt>
test   %rax,%rax
je     1218 <sys_read_guid+0xd8>
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
lea    0xe41(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <strsep@plt>
test   %rax,%rax
je     1218 <sys_read_guid+0xd8>
xor    %ebp,%ebp
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
mov    %eax,%ebx
lea    0xe18(%rip),%rsi
lea    0x8(%rsp),%rdi
call   1030 <strsep@plt>
test   %rax,%rax
je     1218 <sys_read_guid+0xd8>
shl    $0x10,%ebx
mov    %rax,%rdi
xor    %esi,%esi
mov    $0x10,%edx
call   1040 <strtoul@plt>
movzwl %ax,%edi
or     %ebx,%edi
call   1060 <htonll@plt>
mov    %eax,(%r14)
jmp    1227 <sys_read_guid+0xe7>
mov    0x2dc1(%rip),%rax
xor    %ebp,%ebp
sub    (%rax),%ebp
jmp    1227 <sys_read_guid+0xe7>
mov    %eax,%ebp
mov    %ebp,%eax
add    $0x30,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [5 x i8] c": \09\0A\00"
@EINVAL = global i32 0
define i32 @sys_read_guid(i8* %0, i8* %1, i32* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8*
%7 = alloca i32*
%8 = alloca [32 x i8]
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %5
store i8* %1, i8** %6
store i32* %2, i32** %7
%14 = load i8*, i8** %5
%15 = load i8*, i8** %6
%16 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
%17 = call i32 @sys_read_string(i8* %14, i8* %15, i8* %16, i32 32)
store i32 %17, i32* %12
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %3
%20 = load i32, i32* %12
store i32 %20, i32* %4
br label %46
21: ; preds = %3
store i32 0, i32* %11
%22 = getelementptr inbounds [32 x i8], [32 x i8]* %8, i64 0, i64 0
store i8* %22, i8** %10
store i32 0, i32* %13
br label %23
23: ; preds = %39, %21
%24 = load i32, i32* %13
%25 = icmp slt i32 %24, 4
br i1 %25, label %26, label %42
26: ; preds = %23
%27 = call i8* @strsep(i8** %10, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i8* %27, i8** %9
%28 = icmp ne i8* %27, null
br i1 %28, label %32, label %29
29: ; preds = %26
%30 = load i32, i32* @EINVAL
%31 = sub nsw i32 0, %30
store i32 %31, i32* %4
br label %46
32: ; preds = %26
%33 = load i32, i32* %11
%34 = shl i32 %33, 16
%35 = load i8*, i8** %9
%36 = call i32 @strtoul(i8* %35, i32 0, i32 16)
%37 = and i32 %36, 65535
%38 = or i32 %34, %37
store i32 %38, i32* %11
br label %39
39: ; preds = %32
%40 = load i32, i32* %13
%41 = add nsw i32 %40, 1
store i32 %41, i32* %13
br label %23
42: ; preds = %23
%43 = load i32, i32* %11
%44 = call i32 @htonll(i32 %43)
%45 = load i32*, i32** %7
store i32 %44, i32* %45
store i32 0, i32* %4
br label %46
46: ; preds = %42, %29, %19
%47 = load i32, i32* %4
ret i32 %47
}

LLVM IR (-O2):
@.str = [5 x i8] c": \09\0A\00"
@EINVAL = global i32 0
define i32 @sys_read_guid(i8* %0, i8* %1, i32* nocapture writeonly %2) {
%4 = alloca [32 x i8]
%5 = alloca i8*
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%7 = bitcast i8** %5 to i8*
%8 = call i32 @sys_read_string(i8* %0, i8* %1, i8* %6, i32 32)
%9 = icmp slt i32 %8, 0
br i1 %9, label %34, label %10
10: ; preds = %3
store i8* %6, i8** %5
%11 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %24, %20, %16, %10
%14 = load i32, i32* @EINVAL
%15 = sub nsw i32 0, %14
br label %34
16: ; preds = %10
%17 = call i32 @strtoul(i8* %11, i32 0, i32 16)
%18 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%19 = icmp eq i8* %18, null
br i1 %19, label %13, label %20
20: ; preds = %16
%21 = call i32 @strtoul(i8* %18, i32 0, i32 16)
%22 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = icmp eq i8* %22, null
br i1 %23, label %13, label %24
24: ; preds = %20
%25 = call i32 @strtoul(i8* %22, i32 0, i32 16)
%26 = call i8* @strsep(i8** %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%27 = icmp eq i8* %26, null
br i1 %27, label %13, label %28
28: ; preds = %24
%29 = shl i32 %25, 16
%30 = call i32 @strtoul(i8* %26, i32 0, i32 16)
%31 = and i32 %30, 65535
%32 = or i32 %31, %29
%33 = call i32 @htonll(i32 %32)
store i32 %33, i32* %2
br label %34
34: ; preds = %3, %28, %13
%35 = phi i32 [ %15, %13 ], [ 0, %28 ], [ %8, %3 ]
ret i32 %35
}