#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 /*<<< orphan*/ path;
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ strcat(char *, char *);
char *get_device_vendor(char *dev) {
  int i, j;
  FILE *fp;
  char line[100];
  static char vendor[128];
  char path[64], *ven_mod[] = {"vendor", "model"};
  vendor[0] = '\0';
  for (i = 0; i < 2; i++) {
    snprintf(path, sizeof(path), "/sys/block/%s/device/%s", dev, ven_mod[i]);
    if (!(fp = fopen(path, "r")))
      continue;
    fgets(line, sizeof(line), fp);
    fclose(fp);
    j = 0;
    while (line[j] != '\0' && line[j] != '\r' && line[j] != '\n')
      j++;
    line[j] = '\0';
    strcat(vendor, line);
    strcat(vendor, " ");
  }
  j = 127;
  while (vendor[j] == '\t' || vendor[j] == ' ' || vendor[j] == '\0')
    j--;
  vendor[j + 1] = '\0';
  return vendor;
}


x86 assembly (clang, -O0):
<get_device_vendor>:
push   %rbp
mov    %rsp,%rbp
sub    $0xe0,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2caa(%rip),%rax
mov    %rax,-0xd0(%rbp)
mov    0x2ca4(%rip),%rax
mov    %rax,-0xc8(%rbp)
movb   $0x0,0x2ede(%rip)
movl   $0x0,-0xc(%rbp)
cmpl   $0x2,-0xc(%rbp)
jge    12a7 <get_device_vendor+0x157>
lea    -0xc0(%rbp),%rdi
mov    -0x8(%rbp),%rcx
movslq -0xc(%rbp),%rax
mov    -0xd0(%rbp,%rax,8),%r8
ff
mov    $0x40,%esi
lea    0xe57(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0xc0(%rbp),%rdi
lea    0xe3c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11e1 <get_device_vendor+0x91>
jmp    1299 <get_device_vendor+0x149>
lea    -0x80(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x64,%esi
call   1050 <fgets@plt>
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x10(%rbp)
movslq -0x10(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0x0,%ecx
mov    %al,-0xd1(%rbp)
je     124c <get_device_vendor+0xfc>
movslq -0x10(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%ecx
xor    %eax,%eax
cmp    $0xd,%ecx
mov    %al,-0xd1(%rbp)
je     124c <get_device_vendor+0xfc>
movslq -0x10(%rbp),%rax
movsbl -0x80(%rbp,%rax,1),%eax
cmp    $0xa,%eax
setne  %al
mov    %al,-0xd1(%rbp)
mov    -0xd1(%rbp),%al
test   $0x1,%al
jne    125f <get_device_vendor+0x10f>
jmp    126d <get_device_vendor+0x11d>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x10(%rbp)
jmp    1203 <get_device_vendor+0xb3>
movslq -0x10(%rbp),%rax
movb   $0x0,-0x80(%rbp,%rax,1)
lea    -0x80(%rbp),%rsi
lea    0x2ddf(%rip),%rdi
call   1070 <strcat@plt>
lea    0x2dd3(%rip),%rdi
lea    0xd91(%rip),%rsi
call   1070 <strcat@plt>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    1189 <get_device_vendor+0x39>
movl   $0x7f,-0x10(%rbp)
movslq -0x10(%rbp),%rcx
lea    0x2da7(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x9,%ecx
mov    %al,-0xd2(%rbp)
je     1309 <get_device_vendor+0x1b9>
movslq -0x10(%rbp),%rcx
lea    0x2d87(%rip),%rax
movsbl (%rax,%rcx,1),%ecx
mov    $0x1,%al
cmp    $0x20,%ecx
mov    %al,-0xd2(%rbp)
je     1309 <get_device_vendor+0x1b9>
movslq -0x10(%rbp),%rcx
lea    0x2d67(%rip),%rax
movsbl (%rax,%rcx,1),%eax
cmp    $0x0,%eax
sete   %al
mov    %al,-0xd2(%rbp)
mov    -0xd2(%rbp),%al
test   $0x1,%al
jne    131c <get_device_vendor+0x1cc>
jmp    132a <get_device_vendor+0x1da>
mov    -0x10(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x10(%rbp)
jmp    12ae <get_device_vendor+0x15e>
mov    -0x10(%rbp),%eax
add    $0x1,%eax
movslq %eax,%rcx
lea    0x2d26(%rip),%rax
movb   $0x0,(%rax,%rcx,1)
lea    0x2d1b(%rip),%rax
add    $0xe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_device_vendor>:
push   %r14
push   %rbx
sub    $0xb8,%rsp
mov    %rdi,%r14
movb   $0x0,0x2efc(%rip)
lea    0xea2(%rip),%rdx
lea    0xe8e(%rip),%r8
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
lea    0xe77(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     11fb <get_device_vendor+0xab>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
mov    $0x2401,%ecx
jmp    11c4 <get_device_vendor+0x74>
nop
add    $0x1,%rax
movzbl (%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     11c0 <get_device_vendor+0x70>
bt     %rdx,%rcx
jae    11c0 <get_device_vendor+0x70>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0x2e7f(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe32(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xe0b(%rip),%rdx
lea    0xdfe(%rip),%r8
lea    0x70(%rsp),%rbx
mov    %rbx,%rdi
mov    $0x40,%esi
mov    %r14,%rcx
call   1040 <snprintf@plt>
lea    0xde0(%rip),%rsi
mov    %rbx,%rdi
call   1060 <fopen@plt>
test   %rax,%rax
je     129b <get_device_vendor+0x14b>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x64,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
mov    $0x2401,%ecx
jmp    1264 <get_device_vendor+0x114>
cs nopw 0x0(%rax,%rax,1)
add    $0x1,%rax
movzbl (%rsp,%rax,1),%edx
cmp    $0xd,%rdx
ja     1260 <get_device_vendor+0x110>
bt     %rdx,%rcx
jae    1260 <get_device_vendor+0x110>
mov    %eax,%eax
movb   $0x0,(%rsp,%rax,1)
lea    0x2ddf(%rip),%rbx
mov    %rsp,%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
lea    0xd92(%rip),%rsi
mov    %rbx,%rdi
call   1070 <strcat@plt>
movabs $0x8000000000,%rcx
lea    0x2e33(%rip),%rax
movabs $0x100000201,%rdx
movabs $0xffffffff00000000,%rsi
ff ff ff
movzbl (%rax),%edi
cmp    $0x20,%rdi
ja     12d8 <get_device_vendor+0x188>
bt     %rdi,%rdx
jae    12d8 <get_device_vendor+0x188>
add    %rsi,%rcx
add    $0xffffffffffffffff,%rax
jmp    12c0 <get_device_vendor+0x170>
sar    $0x20,%rcx
lea    0x2d7d(%rip),%rax
movb   $0x0,(%rcx,%rax,1)
add    $0xb8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@get_device_vendor.vendor = internal global [128 x i8] zeroinitializer
@.str = [7 x i8] c"vendor\00"
@.str.1 = [6 x i8] c"model\00"
@__const.get_device_vendor.ven_mod = [2 x i8*] [i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i32 0, i32 0)]
@.str.2 = [24 x i8] c"/sys/block/%s/device/%s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c" \00"
define i8* @get_device_vendor(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32*
%6 = alloca [100 x i8]
%7 = alloca [64 x i8]
%8 = alloca [2 x i8*]
store i8* %0, i8** %2
%9 = bitcast [2 x i8*]* %8 to i8*
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0)
store i32 0, i32* %3
br label %10
10: ; preds = %64, %1
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 2
br i1 %12, label %13, label %67
13: ; preds = %10
%14 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%15 = load i8*, i8** %2
%16 = load i32, i32* %3
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [2 x i8*], [2 x i8*]* %8, i64 0, i64 %17
%19 = load i8*, i8** %18
%20 = call i32 @snprintf(i8* %14, i32 64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %15, i8* %19)
%21 = getelementptr inbounds [64 x i8], [64 x i8]* %7, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %22, i32** %5
%23 = icmp ne i32* %22, null
br i1 %23, label %25, label %24
24: ; preds = %13
br label %64
25: ; preds = %13
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%27 = load i32*, i32** %5
%28 = call i32 @fgets(i8* %26, i32 100, i32* %27)
%29 = load i32*, i32** %5
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %4
br label %31
31: ; preds = %54, %25
%32 = load i32, i32* %4
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %33
%35 = load i8, i8* %34
%36 = sext i8 %35 to i32
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %52
38: ; preds = %31
%39 = load i32, i32* %4
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %40
%42 = load i8, i8* %41
%43 = sext i8 %42 to i32
%44 = icmp ne i32 %43, 13
br i1 %44, label %45, label %52
45: ; preds = %38
%46 = load i32, i32* %4
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %47
%49 = load i8, i8* %48
%50 = sext i8 %49 to i32
%51 = icmp ne i32 %50, 10
br label %52
52: ; preds = %45, %38, %31
%53 = phi i1 [ false, %38 ], [ false, %31 ], [ %51, %45 ]
br i1 %53, label %54, label %57
54: ; preds = %52
%55 = load i32, i32* %4
%56 = add nsw i32 %55, 1
store i32 %56, i32* %4
br label %31
57: ; preds = %52
%58 = load i32, i32* %4
%59 = sext i32 %58 to i64
%60 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 %59
store i8 0, i8* %60
%61 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%62 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0), i8* %61)
%63 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %64
64: ; preds = %57, %24
%65 = load i32, i32* %3
%66 = add nsw i32 %65, 1
store i32 %66, i32* %3
br label %10
67: ; preds = %10
store i32 127, i32* %4
br label %68
68: ; preds = %91, %67
%69 = load i32, i32* %4
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds [128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 %70
%72 = load i8, i8* %71
%73 = sext i8 %72 to i32
%74 = icmp eq i32 %73, 9
br i1 %74, label %89, label %75
75: ; preds = %68
%76 = load i32, i32* %4
%77 = sext i32 %76 to i64
%78 = getelementptr inbounds [128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 %77
%79 = load i8, i8* %78
%80 = sext i8 %79 to i32
%81 = icmp eq i32 %80, 32
br i1 %81, label %89, label %82
82: ; preds = %75
%83 = load i32, i32* %4
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds [128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 %84
%86 = load i8, i8* %85
%87 = sext i8 %86 to i32
%88 = icmp eq i32 %87, 0
br label %89
89: ; preds = %82, %75, %68
%90 = phi i1 [ true, %75 ], [ true, %68 ], [ %88, %82 ]
br i1 %90, label %91, label %94
91: ; preds = %89
%92 = load i32, i32* %4
%93 = add nsw i32 %92, -1
store i32 %93, i32* %4
br label %68
94: ; preds = %89
%95 = load i32, i32* %4
%96 = add nsw i32 %95, 1
%97 = sext i32 %96 to i64
%98 = getelementptr inbounds [128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 %97
store i8 0, i8* %98
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0)
}

LLVM IR (-O2):
@get_device_vendor.vendor = internal global [128 x i8] zeroinitializer
@.str = [7 x i8] c"vendor\00"
@.str.1 = [6 x i8] c"model\00"
@.str.2 = [24 x i8] c"/sys/block/%s/device/%s\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [2 x i8] c" \00"
define i8* @get_device_vendor(i8* %0) {
%2 = alloca [100 x i8]
%3 = alloca [64 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
store i8 0, i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0)
%6 = call i32 @snprintf(i8* %5, i32 64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %23, label %9
9: ; preds = %1
%10 = call i32 @fgets(i8* %4, i32 100, i32* %7)
%11 = call i32 @fclose(i32* %7)
br label %12
12: ; preds = %16, %9
%13 = phi i64 [ %17, %16 ], [ 0, %9 ]
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %13
%15 = load i8, i8* %14
switch i8 %15, label %16 [
i8 0, label %18
i8 13, label %18
i8 10, label %18
]
16: ; preds = %12
%17 = add nuw i64 %13, 1
br label %12
18: ; preds = %12, %12, %12
%19 = and i64 %13, 4294967295
%20 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0), i8* %4)
%22 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %23
23: ; preds = %1, %18
%24 = call i32 @snprintf(i8* %5, i32 64, i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.2, i64 0, i64 0), i8* %0, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0))
%25 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i32* %25, null
br i1 %26, label %27, label %28
27: ; preds = %35, %23
br label %42
28: ; preds = %23
%29 = call i32 @fgets(i8* %4, i32 100, i32* %25)
%30 = call i32 @fclose(i32* %25)
br label %31
31: ; preds = %40, %28
%32 = phi i64 [ %41, %40 ], [ 0, %28 ]
%33 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %32
%34 = load i8, i8* %33
switch i8 %34, label %40 [
i8 0, label %35
i8 13, label %35
i8 10, label %35
]
35: ; preds = %31, %31, %31
%36 = and i64 %32, 4294967295
%37 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 %36
store i8 0, i8* %37
%38 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0), i8* %4)
%39 = call i32 @strcat(i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.4, i64 0, i64 0))
br label %27
40: ; preds = %31
%41 = add nuw i64 %32, 1
br label %31
42: ; preds = %27, %46
%43 = phi i64 [ %47, %46 ], [ 127, %27 ]
%44 = getelementptr inbounds [128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 %43
%45 = load i8, i8* %44
switch i8 %45, label %48 [
i8 9, label %46
i8 32, label %46
i8 0, label %46
]
46: ; preds = %42, %42, %42
%47 = add i64 %43, -1
br label %42
48: ; preds = %42
%49 = shl i64 %43, 32
%50 = add i64 %49, 4294967296
%51 = ashr exact i64 %50, 32
%52 = getelementptr inbounds [128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 %51
store i8 0, i8* %52
ret i8* getelementptr inbounds ([128 x i8], [128 x i8]* @get_device_vendor.vendor, i64 0, i64 0)
}