#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 */
scalar_t__ EOF;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fscanf(int /*<<< orphan*/ *, char *, char *);
char getc(int /*<<< orphan*/ *);
scalar_t__ strcmp(char *, char *);
int checkdesc(char *path) {
  char buf[150];
  FILE *fp;
  int val = 0;
  if ((fp = fopen(path, "r")) != NULL) {
    while (fscanf(fp, "%s", buf) != EOF) {
      if (strcmp(buf, "PDL") == 0) {
        fscanf(fp, "%s", buf);
        val = strcmp(buf, "PostScript") == 0;
        break;
      } else if (strcmp(buf, "charset") == 0)
        break;
      while (getc(fp) != '\n')
        ;
    }
    fclose(fp);
  }
  return (val);
}


x86 assembly (clang, -O0):
<checkdesc>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
mov    %rdi,-0x8(%rbp)
movl   $0x0,-0xac(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe8c(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0xa8(%rbp)
cmp    $0x0,%rax
je     1274 <checkdesc+0x124>
jmp    118f <checkdesc+0x3f>
mov    -0xa8(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1040 <fscanf@plt>
mov    0x2e38(%rip),%rcx
cmp    (%rcx),%rax
je     1268 <checkdesc+0x118>
lea    -0xa0(%rbp),%rdi
lea    0xe3e(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    121a <checkdesc+0xca>
mov    -0xa8(%rbp),%rdi
lea    -0xa0(%rbp),%rdx
lea    0xe17(%rip),%rsi
call   1040 <fscanf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe0b(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0xac(%rbp)
jmp    1268 <checkdesc+0x118>
lea    -0xa0(%rbp),%rdi
lea    0xdec(%rip),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    123c <checkdesc+0xec>
jmp    1268 <checkdesc+0x118>
jmp    1241 <checkdesc+0xf1>
jmp    1246 <checkdesc+0xf6>
mov    -0xa8(%rbp),%rdi
call   1070 <getc@plt>
movsbl %al,%eax
cmp    $0xa,%eax
je     1263 <checkdesc+0x113>
jmp    1246 <checkdesc+0xf6>
jmp    118f <checkdesc+0x3f>
mov    -0xa8(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0xac(%rbp),%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<checkdesc>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
lea    0xe98(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1203 <checkdesc+0xb3>
mov    %rax,%rbx
lea    0xe82(%rip),%rsi
mov    %rsp,%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    0x2e56(%rip),%r14
xor    %ebp,%ebp
cmp    (%r14),%rax
je     1234 <checkdesc+0xe4>
lea    0xe61(%rip),%r15
mov    %rsp,%rbp
lea    0xe66(%rip),%r12
lea    0xe4d(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbp,%rdi
mov    %r15,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     1207 <checkdesc+0xb7>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
je     11ff <checkdesc+0xaf>
mov    %rbx,%rdi
call   1070 <getc@plt>
cmp    $0xa,%al
jne    11e0 <checkdesc+0x90>
mov    %rbx,%rdi
mov    %r13,%rsi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
cmp    (%r14),%rax
jne    11c0 <checkdesc+0x70>
xor    %ebp,%ebp
jmp    1234 <checkdesc+0xe4>
xor    %ebp,%ebp
jmp    123c <checkdesc+0xec>
lea    0xdf4(%rip),%rsi
mov    %rsp,%rbp
mov    %rbx,%rdi
mov    %rbp,%rdx
call   1040 <fscanf@plt>
lea    0xde6(%rip),%rsi
mov    %rbp,%rdi
call   1050 <strcmp@plt>
xor    %ebp,%ebp
test   %rax,%rax
sete   %bpl
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [4 x i8] c"PDL\00"
@.str.3 = [11 x i8] c"PostScript\00"
@.str.4 = [8 x i8] c"charset\00"
define i32 @checkdesc(i8* %0) {
%2 = alloca i8*
%3 = alloca [150 x i8]
%4 = alloca i32*
%5 = alloca i32
store i8* %0, i8** %2
store i32 0, i32* %5
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %4
%8 = icmp ne i32* %7, null
br i1 %8, label %9, label %45
9: ; preds = %1
br label %10
10: ; preds = %41, %9
%11 = load i32*, i32** %4
%12 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%13 = call i64 @fscanf(i32* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i64, i64* @EOF
%15 = icmp ne i64 %13, %14
br i1 %15, label %16, label %42
16: ; preds = %10
%17 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%18 = call i64 @strcmp(i8* %17, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %28
20: ; preds = %16
%21 = load i32*, i32** %4
%22 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%23 = call i64 @fscanf(i32* %21, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %22)
%24 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%25 = call i64 @strcmp(i8* %24, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%26 = icmp eq i64 %25, 0
%27 = zext i1 %26 to i32
store i32 %27, i32* %5
br label %42
28: ; preds = %16
%29 = getelementptr inbounds [150 x i8], [150 x i8]* %3, i64 0, i64 0
%30 = call i64 @strcmp(i8* %29, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %28
br label %42
33: ; preds = %28
br label %34
34: ; preds = %33
br label %35
35: ; preds = %40, %34
%36 = load i32*, i32** %4
%37 = call signext i8 @getc(i32* %36)
%38 = sext i8 %37 to i32
%39 = icmp ne i32 %38, 10
br i1 %39, label %40, label %41
40: ; preds = %35
br label %35
41: ; preds = %35
br label %10
42: ; preds = %32, %20, %10
%43 = load i32*, i32** %4
%44 = call i32 @fclose(i32* %43)
br label %45
45: ; preds = %42, %1
%46 = load i32, i32* %5
ret i32 %46
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [3 x i8] c"%s\00"
@EOF = global i64 0
@.str.2 = [4 x i8] c"PDL\00"
@.str.3 = [11 x i8] c"PostScript\00"
@.str.4 = [8 x i8] c"charset\00"
define i32 @checkdesc(i8* nocapture %0) {
%2 = alloca [150 x i8]
%3 = getelementptr inbounds [150 x i8], [150 x i8]* %2, i64 0, i64 0
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %31, label %6
6: ; preds = %1
%7 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%8 = load i64, i64* @EOF
%9 = icmp eq i64 %7, %8
br i1 %9, label %28, label %14
10: ; preds = %25
%11 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%12 = load i64, i64* @EOF
%13 = icmp eq i64 %11, %12
br i1 %13, label %28, label %14
14: ; preds = %6, %10
%15 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %22
17: ; preds = %14
%18 = call i64 @fscanf(i32* %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8* %3)
%19 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
%21 = zext i1 %20 to i32
br label %28
22: ; preds = %14
%23 = call i64 @strcmp(i8* %3, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %28, label %25
25: ; preds = %22, %25
%26 = call signext i8 @getc(i32* %4)
%27 = icmp eq i8 %26, 10
br i1 %27, label %10, label %25
28: ; preds = %10, %22, %6, %17
%29 = phi i32 [ %21, %17 ], [ 0, %6 ], [ 0, %22 ], [ 0, %10 ]
%30 = call i32 @fclose(i32* %4)
br label %31
31: ; preds = %28, %1
%32 = phi i32 [ %29, %28 ], [ 0, %1 ]
ret i32 %32
}