#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*/ addDeviceInfo(char *, int *, char const *, char *);
int /*<<< orphan*/ strcat(char *, char *);
int strlen(char *);
char *strrchr(char const *, char);
int /*<<< orphan*/ tidyStringUp(char *);
void getDeviceInfo(char *out, int *pOutLen, const char device[]) {
  int i;
  char *p;
  char strModel[256];
  int intModelLen = 0;
  for (i = 0; i < 2; i++) {
    p = strrchr(device, '/');
    *p = 0;
  }
  addDeviceInfo(strModel, &intModelLen, device, "/model");
  for (i = 0; i < 4; i++) {
    p = strrchr(device, '/');
    *p = 0;
  }
  addDeviceInfo(out, pOutLen, device, "/manufacturer");
  if (pOutLen > 0)
    out[*pOutLen - 1] = ' ';
  addDeviceInfo(out, pOutLen, device, "/product");
  if (pOutLen > 0)
    out[*pOutLen - 1] = ' ';
  addDeviceInfo(out, pOutLen, device, "/serial");
  if (pOutLen <= 0)
    return;
  tidyStringUp(out);
  tidyStringUp(strModel);
  if (strlen(strModel) != 0) {
    if ((strlen(strModel) + strlen(out) + 2) >= 256) {
      out[256 - strlen(strModel) - 2] = 0;
    }
    strcat(out, " ");
    strcat(out, strModel);
  }
}


x86 assembly (clang, -O0):
<getDeviceInfo>:
push   %rbp
mov    %rsp,%rbp
sub    $0x140,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x134(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2,-0x1c(%rbp)
jge    11a9 <getDeviceInfo+0x59>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1178 <getDeviceInfo+0x28>
lea    -0x130(%rbp),%rdi
mov    -0x18(%rbp),%rdx
lea    -0x134(%rbp),%rsi
lea    0xe3e(%rip),%rcx
call   1060 <addDeviceInfo@plt>
movl   $0x0,-0x1c(%rbp)
cmpl   $0x4,-0x1c(%rbp)
jge    11ff <getDeviceInfo+0xaf>
mov    -0x18(%rbp),%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movb   $0x0,(%rax)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ce <getDeviceInfo+0x7e>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdf5(%rip),%rcx
call   1060 <addDeviceInfo@plt>
cmpq   $0x0,-0x10(%rbp)
jbe    1236 <getDeviceInfo+0xe6>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xdcc(%rip),%rcx
call   1060 <addDeviceInfo@plt>
cmpq   $0x0,-0x10(%rbp)
jbe    126d <getDeviceInfo+0x11d>
mov    -0x8(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x20,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
lea    0xd9e(%rip),%rcx
call   1060 <addDeviceInfo@plt>
cmpq   $0x0,-0x10(%rbp)
ja     1295 <getDeviceInfo+0x145>
jmp    1343 <getDeviceInfo+0x1f3>
mov    -0x8(%rbp),%rdi
call   1030 <tidyStringUp@plt>
lea    -0x130(%rbp),%rdi
call   1030 <tidyStringUp@plt>
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x0,%eax
je     1343 <getDeviceInfo+0x1f3>
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x138(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x138(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cmp    $0x100,%eax
jl     1323 <getDeviceInfo+0x1d3>
mov    -0x8(%rbp),%rax
mov    %rax,-0x140(%rbp)
lea    -0x130(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%edx
mov    -0x140(%rbp),%rax
mov    $0x100,%ecx
sub    %edx,%ecx
sub    $0x2,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x8(%rbp),%rdi
lea    0xcf8(%rip),%rsi
call   1070 <strcat@plt>
mov    -0x8(%rbp),%rdi
lea    -0x130(%rbp),%rsi
call   1070 <strcat@plt>
add    $0x140,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getDeviceInfo>:
push   %r15
push   %r14
push   %rbx
sub    $0x110,%rsp
mov    %rdx,%rbx
mov    %rsi,%r15
mov    %rdi,%r14
movl   $0x0,0xc(%rsp)
mov    %rdx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
lea    0xe6c(%rip),%rcx
lea    0x10(%rsp),%rdi
lea    0xc(%rsp),%rsi
mov    %rbx,%rdx
call   1060 <addDeviceInfo@plt>
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
mov    %rbx,%rdi
mov    $0x2f,%esi
call   1050 <strrchr@plt>
movb   $0x0,(%rax)
lea    0xe1a(%rip),%rcx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <addDeviceInfo@plt>
test   %r15,%r15
je     12b5 <getDeviceInfo+0x165>
movslq (%r15),%rax
movb   $0x20,-0x1(%rax,%r14,1)
lea    0xe01(%rip),%rcx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <addDeviceInfo@plt>
movslq (%r15),%rax
movb   $0x20,-0x1(%rax,%r14,1)
lea    0xdec(%rip),%rcx
mov    %r14,%rdi
mov    %r15,%rsi
mov    %rbx,%rdx
call   1060 <addDeviceInfo@plt>
mov    %r14,%rdi
call   1030 <tidyStringUp@plt>
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
call   1030 <tidyStringUp@plt>
mov    %rbx,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     12dd <getDeviceInfo+0x18d>
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
cmp    $0xfe,%eax
jl     1297 <getDeviceInfo+0x147>
lea    0x10(%rsp),%rdi
call   1040 <strlen@plt>
mov    $0xfe,%ecx
sub    %eax,%ecx
movslq %ecx,%rax
movb   $0x0,(%r14,%rax,1)
lea    0xd88(%rip),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
lea    0x10(%rsp),%rsi
mov    %r14,%rdi
call   1070 <strcat@plt>
jmp    12dd <getDeviceInfo+0x18d>
lea    0xd59(%rip),%rcx
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1060 <addDeviceInfo@plt>
lea    0xd4e(%rip),%rcx
mov    %r14,%rdi
xor    %esi,%esi
mov    %rbx,%rdx
call   1060 <addDeviceInfo@plt>
add    $0x110,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [7 x i8] c"/model\00"
@.str.1 = [14 x i8] c"/manufacturer\00"
@.str.2 = [9 x i8] c"/product\00"
@.str.3 = [8 x i8] c"/serial\00"
@.str.4 = [2 x i8] c" \00"
define void @getDeviceInfo(i8* %0, i32* %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i8*
%9 = alloca [256 x i8]
%10 = alloca i32
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8* %2, i8** %6
store i32 0, i32* %10
store i32 0, i32* %7
br label %11
11: ; preds = %18, %3
%12 = load i32, i32* %7
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %21
14: ; preds = %11
%15 = load i8*, i8** %6
%16 = call i8* @strrchr(i8* %15, i8 signext 47)
store i8* %16, i8** %8
%17 = load i8*, i8** %8
store i8 0, i8* %17
br label %18
18: ; preds = %14
%19 = load i32, i32* %7
%20 = add nsw i32 %19, 1
store i32 %20, i32* %7
br label %11
21: ; preds = %11
%22 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%23 = load i8*, i8** %6
%24 = call i32 @addDeviceInfo(i8* %22, i32* %10, i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %7
br label %25
25: ; preds = %32, %21
%26 = load i32, i32* %7
%27 = icmp slt i32 %26, 4
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load i8*, i8** %6
%30 = call i8* @strrchr(i8* %29, i8 signext 47)
store i8* %30, i8** %8
%31 = load i8*, i8** %8
store i8 0, i8* %31
br label %32
32: ; preds = %28
%33 = load i32, i32* %7
%34 = add nsw i32 %33, 1
store i32 %34, i32* %7
br label %25
35: ; preds = %25
%36 = load i8*, i8** %4
%37 = load i32*, i32** %5
%38 = load i8*, i8** %6
%39 = call i32 @addDeviceInfo(i8* %36, i32* %37, i8* %38, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%40 = load i32*, i32** %5
%41 = icmp ugt i32* %40, null
br i1 %41, label %42, label %49
42: ; preds = %35
%43 = load i8*, i8** %4
%44 = load i32*, i32** %5
%45 = load i32, i32* %44
%46 = sub nsw i32 %45, 1
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8, i8* %43, i64 %47
store i8 32, i8* %48
br label %49
49: ; preds = %42, %35
%50 = load i8*, i8** %4
%51 = load i32*, i32** %5
%52 = load i8*, i8** %6
%53 = call i32 @addDeviceInfo(i8* %50, i32* %51, i8* %52, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%54 = load i32*, i32** %5
%55 = icmp ugt i32* %54, null
br i1 %55, label %56, label %63
56: ; preds = %49
%57 = load i8*, i8** %4
%58 = load i32*, i32** %5
%59 = load i32, i32* %58
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %57, i64 %61
store i8 32, i8* %62
br label %63
63: ; preds = %56, %49
%64 = load i8*, i8** %4
%65 = load i32*, i32** %5
%66 = load i8*, i8** %6
%67 = call i32 @addDeviceInfo(i8* %64, i32* %65, i8* %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%68 = load i32*, i32** %5
%69 = icmp ule i32* %68, null
br i1 %69, label %70, label %71
70: ; preds = %63
br label %101
71: ; preds = %63
%72 = load i8*, i8** %4
%73 = call i32 @tidyStringUp(i8* %72)
%74 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%75 = call i32 @tidyStringUp(i8* %74)
%76 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%77 = call i32 @strlen(i8* %76)
%78 = icmp ne i32 %77, 0
br i1 %78, label %79, label %101
79: ; preds = %71
%80 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%81 = call i32 @strlen(i8* %80)
%82 = load i8*, i8** %4
%83 = call i32 @strlen(i8* %82)
%84 = add nsw i32 %81, %83
%85 = add nsw i32 %84, 2
%86 = icmp sge i32 %85, 256
br i1 %86, label %87, label %95
87: ; preds = %79
%88 = load i8*, i8** %4
%89 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%90 = call i32 @strlen(i8* %89)
%91 = sub nsw i32 256, %90
%92 = sub nsw i32 %91, 2
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8, i8* %88, i64 %93
store i8 0, i8* %94
br label %95
95: ; preds = %87, %79
%96 = load i8*, i8** %4
%97 = call i32 @strcat(i8* %96, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%98 = load i8*, i8** %4
%99 = getelementptr inbounds [256 x i8], [256 x i8]* %9, i64 0, i64 0
%100 = call i32 @strcat(i8* %98, i8* %99)
br label %101
101: ; preds = %70, %95, %71
ret void
}

LLVM IR (-O2):
@.str = [7 x i8] c"/model\00"
@.str.1 = [14 x i8] c"/manufacturer\00"
@.str.2 = [9 x i8] c"/product\00"
@.str.3 = [8 x i8] c"/serial\00"
@.str.4 = [2 x i8] c" \00"
define void @getDeviceInfo(i8* %0, i32* %1, i8* %2) {
%4 = alloca [256 x i8]
%5 = alloca i32
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %4, i64 0, i64 0
%7 = bitcast i32* %5 to i8*
store i32 0, i32* %5
%8 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
store i8 0, i8* %8
%9 = tail call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
store i8 0, i8* %9
%10 = call i32 @addDeviceInfo(i8* %6, i32* %5, i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%11 = call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
store i8 0, i8* %11
%12 = call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
store i8 0, i8* %12
%13 = call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
store i8 0, i8* %13
%14 = call i8* @strrchr(i8* dereferenceable(1) %2, i8 signext 47)
store i8 0, i8* %14
%15 = call i32 @addDeviceInfo(i8* %0, i32* %1, i8* %2, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0))
%16 = icmp eq i32* %1, null
br i1 %16, label %17, label %20
17: ; preds = %3
%18 = call i32 @addDeviceInfo(i8* %0, i32* null, i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @addDeviceInfo(i8* %0, i32* null, i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
br label %48
20: ; preds = %3
%21 = load i32, i32* %1
%22 = add nsw i32 %21, -1
%23 = sext i32 %22 to i64
%24 = getelementptr inbounds i8, i8* %0, i64 %23
store i8 32, i8* %24
%25 = call i32 @addDeviceInfo(i8* %0, i32* %1, i8* %2, i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.2, i64 0, i64 0))
%26 = load i32, i32* %1
%27 = add nsw i32 %26, -1
%28 = sext i32 %27 to i64
%29 = getelementptr inbounds i8, i8* %0, i64 %28
store i8 32, i8* %29
%30 = call i32 @addDeviceInfo(i8* %0, i32* %1, i8* %2, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0))
%31 = call i32 @tidyStringUp(i8* %0)
%32 = call i32 @tidyStringUp(i8* %6)
%33 = call i32 @strlen(i8* %6)
%34 = icmp eq i32 %33, 0
br i1 %34, label %48, label %35
35: ; preds = %20
%36 = call i32 @strlen(i8* %6)
%37 = call i32 @strlen(i8* %0)
%38 = add nsw i32 %37, %36
%39 = icmp sgt i32 %38, 253
br i1 %39, label %40, label %45
40: ; preds = %35
%41 = call i32 @strlen(i8* %6)
%42 = sub i32 254, %41
%43 = sext i32 %42 to i64
%44 = getelementptr inbounds i8, i8* %0, i64 %43
store i8 0, i8* %44
br label %45
45: ; preds = %40, %35
%46 = call i32 @strcat(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
%47 = call i32 @strcat(i8* %0, i8* %6)
br label %48
48: ; preds = %17, %20, %45
ret void
}