#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 EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int getc(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ printf(char *);
int set_description(char *);
int set_description_from_file(char *descfile) {
  if (descfile != NULL) {
    FILE *fptr;
    if ((fptr = fopen(descfile, "r")) == NULL) {
      printf("Error! opening file");
      return -1;
    }
    fseek(fptr, 0L, SEEK_END);
    int sz = ftell(fptr);
    char *desc = malloc(sz + 1);
    fseek(fptr, 0L, SEEK_SET);
    int c;
    int i = 0;
    while ((c = getc(fptr)) != EOF) {
      desc[i++] = c;
    }
    desc[i] = 0;
    fclose(fptr);
    return set_description(desc);
  }
  return -1;
}


x86 assembly (clang, -O0):
<set_description_from_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     127b <set_description_from_file+0xfb>
mov    -0x10(%rbp),%rdi
lea    0xe5e(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jne    11cd <set_description_from_file+0x4d>
lea    0xe46(%rip),%rdi
call   1040 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    1282 <set_description_from_file+0x102>
mov    -0x18(%rbp),%rdi
mov    0x2e10(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1070 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2dc7(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
movl   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   10a0 <getc@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2db2(%rip),%rcx
cmp    (%rcx),%eax
je     1255 <set_description_from_file+0xd5>
mov    -0x2c(%rbp),%eax
mov    %al,%dl
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%ecx
mov    %ecx,%esi
add    $0x1,%esi
mov    %esi,-0x30(%rbp)
movslq %ecx,%rcx
mov    %dl,(%rax,%rcx,1)
jmp    121b <set_description_from_file+0x9b>
mov    -0x28(%rbp),%rax
movslq -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rdi
call   1060 <set_description@plt>
mov    %eax,-0x4(%rbp)
jmp    1282 <set_description_from_file+0x102>
movl   $0xffffffff,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_description_from_file>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
test   %rdi,%rdi
je     1245 <set_description_from_file+0xc5>
lea    0xe67(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1239 <set_description_from_file+0xb9>
mov    %rax,%r14
mov    0x2e37(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1050 <ftell@plt>
lea    0x1(%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%r13
mov    0x2df6(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   10a0 <getc@plt>
mov    0x2deb(%rip),%r12
cmp    (%r12),%eax
je     121a <set_description_from_file+0x9a>
xor    %ebx,%ebx
nopl   (%rax)
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   10a0 <getc@plt>
cmp    (%r12),%eax
jne    1200 <set_description_from_file+0x80>
mov    %ebx,%r15d
movb   $0x0,0x0(%r13,%r15,1)
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r13,%rdi
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
jmp    1060 <set_description@plt>
lea    0xdc2(%rip),%rdi
call   1040 <printf@plt>
mov    $0xffffffff,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"Error! opening file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @set_description_from_file(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %3
%9 = load i8*, i8** %3
%10 = icmp ne i8* %9, null
br i1 %10, label %11, label %51
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = call i32* @fopen(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %13, i32** %4
%14 = icmp eq i32* %13, null
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
br label %52
17: ; preds = %11
%18 = load i32*, i32** %4
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i64 0, i32 %19)
%21 = load i32*, i32** %4
%22 = call i32 @ftell(i32* %21)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = add nsw i32 %23, 1
%25 = call i8* @malloc(i32 %24)
store i8* %25, i8** %6
%26 = load i32*, i32** %4
%27 = load i32, i32* @SEEK_SET
%28 = call i32 @fseek(i32* %26, i64 0, i32 %27)
store i32 0, i32* %8
br label %29
29: ; preds = %34, %17
%30 = load i32*, i32** %4
%31 = call i32 @getc(i32* %30)
store i32 %31, i32* %7
%32 = load i32, i32* @EOF
%33 = icmp ne i32 %31, %32
br i1 %33, label %34, label %42
34: ; preds = %29
%35 = load i32, i32* %7
%36 = trunc i32 %35 to i8
%37 = load i8*, i8** %6
%38 = load i32, i32* %8
%39 = add nsw i32 %38, 1
store i32 %39, i32* %8
%40 = sext i32 %38 to i64
%41 = getelementptr inbounds i8, i8* %37, i64 %40
store i8 %36, i8* %41
br label %29
42: ; preds = %29
%43 = load i8*, i8** %6
%44 = load i32, i32* %8
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8, i8* %43, i64 %45
store i8 0, i8* %46
%47 = load i32*, i32** %4
%48 = call i32 @fclose(i32* %47)
%49 = load i8*, i8** %6
%50 = call i32 @set_description(i8* %49)
store i32 %50, i32* %2
br label %52
51: ; preds = %1
store i32 -1, i32* %2
br label %52
52: ; preds = %51, %42, %15
%53 = load i32, i32* %2
ret i32 %53
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [20 x i8] c"Error! opening file\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i32 0
define i32 @set_description_from_file(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %35, label %3
3: ; preds = %1
%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 %6, label %8
6: ; preds = %3
%7 = tail call i32 @printf(i8* dereferenceable(1) getelementptr inbounds ([20 x i8], [20 x i8]* @.str.1, i64 0, i64 0))
br label %35
8: ; preds = %3
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %4, i64 0, i32 %9)
%11 = tail call i32 @ftell(i32* %4)
%12 = add nsw i32 %11, 1
%13 = tail call i8* @malloc(i32 %12)
%14 = load i32, i32* @SEEK_SET
%15 = tail call i32 @fseek(i32* %4, i64 0, i32 %14)
%16 = tail call i32 @getc(i32* %4)
%17 = load i32, i32* @EOF
%18 = icmp eq i32 %16, %17
br i1 %18, label %30, label %19
19: ; preds = %8, %19
%20 = phi i64 [ %23, %19 ], [ 0, %8 ]
%21 = phi i32 [ %25, %19 ], [ %16, %8 ]
%22 = trunc i32 %21 to i8
%23 = add nuw i64 %20, 1
%24 = getelementptr inbounds i8, i8* %13, i64 %20
store i8 %22, i8* %24
%25 = tail call i32 @getc(i32* %4)
%26 = load i32, i32* @EOF
%27 = icmp eq i32 %25, %26
br i1 %27, label %28, label %19
28: ; preds = %19
%29 = and i64 %23, 4294967295
br label %30
30: ; preds = %28, %8
%31 = phi i64 [ 0, %8 ], [ %29, %28 ]
%32 = getelementptr inbounds i8, i8* %13, i64 %31
store i8 0, i8* %32
%33 = tail call i32 @fclose(i32* %4)
%34 = tail call i32 @set_description(i8* %13)
br label %35
35: ; preds = %1, %6, %30
%36 = phi i32 [ -1, %6 ], [ %34, %30 ], [ -1, %1 ]
ret i32 %36
}