#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*/ fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ perror(char *);
char *strchr(char *, char);
int get_credentials(char *buffer) {
  char *p;
  FILE *fp = NULL;
  fp = fopen("preferences.txt", "r");
  if (fp == NULL) {
    perror("Cannot open file");
    return 1;
  }
  fgets(buffer, 80 + 1, fp);
  fclose(fp);
  if ((p = strchr(buffer, '\n')) != NULL) {
    *p = '\0';
  }
  return 0;
}


x86 assembly (clang, -O0):
<get_credentials>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
lea    0xe95(%rip),%rdi
lea    0xe9e(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    119e <get_credentials+0x4e>
lea    0xe85(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    11e3 <get_credentials+0x93>
mov    -0x10(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x51,%esi
call   1050 <fgets@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x10(%rbp),%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
je     11dc <get_credentials+0x8c>
mov    -0x18(%rbp),%rax
movb   $0x0,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_credentials>:
push   %r14
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xea2(%rip),%rdi
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     11ac <get_credentials+0x5c>
mov    %rax,%rbx
mov    %r14,%rdi
mov    $0x51,%esi
mov    %rax,%rdx
call   1050 <fgets@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %r14,%rdi
mov    $0xa,%esi
call   1040 <strchr@plt>
mov    %rax,%rcx
xor    %eax,%eax
test   %rcx,%rcx
je     11a4 <get_credentials+0x54>
movb   $0x0,(%rcx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
mov    $0x1,%eax
jmp    11a4 <get_credentials+0x54>

LLVM IR (-O0):
@.str = [16 x i8] c"preferences.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Cannot open file\00"
define i32 @get_credentials(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
store i8* %0, i8** %3
store i32* null, i32** %5
%6 = call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = load i32*, i32** %5
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %11
9: ; preds = %1
%10 = call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %2
br label %23
11: ; preds = %1
%12 = load i8*, i8** %3
%13 = load i32*, i32** %5
%14 = call i32 @fgets(i8* %12, i32 81, i32* %13)
%15 = load i32*, i32** %5
%16 = call i32 @fclose(i32* %15)
%17 = load i8*, i8** %3
%18 = call i8* @strchr(i8* %17, i8 signext 10)
store i8* %18, i8** %4
%19 = icmp ne i8* %18, null
br i1 %19, label %20, label %22
20: ; preds = %11
%21 = load i8*, i8** %4
store i8 0, i8* %21
br label %22
22: ; preds = %20, %11
store i32 0, i32* %2
br label %23
23: ; preds = %22, %9
%24 = load i32, i32* %2
ret i32 %24
}

LLVM IR (-O2):
@.str = [16 x i8] c"preferences.txt\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [17 x i8] c"Cannot open file\00"
define i32 @get_credentials(i8* %0) {
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = tail call i32 @perror(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0))
br label %12
6: ; preds = %1
%7 = tail call i32 @fgets(i8* %0, i32 81, i32* %2)
%8 = tail call i32 @fclose(i32* %2)
%9 = tail call i8* @strchr(i8* dereferenceable(1) %0, i8 signext 10)
%10 = icmp eq i8* %9, null
br i1 %10, label %12, label %11
11: ; preds = %6
store i8 0, i8* %9
br label %12
12: ; preds = %6, %11, %4
%13 = phi i32 [ 1, %4 ], [ 0, %11 ], [ 0, %6 ]
ret i32 %13
}