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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char const *);
int strlen(char *);
void v4lcontrol_get_dmi_string(const char *string, char *buf, int size) {
  FILE *f;
  char *s, sysfs_name[512];
  snprintf(sysfs_name, sizeof(sysfs_name), "/sys/class/dmi/id/%s", string);
  f = fopen(sysfs_name, "r");
  if (!f) {
    snprintf(sysfs_name, sizeof(sysfs_name), "/sys/devices/virtual/dmi/id/%s",
             string);
    f = fopen(sysfs_name, "r");
    if (!f) {
      buf[0] = 0;
      return;
    }
  }
  s = fgets(buf, size, f);
  if (s)
    s[strlen(s) - 1] = 0;
  fclose(f);
}


x86 assembly (clang, -O0):
<v4lcontrol_get_dmi_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x240,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
lea    -0x230(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x200,%esi
lea    0xe83(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x230(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11f3 <v4lcontrol_get_dmi_string+0xa3>
lea    -0x230(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x200,%esi
lea    0xe5c(%rip),%rdx
call   1050 <snprintf@plt>
lea    -0x230(%rbp),%rdi
lea    0xe47(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ee <v4lcontrol_get_dmi_string+0x9e>
mov    -0x10(%rbp),%rax
movb   $0x0,(%rax)
jmp    1242 <v4lcontrol_get_dmi_string+0xf2>
jmp    11f3 <v4lcontrol_get_dmi_string+0xa3>
mov    -0x10(%rbp),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rdx
call   1060 <fgets@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
je     1239 <v4lcontrol_get_dmi_string+0xe9>
mov    -0x28(%rbp),%rax
mov    %rax,-0x238(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x238(%rbp),%rax
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
add    $0x240,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<v4lcontrol_get_dmi_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x208,%rsp
mov    %edx,%r14d
mov    %rsi,%r15
mov    %rdi,%rbx
lea    0xe93(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
lea    0xe8e(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
jne    11c8 <v4lcontrol_get_dmi_string+0x78>
lea    0xe79(%rip),%rdx
mov    %rsp,%rbp
mov    %rbp,%rdi
mov    $0x200,%esi
mov    %rbx,%rcx
call   1050 <snprintf@plt>
lea    0xe5d(%rip),%rsi
mov    %rbp,%rdi
call   1070 <fopen@plt>
mov    %rax,%rbp
test   %rax,%rax
je     1203 <v4lcontrol_get_dmi_string+0xb3>
mov    %r15,%rdi
mov    %r14d,%esi
mov    %rbp,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11ed <v4lcontrol_get_dmi_string+0x9d>
mov    %rax,%rbx
mov    %rax,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %rbp,%rdi
call   1030 <fclose@plt>
add    $0x208,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
movb   $0x0,(%r15)
jmp    11f5 <v4lcontrol_get_dmi_string+0xa5>

LLVM IR (-O0):
@.str = [21 x i8] c"/sys/class/dmi/id/%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"/sys/devices/virtual/dmi/id/%s\00"
define void @v4lcontrol_get_dmi_string(i8* %0, i8* %1, i32 %2) {
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [512 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
store i32 %2, i32* %6
%10 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%11 = load i8*, i8** %4
%12 = call i32 @snprintf(i8* %10, i32 512, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %7
%15 = load i32*, i32** %7
%16 = icmp ne i32* %15, null
br i1 %16, label %29, label %17
17: ; preds = %3
%18 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%19 = load i8*, i8** %4
%20 = call i32 @snprintf(i8* %18, i32 512, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [512 x i8], [512 x i8]* %9, i64 0, i64 0
%22 = call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %22, i32** %7
%23 = load i32*, i32** %7
%24 = icmp ne i32* %23, null
br i1 %24, label %28, label %25
25: ; preds = %17
%26 = load i8*, i8** %5
%27 = getelementptr inbounds i8, i8* %26, i64 0
store i8 0, i8* %27
br label %46
28: ; preds = %17
br label %29
29: ; preds = %28, %3
%30 = load i8*, i8** %5
%31 = load i32, i32* %6
%32 = load i32*, i32** %7
%33 = call i8* @fgets(i8* %30, i32 %31, i32* %32)
store i8* %33, i8** %8
%34 = load i8*, i8** %8
%35 = icmp ne i8* %34, null
br i1 %35, label %36, label %43
36: ; preds = %29
%37 = load i8*, i8** %8
%38 = load i8*, i8** %8
%39 = call i32 @strlen(i8* %38)
%40 = sub nsw i32 %39, 1
%41 = sext i32 %40 to i64
%42 = getelementptr inbounds i8, i8* %37, i64 %41
store i8 0, i8* %42
br label %43
43: ; preds = %36, %29
%44 = load i32*, i32** %7
%45 = call i32 @fclose(i32* %44)
br label %46
46: ; preds = %43, %25
ret void
}

LLVM IR (-O2):
@.str = [21 x i8] c"/sys/class/dmi/id/%s\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [31 x i8] c"/sys/devices/virtual/dmi/id/%s\00"
define void @v4lcontrol_get_dmi_string(i8* %0, i8* %1, i32 %2) {
%4 = alloca [512 x i8]
%5 = getelementptr inbounds [512 x i8], [512 x i8]* %4, i64 0, i64 0
%6 = call i32 @snprintf(i8* %5, i32 512, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %3
%10 = call i32 @snprintf(i8* %5, i32 512, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.2, i64 0, i64 0), i8* %0)
%11 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %14
13: ; preds = %9
store i8 0, i8* %1
br label %25
14: ; preds = %9, %3
%15 = phi i32* [ %7, %3 ], [ %11, %9 ]
%16 = call i8* @fgets(i8* %1, i32 %2, i32* %15)
%17 = icmp eq i8* %16, null
br i1 %17, label %23, label %18
18: ; preds = %14
%19 = call i32 @strlen(i8* %16)
%20 = add nsw i32 %19, -1
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8, i8* %16, i64 %21
store i8 0, i8* %22
br label %23
23: ; preds = %18, %14
%24 = call i32 @fclose(i32* %15)
br label %25
25: ; preds = %23, %13
ret void
}