#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*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fscanf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char const *);
char *strdup(char *);
char *getScheduler(const char *suffix) {
  if (suffix) {
    char s[1000];
    sprintf(s, "/sys/block/%s/queue/scheduler", suffix);
    FILE *fp = fopen(s, "rt");
    if (!fp) {
      return strdup("problem");
    }
    int ret = fscanf(fp, "%s", s);
    fclose(fp);
    if (ret == 1) {
      return strdup(s);
    }
  }
  return strdup("NULL");
}


x86 assembly (clang, -O0):
<getScheduler>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     1211 <getScheduler+0xc1>
lea    -0x400(%rbp),%rdi
mov    -0x10(%rbp),%rdx
lea    0xe84(%rip),%rsi
call   1060 <sprintf@plt>
lea    -0x400(%rbp),%rdi
lea    0xe8f(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x408(%rbp)
cmpq   $0x0,-0x408(%rbp)
jne    11be <getScheduler+0x6e>
lea    0xe71(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1221 <getScheduler+0xd1>
mov    -0x408(%rbp),%rdi
lea    -0x400(%rbp),%rdx
lea    0xe56(%rip),%rsi
call   1040 <fscanf@plt>
mov    %eax,-0x40c(%rbp)
mov    -0x408(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x1,-0x40c(%rbp)
jne    120c <getScheduler+0xbc>
lea    -0x400(%rbp),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
jmp    1221 <getScheduler+0xd1>
jmp    1211 <getScheduler+0xc1>
lea    0xe14(%rip),%rdi
call   1070 <strdup@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getScheduler>:
push   %rbp
push   %rbx
sub    $0x3e8,%rsp
test   %rdi,%rdi
je     11b0 <getScheduler+0x60>
mov    %rdi,%rdx
lea    0xe98(%rip),%rsi
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1060 <sprintf@plt>
lea    0xea4(%rip),%rsi
mov    %rbx,%rdi
call   1050 <fopen@plt>
test   %rax,%rax
je     11b9 <getScheduler+0x69>
mov    %rax,%rbx
lea    0xe98(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
cmp    $0x1,%ebp
jne    11b0 <getScheduler+0x60>
mov    %rsp,%rdi
jmp    11c0 <getScheduler+0x70>
lea    0xe75(%rip),%rdi
jmp    11c0 <getScheduler+0x70>
lea    0xe61(%rip),%rdi
call   1070 <strdup@plt>
add    $0x3e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [30 x i8] c"/sys/block/%s/queue/scheduler\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [8 x i8] c"problem\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [5 x i8] c"NULL\00"
define i8* @getScheduler(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [1000 x i8]
%5 = alloca i32*
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i8*, i8** %3
%8 = icmp ne i8* %7, null
br i1 %8, label %9, label %31
9: ; preds = %1
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%11 = load i8*, i8** %3
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %5
%15 = load i32*, i32** %5
%16 = icmp ne i32* %15, null
br i1 %16, label %19, label %17
17: ; preds = %9
%18 = call i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
store i8* %18, i8** %2
br label %33
19: ; preds = %9
%20 = load i32*, i32** %5
%21 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%22 = call i32 @fscanf(i32* %20, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %21)
store i32 %22, i32* %6
%23 = load i32*, i32** %5
%24 = call i32 @fclose(i32* %23)
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, 1
br i1 %26, label %27, label %30
27: ; preds = %19
%28 = getelementptr inbounds [1000 x i8], [1000 x i8]* %4, i64 0, i64 0
%29 = call i8* @strdup(i8* %28)
store i8* %29, i8** %2
br label %33
30: ; preds = %19
br label %31
31: ; preds = %30, %1
%32 = call i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
store i8* %32, i8** %2
br label %33
33: ; preds = %31, %27, %17
%34 = load i8*, i8** %2
ret i8* %34
}

LLVM IR (-O2):
@.str = [30 x i8] c"/sys/block/%s/queue/scheduler\00"
@.str.1 = [3 x i8] c"rt\00"
@.str.2 = [8 x i8] c"problem\00"
@.str.3 = [3 x i8] c"%s\00"
@.str.4 = [5 x i8] c"NULL\00"
define noalias i8* @getScheduler(i8* %0) {
%2 = alloca [1000 x i8]
%3 = icmp eq i8* %0, null
br i1 %3, label %20, label %4
4: ; preds = %1
%5 = getelementptr inbounds [1000 x i8], [1000 x i8]* %2, i64 0, i64 0
%6 = call i32 @sprintf(i8* %5, i8* dereferenceable(1) getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0), i8* %0)
%7 = call i32* @fopen(i8* %5, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0))
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %4
%10 = tail call dereferenceable_or_null(8) i8* @strdup(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i64 0, i64 0))
br label %17
11: ; preds = %4
%12 = call i32 @fscanf(i32* %7, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %5)
%13 = call i32 @fclose(i32* %7)
%14 = icmp eq i32 %12, 1
br i1 %14, label %15, label %19
15: ; preds = %11
%16 = call i8* @strdup(i8* %5)
br label %17
17: ; preds = %9, %15
%18 = phi i8* [ %16, %15 ], [ %10, %9 ]
br label %22
19: ; preds = %11
br label %20
20: ; preds = %19, %1
%21 = call dereferenceable_or_null(5) i8* @strdup(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0))
br label %22
22: ; preds = %17, %20
%23 = phi i8* [ %21, %20 ], [ %18, %17 ]
ret i8* %23
}