#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 fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fputc(char, int /*<<< orphan*/ *);
int /*<<< orphan*/ putc(char, int /*<<< orphan*/);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ unlink(char *);
int main() {
  FILE *tmp;
  int ch;
  putc('c', stdout);
  putc('\n', stdout);
  tmp = fopen("putc.tmp", "w");
  fputc('a', tmp);
  fclose(tmp);
  tmp = fopen("putc.tmp", "r");
  ch = fgetc(tmp);
  fclose(tmp);
  if (ch != 'a') {
    return 4;
  }
  unlink("putc.tmp");
  puts("putc seems to work");
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%esi
mov    $0x63,%edi
call   1080 <putc@plt>
mov    0x2e47(%rip),%rax
mov    (%rax),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    0xe54(%rip),%rdi
lea    0xe56(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rsi
mov    $0x61,%edi
call   1070 <fputc@plt>
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
lea    0xe26(%rip),%rdi
lea    0xe2a(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1060 <fgetc@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <fclose@plt>
cmpl   $0x61,-0x14(%rbp)
je     1215 <main+0xa5>
movl   $0x4,-0x4(%rbp)
jmp    1234 <main+0xc4>
lea    0xde4(%rip),%rdi
call   1030 <unlink@plt>
lea    0xde5(%rip),%rdi
call   1040 <puts@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
mov    0x2e65(%rip),%rbx
mov    (%rbx),%esi
mov    $0x63,%edi
call   1080 <putc@plt>
mov    (%rbx),%esi
mov    $0xa,%edi
call   1080 <putc@plt>
lea    0xe66(%rip),%r14
lea    0xe68(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    $0x61,%edi
mov    %rax,%rsi
call   1070 <fputc@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe43(%rip),%rsi
mov    %r14,%rdi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <fgetc@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    $0x4,%eax
cmp    $0x61,%ebp
jne    1209 <main+0x99>
lea    0xe0a(%rip),%rdi
call   1030 <unlink@plt>
lea    0xe0b(%rip),%rdi
call   1040 <puts@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [9 x i8] c"putc.tmp\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"putc seems to work\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i32
store i32 0, i32* %1
%4 = load i32, i32* @stdout
%5 = call i32 @putc(i8 signext 99, i32 %4)
%6 = load i32, i32* @stdout
%7 = call i32 @putc(i8 signext 10, i32 %6)
%8 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = call i32 @fputc(i8 signext 97, i32* %9)
%11 = load i32*, i32** %2
%12 = call i32 @fclose(i32* %11)
%13 = call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %13, i32** %2
%14 = load i32*, i32** %2
%15 = call i32 @fgetc(i32* %14)
store i32 %15, i32* %3
%16 = load i32*, i32** %2
%17 = call i32 @fclose(i32* %16)
%18 = load i32, i32* %3
%19 = icmp ne i32 %18, 97
br i1 %19, label %20, label %21
20: ; preds = %0
store i32 4, i32* %1
br label %24
21: ; preds = %0
%22 = call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @puts(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %24
24: ; preds = %21, %20
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [9 x i8] c"putc.tmp\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [19 x i8] c"putc seems to work\00"
define i32 @main() {
%1 = load i32, i32* @stdout
%2 = tail call i32 @putc(i8 signext 99, i32 %1)
%3 = load i32, i32* @stdout
%4 = tail call i32 @putc(i8 signext 10, i32 %3)
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = tail call i32 @fputc(i8 signext 97, i32* %5)
%7 = tail call i32 @fclose(i32* %5)
%8 = tail call i32* @fopen(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%9 = tail call i32 @fgetc(i32* %8)
%10 = tail call i32 @fclose(i32* %8)
%11 = icmp eq i32 %9, 97
br i1 %11, label %12, label %15
12: ; preds = %0
%13 = tail call i32 @unlink(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0))
br label %15
15: ; preds = %0, %12
%16 = phi i32 [ 0, %12 ], [ 4, %0 ]
ret i32 %16
}