#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ strncpy(char *, char *, int);
int add_uuid(char *destination, int maxsize) {
  int uuidf;
  int uuidsize;
  uuidf = open("/sys/devices/virtual/dmi/id/product_uuid", O_RDONLY);
  if (uuidf < 1) {
    return 0;
  }
  strncpy(destination, "/uuid=", maxsize);
  uuidsize = read(uuidf, destination + 6, maxsize - 6);
  close(uuidf);
  if (destination[uuidsize + 5] == '\n') {
    destination[uuidsize + 5] = 0;
  }
  return uuidsize + 6;
}


x86 assembly (clang, -O0):
<add_uuid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e92(%rip),%rax
mov    (%rax),%esi
lea    0xea1(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x1,-0x18(%rbp)
jge    117d <add_uuid+0x3d>
movl   $0x0,-0x4(%rbp)
jmp    11e5 <add_uuid+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%edx
lea    0xe9e(%rip),%rsi
call   1030 <strncpy@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
add    $0x6,%rsi
mov    -0x14(%rbp),%edx
sub    $0x6,%edx
call   1050 <read@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    11dc <add_uuid+0x9c>
mov    -0x10(%rbp),%rax
mov    -0x1c(%rbp),%ecx
add    $0x5,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x1c(%rbp),%eax
add    $0x6,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_uuid>:
push   %rbp
push   %r14
push   %rbx
mov    %esi,%ebp
mov    %rdi,%r14
mov    0x2e98(%rip),%rax
mov    (%rax),%esi
lea    0xea7(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
jle    11a4 <add_uuid+0x64>
mov    %eax,%ebx
lea    0xebe(%rip),%rsi
mov    %r14,%rdi
mov    %ebp,%edx
call   1030 <strncpy@plt>
lea    0x6(%r14),%rsi
add    $0xfffffffa,%ebp
mov    %ebx,%edi
mov    %ebp,%edx
call   1050 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1040 <close@plt>
movslq %ebp,%rax
cmpb   $0xa,0x5(%rax,%r14,1)
jne    119f <add_uuid+0x5f>
movb   $0x0,0x5(%r14,%rax,1)
add    $0x6,%ebp
jmp    11a6 <add_uuid+0x66>
xor    %ebp,%ebp
mov    %ebp,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [41 x i8] c"/sys/devices/virtual/dmi/id/product_uuid\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"/uuid=\00"
define i32 @add_uuid(i8* %0, i32 %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %6
%10 = load i32, i32* %6
%11 = icmp slt i32 %10, 1
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %42
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = load i32, i32* %5
%16 = call i32 @strncpy(i8* %14, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %15)
%17 = load i32, i32* %6
%18 = load i8*, i8** %4
%19 = getelementptr inbounds i8, i8* %18, i64 6
%20 = load i32, i32* %5
%21 = sub nsw i32 %20, 6
%22 = call i32 @read(i32 %17, i8* %19, i32 %21)
store i32 %22, i32* %7
%23 = load i32, i32* %6
%24 = call i32 @close(i32 %23)
%25 = load i8*, i8** %4
%26 = load i32, i32* %7
%27 = add nsw i32 %26, 5
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %25, i64 %28
%30 = load i8, i8* %29
%31 = sext i8 %30 to i32
%32 = icmp eq i32 %31, 10
br i1 %32, label %33, label %39
33: ; preds = %13
%34 = load i8*, i8** %4
%35 = load i32, i32* %7
%36 = add nsw i32 %35, 5
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %34, i64 %37
store i8 0, i8* %38
br label %39
39: ; preds = %33, %13
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 6
store i32 %41, i32* %3
br label %42
42: ; preds = %39, %12
%43 = load i32, i32* %3
ret i32 %43
}

LLVM IR (-O2):
@.str = [41 x i8] c"/sys/devices/virtual/dmi/id/product_uuid\00"
@O_RDONLY = global i32 0
@.str.1 = [7 x i8] c"/uuid=\00"
define i32 @add_uuid(i8* %0, i32 %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 1
br i1 %5, label %20, label %6
6: ; preds = %2
%7 = tail call i32 @strncpy(i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i32 %1)
%8 = getelementptr inbounds i8, i8* %0, i64 6
%9 = add nsw i32 %1, -6
%10 = tail call i32 @read(i32 %4, i8* %8, i32 %9)
%11 = tail call i32 @close(i32 %4)
%12 = add nsw i32 %10, 5
%13 = sext i32 %12 to i64
%14 = getelementptr inbounds i8, i8* %0, i64 %13
%15 = load i8, i8* %14
%16 = icmp eq i8 %15, 10
br i1 %16, label %17, label %18
17: ; preds = %6
store i8 0, i8* %14
br label %18
18: ; preds = %17, %6
%19 = add nsw i32 %10, 6
br label %20
20: ; preds = %2, %18
%21 = phi i32 [ %19, %18 ], [ 0, %2 ]
ret i32 %21
}