#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 */
char *get_file_contents(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *);
char *strchr(char *, char);
char *get_dmi_string(char *p) {
  char fn[256];
  char *ret = NULL, *rep = NULL;
  snprintf(fn, 256, "/sys/class/dmi/id/%s", p);
  ret = get_file_contents(fn);
  if (ret) {
    while ((rep = strchr(ret, '\n')))
      *rep = 0;
  }
  return ret;
}


x86 assembly (clang, -O0):
<get_dmi_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x118(%rbp)
movq   $0x0,-0x120(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rcx
mov    $0x100,%esi
lea    0xe94(%rip),%rdx
call   1040 <snprintf@plt>
lea    -0x110(%rbp),%rdi
call   1050 <get_file_contents@plt>
mov    %rax,-0x118(%rbp)
cmpq   $0x0,-0x118(%rbp)
je     11cd <get_dmi_string+0x9d>
jmp    1197 <get_dmi_string+0x67>
mov    -0x118(%rbp),%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
mov    %rax,-0x120(%rbp)
cmp    $0x0,%rax
je     11c8 <get_dmi_string+0x98>
mov    -0x120(%rbp),%rax
movb   $0x0,(%rax)
jmp    1197 <get_dmi_string+0x67>
jmp    11cd <get_dmi_string+0x9d>
mov    -0x118(%rbp),%rax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_dmi_string>:
push   %rbx
sub    $0x100,%rsp
mov    %rdi,%rcx
lea    0xebe(%rip),%rdx
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x100,%esi
call   1040 <snprintf@plt>
mov    %rbx,%rdi
call   1050 <get_file_contents@plt>
mov    %rax,%rbx
test   %rax,%rax
je     1187 <get_dmi_string+0x57>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1030 <strchr@plt>
test   %rax,%rax
je     1187 <get_dmi_string+0x57>
movb   $0x0,(%rax)
jmp    1170 <get_dmi_string+0x40>
mov    %rbx,%rax
add    $0x100,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [21 x i8] c"/sys/class/dmi/id/%s\00"
define i8* @get_dmi_string(i8* %0) {
%2 = alloca i8*
%3 = alloca [256 x i8]
%4 = alloca i8*
%5 = alloca i8*
store i8* %0, i8** %2
store i8* null, i8** %4
store i8* null, i8** %5
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%7 = load i8*, i8** %2
%8 = call i32 @snprintf(i8* %6, i32 256, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %7)
%9 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
%10 = call i8* @get_file_contents(i8* %9)
store i8* %10, i8** %4
%11 = load i8*, i8** %4
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %21
13: ; preds = %1
br label %14
14: ; preds = %18, %13
%15 = load i8*, i8** %4
%16 = call i8* @strchr(i8* %15, i8 signext 10)
store i8* %16, i8** %5
%17 = icmp ne i8* %16, null
br i1 %17, label %18, label %20
18: ; preds = %14
%19 = load i8*, i8** %5
store i8 0, i8* %19
br label %14
20: ; preds = %14
br label %21
21: ; preds = %20, %1
%22 = load i8*, i8** %4
ret i8* %22
}

LLVM IR (-O2):
@.str = [21 x i8] c"/sys/class/dmi/id/%s\00"
define i8* @get_dmi_string(i8* %0) {
%2 = alloca [256 x i8]
%3 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%4 = call i32 @snprintf(i8* %3, i32 256, i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0), i8* %0)
%5 = call i8* @get_file_contents(i8* %3)
%6 = icmp eq i8* %5, null
br i1 %6, label %14, label %7
7: ; preds = %1
%8 = call i8* @strchr(i8* %5, i8 signext 10)
%9 = icmp eq i8* %8, null
br i1 %9, label %14, label %10
10: ; preds = %7, %10
%11 = phi i8* [ %12, %10 ], [ %8, %7 ]
store i8 0, i8* %11
%12 = call i8* @strchr(i8* %5, i8 signext 10)
%13 = icmp eq i8* %12, null
br i1 %13, label %14, label %10
14: ; preds = %10, %7, %1
ret i8* %5
}