#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 open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ strcat(char *, char const *);
int /*<<< orphan*/ strcpy(char *, char const *);
int strlen(char *);
int /*<<< orphan*/ tidyStringUp(char *);
void addDeviceInfo(char *out, int *pOutLen, const char device[],
                   const char property[]) {
  char source[256];
  char buf[256];
  out[*pOutLen] = 0;
  strcpy(source, device);
  strcat(source, property);
  int f = open(source, 0);
  if (f == -1)
    return;
  int len = read(f, buf, 256);
  if (len <= 0)
    return;
  *pOutLen += len;
  buf[len - 1] = 0;
  strcat(out, (const char *)buf);
  tidyStringUp(out);
  *pOutLen = strlen(out) + 1;
}


x86 assembly (clang, -O0):
<addDeviceInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x230,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
movb   $0x0,(%rax,%rcx,1)
lea    -0x120(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1040 <strcpy@plt>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strcat@plt>
lea    -0x120(%rbp),%rdi
xor    %esi,%esi
call   1070 <open@plt>
mov    %eax,-0x224(%rbp)
cmpl   $0xffffffff,-0x224(%rbp)
jne    11d0 <addDeviceInfo+0x70>
jmp    124d <addDeviceInfo+0xed>
mov    -0x224(%rbp),%edi
lea    -0x220(%rbp),%rsi
mov    $0x100,%edx
call   1060 <read@plt>
mov    %eax,-0x228(%rbp)
cmpl   $0x0,-0x228(%rbp)
jg     11ff <addDeviceInfo+0x9f>
jmp    124d <addDeviceInfo+0xed>
mov    -0x228(%rbp),%ecx
mov    -0x10(%rbp),%rax
add    (%rax),%ecx
mov    %ecx,(%rax)
mov    -0x228(%rbp),%eax
sub    $0x1,%eax
cltq
movb   $0x0,-0x220(%rbp,%rax,1)
mov    -0x8(%rbp),%rdi
lea    -0x220(%rbp),%rsi
call   1080 <strcat@plt>
mov    -0x8(%rbp),%rdi
call   1030 <tidyStringUp@plt>
mov    -0x8(%rbp),%rdi
call   1050 <strlen@plt>
mov    %eax,%ecx
add    $0x1,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x230,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<addDeviceInfo>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x208,%rsp
mov    %rcx,%r12
mov    %rsi,%r14
mov    %rdi,%r15
movslq (%rsi),%rax
movb   $0x0,(%rdi,%rax,1)
lea    0x100(%rsp),%rbx
mov    %rbx,%rdi
mov    %rdx,%rsi
call   1040 <strcpy@plt>
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strcat@plt>
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <open@plt>
cmp    $0xffffffff,%eax
je     11e9 <addDeviceInfo+0x89>
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1060 <read@plt>
test   %eax,%eax
jle    11e9 <addDeviceInfo+0x89>
add    %eax,(%r14)
add    $0xffffffff,%eax
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rsi
mov    %r15,%rdi
call   1080 <strcat@plt>
mov    %r15,%rdi
call   1030 <tidyStringUp@plt>
mov    %r15,%rdi
call   1050 <strlen@plt>
add    $0x1,%eax
mov    %eax,(%r14)
add    $0x208,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define void @addDeviceInfo(i8* %0, i32* %1, i8* %2, i8* %3) {
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca [256 x i8]
%11 = alloca i32
%12 = alloca i32
store i8* %0, i8** %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8* %3, i8** %8
%13 = load i8*, i8** %5
%14 = load i32*, i32** %6
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = getelementptr inbounds i8, i8* %13, i64 %16
store i8 0, i8* %17
%18 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%19 = load i8*, i8** %7
%20 = call i32 @strcpy(i8* %18, i8* %19)
%21 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%22 = load i8*, i8** %8
%23 = call i32 @strcat(i8* %21, i8* %22)
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%25 = call i32 @open(i8* %24, i32 0)
store i32 %25, i32* %11
%26 = load i32, i32* %11
%27 = icmp eq i32 %26, -1
br i1 %27, label %28, label %29
28: ; preds = %4
br label %54
29: ; preds = %4
%30 = load i32, i32* %11
%31 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%32 = call i32 @read(i32 %30, i8* %31, i32 256)
store i32 %32, i32* %12
%33 = load i32, i32* %12
%34 = icmp sle i32 %33, 0
br i1 %34, label %35, label %36
35: ; preds = %29
br label %54
36: ; preds = %29
%37 = load i32, i32* %12
%38 = load i32*, i32** %6
%39 = load i32, i32* %38
%40 = add nsw i32 %39, %37
store i32 %40, i32* %38
%41 = load i32, i32* %12
%42 = sub nsw i32 %41, 1
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 %43
store i8 0, i8* %44
%45 = load i8*, i8** %5
%46 = getelementptr inbounds [256 x i8], [256 x i8]* %10, i64 0, i64 0
%47 = call i32 @strcat(i8* %45, i8* %46)
%48 = load i8*, i8** %5
%49 = call i32 @tidyStringUp(i8* %48)
%50 = load i8*, i8** %5
%51 = call i32 @strlen(i8* %50)
%52 = add nsw i32 %51, 1
%53 = load i32*, i32** %6
store i32 %52, i32* %53
br label %54
54: ; preds = %36, %35, %28
ret void
}

LLVM IR (-O2):
define void @addDeviceInfo(i8* %0, i32* nocapture %1, i8* %2, i8* %3) {
%5 = alloca [256 x i8]
%6 = alloca [256 x i8]
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %5, i64 0, i64 0
%8 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 0
%9 = load i32, i32* %1
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %0, i64 %10
store i8 0, i8* %11
%12 = call i32 @strcpy(i8* %7, i8* %2)
%13 = call i32 @strcat(i8* %7, i8* %3)
%14 = call i32 @open(i8* %7, i32 0)
%15 = icmp eq i32 %14, -1
br i1 %15, label %29, label %16
16: ; preds = %4
%17 = call i32 @read(i32 %14, i8* %8, i32 256)
%18 = icmp slt i32 %17, 1
br i1 %18, label %29, label %19
19: ; preds = %16
%20 = load i32, i32* %1
%21 = add nsw i32 %20, %17
store i32 %21, i32* %1
%22 = add nsw i32 %17, -1
%23 = zext i32 %22 to i64
%24 = getelementptr inbounds [256 x i8], [256 x i8]* %6, i64 0, i64 %23
store i8 0, i8* %24
%25 = call i32 @strcat(i8* %0, i8* %8)
%26 = call i32 @tidyStringUp(i8* %0)
%27 = call i32 @strlen(i8* %0)
%28 = add nsw i32 %27, 1
store i32 %28, i32* %1
br label %29
29: ; preds = %19, %16, %4
ret void
}