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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strncmp(char *, char *, int);
void readstatus(char *filename) {
  FILE *file;
  static char buf[1024];
  file = fopen(filename, "r");
  if (!file)
    return;
  while (fgets(buf, sizeof(buf), file)) {
    if (strncmp(buf, "State", 5) == 0) {
      printf("%s\n", buf);
      break;
    }
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<readstatus>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1180 <readstatus+0x30>
jmp    11ec <readstatus+0x9c>
jmp    1185 <readstatus+0x35>
mov    -0x10(%rbp),%rdx
lea    0x2ed0(%rip),%rdi
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     11e3 <readstatus+0x93>
lea    0x2eb5(%rip),%rdi
lea    0xe50(%rip),%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    11de <readstatus+0x8e>
lea    0xe3b(%rip),%rdi
lea    0x2e8c(%rip),%rsi
call   1050 <printf@plt>
jmp    11e3 <readstatus+0x93>
jmp    1185 <readstatus+0x35>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readstatus>:
push   %r15
push   %r14
push   %rbx
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11ca <readstatus+0x7a>
mov    %rax,%r14
lea    0x2ef0(%rip),%rbx
lea    0xe8b(%rip),%r15
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x400,%esi
mov    %r14,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11bd <readstatus+0x6d>
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x5,%edx
call   1030 <strncmp@plt>
test   %rax,%rax
jne    1180 <readstatus+0x30>
lea    0xe57(%rip),%rdi
lea    0x2ea8(%rip),%rsi
call   1050 <printf@plt>
mov    %r14,%rdi
pop    %rbx
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@readstatus.buf = internal global [1024 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"State\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @readstatus(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = call i32* @fopen(i8* %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %5, i32** %3
%6 = load i32*, i32** %3
%7 = icmp ne i32* %6, null
br i1 %7, label %9, label %8
8: ; preds = %1
br label %23
9: ; preds = %1
br label %10
10: ; preds = %19, %9
%11 = load i32*, i32** %3
%12 = call i64 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @readstatus.buf, i64 0, i64 0), i32 1024, i32* %11)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %20
14: ; preds = %10
%15 = call i64 @strncmp(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @readstatus.buf, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %14
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @readstatus.buf, i64 0, i64 0))
br label %20
19: ; preds = %14
br label %10
20: ; preds = %17, %10
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
br label %23
23: ; preds = %20, %8
ret void
}

LLVM IR (-O2):
@readstatus.buf = internal global [1024 x i8] zeroinitializer
@.str = [2 x i8] c"r\00"
@.str.1 = [6 x i8] c"State\00"
@.str.2 = [4 x i8] c"%s\0A\00"
define void @readstatus(i8* nocapture %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %14, label %4
4: ; preds = %1, %7
%5 = tail call i64 @fgets(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @readstatus.buf, i64 0, i64 0), i32 1024, i32* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %12, label %7
7: ; preds = %4
%8 = tail call i64 @strncmp(i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @readstatus.buf, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %4
10: ; preds = %7
%11 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([1024 x i8], [1024 x i8]* @readstatus.buf, i64 0, i64 0))
br label %12
12: ; preds = %4, %10
%13 = tail call i32 @fclose(i32* %2)
br label %14
14: ; preds = %1, %12
ret void
}