#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*/ mapping_chdir(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ pwd();
int main(int argc, char **argv) {
  char orig_path[10 + 20];
  FILE *f;
  f = fopen("pathfile", "r");
  fgets(orig_path, 10 + 20, f);
  fclose(f);
  if (0)
    printf("orig_path = %s\n", orig_path);
  mapping_chdir(orig_path);
  pwd();
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe93(%rip),%rdi
lea    0xe95(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x38(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    $0x1e,%esi
call   1060 <fgets@plt>
mov    -0x38(%rbp),%rdi
call   1040 <fclose@plt>
lea    -0x30(%rbp),%rdi
call   1030 <mapping_chdir@plt>
mov    $0x0,%al
call   1050 <pwd@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x28,%rsp
lea    0xea2(%rip),%rdi
lea    0xea4(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
mov    $0x1e,%esi
mov    %rax,%rdx
call   1060 <fgets@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14,%rdi
call   1030 <mapping_chdir@plt>
xor    %eax,%eax
call   1050 <pwd@plt>
xor    %eax,%eax
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [9 x i8] c"pathfile\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [30 x i8]
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%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** %7
%9 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%10 = load i32*, i32** %7
%11 = call i32 @fgets(i8* %9, i32 30, i32* %10)
%12 = load i32*, i32** %7
%13 = call i32 @fclose(i32* %12)
%14 = getelementptr inbounds [30 x i8], [30 x i8]* %6, i64 0, i64 0
%15 = call i32 @mapping_chdir(i8* %14)
%16 = call i32 (...) @pwd()
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"pathfile\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [30 x i8]
%4 = getelementptr inbounds [30 x i8], [30 x i8]* %3, i64 0, i64 0
%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 = call i32 @fgets(i8* %4, i32 30, i32* %5)
%7 = call i32 @fclose(i32* %5)
%8 = call i32 @mapping_chdir(i8* %4)
%9 = call i32 (...) @pwd()
ret i32 0
}