#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*/ assert(int);
scalar_t__ calloc(int, int);
int chdir(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, char *);
int /*<<< orphan*/ free(int *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, char *);
scalar_t__ malloc(int);
int printf(char *, char *);
scalar_t__ strlen(char *);
int main(int argc, char **argv) {
  char read[100];
  int ret;
  int *mal = (int *)malloc(sizeof(int));
  assert(mal != NULL);
  free(mal);
  int *cal = (int *)calloc(1, sizeof(int));
  assert(cal != NULL);
  free(cal);
  mal = (int *)malloc(sizeof(int));
  assert(mal != NULL);
  free(mal);
  FILE *fp = fopen("foo.txt", "w");
  assert(fp != NULL);
  fprintf(fp, "%s\n", "hello world");
  fclose(fp);
  int x = chdir("..");
  assert(x == 0);
  cal = (int *)calloc(1, sizeof(int));
  assert(cal != NULL);
  free(cal);
  fp = fopen("foo.txt", "r");
  assert(fp != NULL);
  fscanf(fp, "%s", read);
  ret = printf("%s\n", read);
  assert(ret == (int)strlen(read));
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x4,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
mov    $0x1,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   10c0 <malloc@plt>
mov    %rax,-0x90(%rbp)
cmpq   $0x0,-0x90(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x90(%rbp),%rdi
call   1030 <free@plt>
lea    0xd95(%rip),%rdi
lea    0xd96(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0xa0(%rbp),%rdi
lea    0xd69(%rip),%rsi
lea    0xd66(%rip),%rdx
call   10b0 <fprintf@plt>
mov    -0xa0(%rbp),%rdi
call   1040 <fclose@plt>
lea    0xd5a(%rip),%rdi
call   1060 <chdir@plt>
mov    %eax,-0xa4(%rbp)
cmpl   $0x0,-0xa4(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    $0x1,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,-0x98(%rbp)
cmpq   $0x0,-0x98(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0x98(%rbp),%rdi
call   1030 <free@plt>
lea    0xce3(%rip),%rdi
lea    0xcf9(%rip),%rsi
call   10d0 <fopen@plt>
mov    %rax,-0xa0(%rbp)
cmpq   $0x0,-0xa0(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0xa0(%rbp),%rdi
lea    -0x80(%rbp),%rdx
lea    0xcc8(%rip),%rsi
call   1080 <fscanf@plt>
lea    -0x80(%rbp),%rsi
lea    0xca3(%rip),%rdi
call   1070 <printf@plt>
mov    %eax,-0x84(%rbp)
mov    -0x84(%rbp),%eax
mov    %eax,-0xa8(%rbp)
lea    -0x80(%rbp),%rdi
call   1050 <strlen@plt>
mov    %rax,%rcx
mov    -0xa8(%rbp),%eax
cmp    %ecx,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
mov    -0xa0(%rbp),%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x68,%rsp
mov    $0x4,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x1,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
mov    $0x4,%edi
call   10c0 <malloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xdd1(%rip),%r15
lea    0xdd2(%rip),%rsi
mov    %r15,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10a0 <assert@plt>
lea    0xdb4(%rip),%r14
lea    0xdb1(%rip),%rdx
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
lea    0xda3(%rip),%rdi
call   1060 <chdir@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   10a0 <assert@plt>
mov    $0x1,%edi
mov    $0x4,%esi
call   1090 <calloc@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   1030 <free@plt>
lea    0xd65(%rip),%rsi
mov    %r15,%rdi
call   10d0 <fopen@plt>
mov    %rax,%rbx
xor    %edi,%edi
test   %rax,%rax
setne  %dil
call   10a0 <assert@plt>
lea    0xd47(%rip),%rsi
mov    %rsp,%r15
mov    %rbx,%rdi
mov    %r15,%rdx
call   1080 <fscanf@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <printf@plt>
mov    %eax,%ebp
mov    %r15,%rdi
call   1050 <strlen@plt>
xor    %edi,%edi
cmp    %eax,%ebp
sete   %dil
call   10a0 <assert@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %eax,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [8 x i8] c"foo.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [12 x i8] c"hello world\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [100 x i8]
%7 = alloca i32
%8 = alloca i32*
%9 = alloca i32*
%10 = alloca i32*
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = call i64 @malloc(i32 4)
%13 = inttoptr i64 %12 to i32*
store i32* %13, i32** %8
%14 = load i32*, i32** %8
%15 = icmp ne i32* %14, null
%16 = zext i1 %15 to i32
%17 = call i32 @assert(i32 %16)
%18 = load i32*, i32** %8
%19 = call i32 @free(i32* %18)
%20 = call i64 @calloc(i32 1, i32 4)
%21 = inttoptr i64 %20 to i32*
store i32* %21, i32** %9
%22 = load i32*, i32** %9
%23 = icmp ne i32* %22, null
%24 = zext i1 %23 to i32
%25 = call i32 @assert(i32 %24)
%26 = load i32*, i32** %9
%27 = call i32 @free(i32* %26)
%28 = call i64 @malloc(i32 4)
%29 = inttoptr i64 %28 to i32*
store i32* %29, i32** %8
%30 = load i32*, i32** %8
%31 = icmp ne i32* %30, null
%32 = zext i1 %31 to i32
%33 = call i32 @assert(i32 %32)
%34 = load i32*, i32** %8
%35 = call i32 @free(i32* %34)
%36 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %36, i32** %10
%37 = load i32*, i32** %10
%38 = icmp ne i32* %37, null
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
%41 = load i32*, i32** %10
%42 = call i32 @fprintf(i32* %41, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%43 = load i32*, i32** %10
%44 = call i32 @fclose(i32* %43)
%45 = call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
store i32 %45, i32* %11
%46 = load i32, i32* %11
%47 = icmp eq i32 %46, 0
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = call i64 @calloc(i32 1, i32 4)
%51 = inttoptr i64 %50 to i32*
store i32* %51, i32** %9
%52 = load i32*, i32** %9
%53 = icmp ne i32* %52, null
%54 = zext i1 %53 to i32
%55 = call i32 @assert(i32 %54)
%56 = load i32*, i32** %9
%57 = call i32 @free(i32* %56)
%58 = call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
store i32* %58, i32** %10
%59 = load i32*, i32** %10
%60 = icmp ne i32* %59, null
%61 = zext i1 %60 to i32
%62 = call i32 @assert(i32 %61)
%63 = load i32*, i32** %10
%64 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%65 = call i32 @fscanf(i32* %63, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %64)
%66 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%67 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %66)
store i32 %67, i32* %7
%68 = load i32, i32* %7
%69 = getelementptr inbounds [100 x i8], [100 x i8]* %6, i64 0, i64 0
%70 = call i64 @strlen(i8* %69)
%71 = trunc i64 %70 to i32
%72 = icmp eq i32 %68, %71
%73 = zext i1 %72 to i32
%74 = call i32 @assert(i32 %73)
%75 = load i32*, i32** %10
%76 = call i32 @fclose(i32* %75)
ret i32 0
}

LLVM IR (-O2):
@.str = [8 x i8] c"foo.txt\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [4 x i8] c"%s\0A\00"
@.str.3 = [12 x i8] c"hello world\00"
@.str.4 = [3 x i8] c"..\00"
@.str.5 = [2 x i8] c"r\00"
@.str.6 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [100 x i8]
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %3, i64 0, i64 0
%5 = tail call i64 @malloc(i32 4)
%6 = inttoptr i64 %5 to i32*
%7 = icmp ne i64 %5, 0
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = tail call i32 @free(i32* %6)
%11 = tail call i64 @calloc(i32 1, i32 4)
%12 = inttoptr i64 %11 to i32*
%13 = icmp ne i64 %11, 0
%14 = zext i1 %13 to i32
%15 = tail call i32 @assert(i32 %14)
%16 = tail call i32 @free(i32* %12)
%17 = tail call i64 @malloc(i32 4)
%18 = inttoptr i64 %17 to i32*
%19 = icmp ne i64 %17, 0
%20 = zext i1 %19 to i32
%21 = tail call i32 @assert(i32 %20)
%22 = tail call i32 @free(i32* %18)
%23 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp ne i32* %23, null
%25 = zext i1 %24 to i32
%26 = tail call i32 @assert(i32 %25)
%27 = tail call i32 @fprintf(i32* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0))
%28 = tail call i32 @fclose(i32* %23)
%29 = tail call i32 @chdir(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%30 = icmp eq i32 %29, 0
%31 = zext i1 %30 to i32
%32 = tail call i32 @assert(i32 %31)
%33 = tail call i64 @calloc(i32 1, i32 4)
%34 = inttoptr i64 %33 to i32*
%35 = icmp ne i64 %33, 0
%36 = zext i1 %35 to i32
%37 = tail call i32 @assert(i32 %36)
%38 = tail call i32 @free(i32* %34)
%39 = tail call i32* @fopen(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i64 0, i64 0))
%40 = icmp ne i32* %39, null
%41 = zext i1 %40 to i32
%42 = tail call i32 @assert(i32 %41)
%43 = call i32 @fscanf(i32* %39, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* %4)
%44 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %4)
%45 = call i64 @strlen(i8* %4)
%46 = trunc i64 %45 to i32
%47 = icmp eq i32 %44, %46
%48 = zext i1 %47 to i32
%49 = call i32 @assert(i32 %48)
%50 = call i32 @fclose(i32* %39)
ret i32 0
}