#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 /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
char *strchr(char *, char);
char *get_modprobe(void) {
  int procfile;
  char *ret;
  procfile = open("/proc/sys/kernel/modprobe", O_RDONLY);
  if (procfile < 0)
    return NULL;
  ret = malloc(1024);
  if (ret) {
    if (read(procfile, ret, 1024) == -1)
      goto fail;
    ret[1023] = '\n';
    *strchr(ret, '\n') = '\0';
    close(procfile);
    return ret;
  }
fail:
  free(ret);
  close(procfile);
  return NULL;
}


x86 assembly (clang, -O0):
<get_modprobe>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e79(%rip),%rax
mov    (%rax),%esi
lea    0xe88(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jge    1197 <get_modprobe+0x37>
movq   $0x0,-0x8(%rbp)
jmp    121e <get_modprobe+0xbe>
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     1200 <get_modprobe+0xa0>
mov    -0xc(%rbp),%edi
mov    -0x18(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
jne    11cf <get_modprobe+0x6f>
jmp    1205 <get_modprobe+0xa5>
mov    -0x18(%rbp),%rax
movb   $0xa,0x3ff(%rax)
mov    -0x18(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    121e <get_modprobe+0xbe>
jmp    1205 <get_modprobe+0xa5>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_modprobe>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e7e(%rip),%rax
mov    (%rax),%esi
lea    0xe8d(%rip),%rdi
call   1080 <open@plt>
test   %eax,%eax
js     11bd <get_modprobe+0x5d>
mov    %eax,%ebp
mov    $0x400,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
test   %rax,%rax
je     11c1 <get_modprobe+0x61>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
cmp    $0xffffffff,%eax
je     11c1 <get_modprobe+0x61>
movb   $0xa,0x3ff(%rbx)
mov    %rbx,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
movb   $0x0,(%rax)
jmp    11cb <get_modprobe+0x6b>
xor    %ebx,%ebx
jmp    11d2 <get_modprobe+0x72>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %ebp,%edi
call   1050 <close@plt>
mov    %rbx,%rax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [26 x i8] c"/proc/sys/kernel/modprobe\00"
@O_RDONLY = global i32 0
define i8* @get_modprobe() {
%1 = alloca i8*
%2 = alloca i32
%3 = alloca i8*
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %0
store i8* null, i8** %1
br label %33
9: ; preds = %0
%10 = call i8* @malloc(i32 1024)
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = icmp ne i8* %11, null
br i1 %12, label %13, label %27
13: ; preds = %9
%14 = load i32, i32* %2
%15 = load i8*, i8** %3
%16 = call i32 @read(i32 %14, i8* %15, i32 1024)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %19
18: ; preds = %13
br label %28
19: ; preds = %13
%20 = load i8*, i8** %3
%21 = getelementptr inbounds i8, i8* %20, i64 1023
store i8 10, i8* %21
%22 = load i8*, i8** %3
%23 = call i8* @strchr(i8* %22, i8 signext 10)
store i8 0, i8* %23
%24 = load i32, i32* %2
%25 = call i32 @close(i32 %24)
%26 = load i8*, i8** %3
store i8* %26, i8** %1
br label %33
27: ; preds = %9
br label %28
28: ; preds = %27, %18
%29 = load i8*, i8** %3
%30 = call i32 @free(i8* %29)
%31 = load i32, i32* %2
%32 = call i32 @close(i32 %31)
store i8* null, i8** %1
br label %33
33: ; preds = %28, %19, %8
%34 = load i8*, i8** %1
ret i8* %34
}

LLVM IR (-O2):
@.str = [26 x i8] c"/proc/sys/kernel/modprobe\00"
@O_RDONLY = global i32 0
define i8* @get_modprobe() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp slt i32 %2, 0
br i1 %3, label %18, label %4
4: ; preds = %0
%5 = tail call dereferenceable_or_null(1024) i8* @malloc(i32 1024)
%6 = icmp eq i8* %5, null
br i1 %6, label %13, label %7
7: ; preds = %4
%8 = tail call i32 @read(i32 %2, i8* %5, i32 1024)
%9 = icmp eq i32 %8, -1
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = getelementptr inbounds i8, i8* %5, i64 1023
store i8 10, i8* %11
%12 = tail call i8* @strchr(i8* %5, i8 signext 10)
store i8 0, i8* %12
br label %15
13: ; preds = %4, %7
%14 = tail call i32 @free(i8* %5)
br label %15
15: ; preds = %10, %13
%16 = phi i8* [ %5, %10 ], [ null, %13 ]
%17 = tail call i32 @close(i32 %2)
br label %18
18: ; preds = %15, %0
%19 = phi i8* [ null, %0 ], [ %16, %15 ]
ret i8* %19
}