#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 strlen(char *);
scalar_t__ strncmp(char *, char *, int);
char *sysfsparser_getline(char *, unsigned int);
const char *sysfsparser_thermal_get_device(unsigned int thermal_zone) {
  char *device;
  device = sysfsparser_getline("/sys/class"
                               "/thermal"
                               "/thermal_zone%u/device/path",
                               thermal_zone);
  if (NULL == device)
    return "Virtual device";
  return (strncmp(device, "\\_TZ_.", strlen("\\_TZ_.")) == 0)
             ? device + strlen("\\_TZ_.")
             : device;
}


x86 assembly (clang, -O0):
<sysfsparser_thermal_get_device>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0xc(%rbp)
mov    -0xc(%rbp),%esi
lea    0xebb(%rip),%rdi
call   1050 <sysfsparser_getline@plt>
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
cmp    -0x18(%rbp),%rax
jne    116a <sysfsparser_thermal_get_device+0x3a>
lea    0xecd(%rip),%rax
mov    %rax,-0x8(%rbp)
jmp    11d3 <sysfsparser_thermal_get_device+0xa3>
mov    -0x18(%rbp),%rax
mov    %rax,-0x20(%rbp)
lea    0xec4(%rip),%rdi
call   1040 <strlen@plt>
mov    -0x20(%rbp),%rdi
mov    %eax,%edx
lea    0xeb2(%rip),%rsi
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11c3 <sysfsparser_thermal_get_device+0x93>
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
lea    0xe94(%rip),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x30(%rbp),%rax
movslq %ecx,%rcx
add    %rcx,%rax
mov    %rax,-0x28(%rbp)
jmp    11cb <sysfsparser_thermal_get_device+0x9b>
mov    -0x18(%rbp),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sysfsparser_thermal_get_device>:
push   %r14
push   %rbx
push   %rax
mov    %edi,%esi
lea    0xec3(%rip),%rdi
call   1050 <sysfsparser_getline@plt>
test   %rax,%rax
je     117e <sysfsparser_thermal_get_device+0x4e>
mov    %rax,%rbx
lea    0xeec(%rip),%r14
mov    %r14,%rdi
call   1040 <strlen@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %eax,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1185 <sysfsparser_thermal_get_device+0x55>
lea    0xecb(%rip),%rdi
call   1040 <strlen@plt>
cltq
add    %rax,%rbx
jmp    1185 <sysfsparser_thermal_get_device+0x55>
lea    0xea9(%rip),%rbx
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [46 x i8] c"/sys/class/thermal/thermal_zone%u/device/path\00"
@.str.1 = [15 x i8] c"Virtual device\00"
@.str.2 = [7 x i8] c"\\_TZ_.\00"
define i8* @sysfsparser_thermal_get_device(i32 %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8*
store i32 %0, i32* %3
%5 = load i32, i32* %3
%6 = call i8* @sysfsparser_getline(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %5)
store i8* %6, i8** %4
%7 = load i8*, i8** %4
%8 = icmp eq i8* null, %7
br i1 %8, label %9, label %10
9: ; preds = %1
store i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8** %2
br label %24
10: ; preds = %1
%11 = load i8*, i8** %4
%12 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%13 = call i64 @strncmp(i8* %11, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %20
15: ; preds = %10
%16 = load i8*, i8** %4
%17 = call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i8, i8* %16, i64 %18
br label %22
20: ; preds = %10
%21 = load i8*, i8** %4
br label %22
22: ; preds = %20, %15
%23 = phi i8* [ %19, %15 ], [ %21, %20 ]
store i8* %23, i8** %2
br label %24
24: ; preds = %22, %9
%25 = load i8*, i8** %2
ret i8* %25
}

LLVM IR (-O2):
@.str = [46 x i8] c"/sys/class/thermal/thermal_zone%u/device/path\00"
@.str.1 = [15 x i8] c"Virtual device\00"
@.str.2 = [7 x i8] c"\\_TZ_.\00"
define i8* @sysfsparser_thermal_get_device(i32 %0) {
%2 = tail call i8* @sysfsparser_getline(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i32 %0)
%3 = icmp eq i8* %2, null
br i1 %3, label %12, label %4
4: ; preds = %1
%5 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%6 = tail call i64 @strncmp(i8* %2, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %12
8: ; preds = %4
%9 = tail call i32 @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0))
%10 = sext i32 %9 to i64
%11 = getelementptr inbounds i8, i8* %2, i64 %10
br label %12
12: ; preds = %8, %4, %1
%13 = phi i8* [ getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), %1 ], [ %11, %8 ], [ %2, %4 ]
ret i8* %13
}