#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*/ *fopen(char *, char *);
char getc(int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ *stdin;
int main(void) {
  char c;
  FILE *fp;
  printf("stdin: ");
  c = getc(stdin);
  printf("stdin: c = %c\n", c);
  fp = fopen("test1.txt", "r");
  if (fp == NULL) {
    perror("test1.txt");
    return -1;
  }
  c = getc(fp);
  printf("fp: c = %c\n", c);
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe9a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2e74(%rip),%rax
mov    (%rax),%rdi
call   1070 <getc@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%esi
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    0xe7f(%rip),%rdi
lea    0xe82(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11cb <main+0x7b>
lea    0xe5d(%rip),%rdi
call   1060 <perror@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11f9 <main+0xa9>
mov    -0x10(%rbp),%rdi
call   1070 <getc@plt>
mov    %al,-0x5(%rbp)
movsbl -0x5(%rbp),%esi
lea    0xe41(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xea6(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e7e(%rip),%rax
mov    (%rax),%rdi
call   1070 <getc@plt>
movsbl %al,%esi
lea    0xe8c(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe8d(%rip),%rdi
lea    0xe90(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     11c8 <main+0x78>
mov    %rax,%rbx
mov    %rax,%rdi
call   1070 <getc@plt>
movsbl %al,%esi
lea    0xe73(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe48(%rip),%rdi
call   1060 <perror@plt>
mov    $0xffffffff,%ebp
jmp    11bf <main+0x6f>

LLVM IR (-O0):
@.str = [8 x i8] c"stdin: \00"
@stdin = global i32* null
@.str.1 = [15 x i8] c"stdin: c = %c\0A\00"
@.str.2 = [10 x i8] c"test1.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [12 x i8] c"fp: c = %c\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i8
%3 = alloca i32*
store i32 0, i32* %1
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%5 = load i32*, i32** @stdin
%6 = call signext i8 @getc(i32* %5)
store i8 %6, i8* %2
%7 = load i8, i8* %2
%8 = sext i8 %7 to i32
%9 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
store i32* %10, i32** %3
%11 = load i32*, i32** %3
%12 = icmp eq i32* %11, null
br i1 %12, label %13, label %15
13: ; preds = %0
%14 = call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %23
15: ; preds = %0
%16 = load i32*, i32** %3
%17 = call signext i8 @getc(i32* %16)
store i8 %17, i8* %2
%18 = load i8, i8* %2
%19 = sext i8 %18 to i32
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %19)
%21 = load i32*, i32** %3
%22 = call i32 @fclose(i32* %21)
store i32 0, i32* %1
br label %23
23: ; preds = %15, %13
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
@.str = [8 x i8] c"stdin: \00"
@stdin = global i32* null
@.str.1 = [15 x i8] c"stdin: c = %c\0A\00"
@.str.2 = [10 x i8] c"test1.txt\00"
@.str.3 = [2 x i8] c"r\00"
@.str.4 = [12 x i8] c"fp: c = %c\0A\00"
define i32 @main() {
%1 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0))
%2 = load i32*, i32** @stdin
%3 = tail call signext i8 @getc(i32* %2)
%4 = sext i8 %3 to i32
%5 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i32 %4)
%6 = tail call i32* @fopen(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i64 0, i64 0))
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = tail call i32 @perror(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0))
br label %15
10: ; preds = %0
%11 = tail call signext i8 @getc(i32* %6)
%12 = sext i8 %11 to i32
%13 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 %12)
%14 = tail call i32 @fclose(i32* %6)
br label %15
15: ; preds = %10, %8
%16 = phi i32 [ -1, %8 ], [ 0, %10 ]
ret i32 %16
}