#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 STDERR_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fdopen(int, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/ *, char *, ...);
char *getcwd(int /*<<< orphan*/ *, int /*<<< orphan*/);
int /*<<< orphan*/ *stderr;
int /*<<< orphan*/ *stdout;
int /*<<< orphan*/ xfree(char *);
int sd_pwd(int argc, char **argv, int in, int out, int err) {
  char *pwd;
  FILE *fdout = stdout, *fderr = stderr;
  do {
    if (out != STDOUT_FILENO)
      if (out == err)
        fdout = fderr;
      else
        fdout = fdopen(out, "a");
    else
      fdout = stdout;
    if (err != STDERR_FILENO)
      fderr = fdopen(err, "a");
    else
      fderr = stderr;
  } while (0);
  ;
  if (argc > 0) {
    fprintf(fderr, "ERROR: too many arguments\n");
    fprintf(fderr, "usage: pwd\n");
    do {
      if (out != STDOUT_FILENO)
        fclose(fdout);
      if (err != STDERR_FILENO && err != out)
        fclose(fderr);
    } while (0);
    ;
    return 1;
  }
  pwd = getcwd(NULL, 0);
  fprintf(fdout, "%s\n", pwd);
  xfree(pwd);
  do {
    if (out != STDOUT_FILENO)
      fclose(fdout);
    if (err != STDERR_FILENO && err != out)
      fclose(fderr);
  } while (0);
  ;
  (void)argv;
  (void)in;
  return 0;
}


x86 assembly (clang, -O0):
<sd_pwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    %r8d,-0x1c(%rbp)
mov    0x2e58(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%eax
mov    0x2e61(%rip),%rcx
cmp    (%rcx),%eax
je     11c8 <sd_pwd+0x78>
mov    -0x18(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jne    11b0 <sd_pwd+0x60>
mov    -0x38(%rbp),%rax
mov    %rax,-0x30(%rbp)
jmp    11c3 <sd_pwd+0x73>
mov    -0x18(%rbp),%edi
lea    0xe46(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,-0x30(%rbp)
jmp    11d6 <sd_pwd+0x86>
mov    0x2df9(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x1c(%rbp),%eax
mov    0x2df0(%rip),%rcx
cmp    (%rcx),%eax
je     1200 <sd_pwd+0xb0>
mov    -0x1c(%rbp),%edi
lea    0xe0e(%rip),%rsi
call   1070 <fdopen@plt>
mov    %rax,-0x38(%rbp)
jmp    120e <sd_pwd+0xbe>
mov    0x2dd1(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x38(%rbp)
jmp    1213 <sd_pwd+0xc3>
cmpl   $0x0,-0x8(%rbp)
jle    1294 <sd_pwd+0x144>
mov    -0x38(%rbp),%rdi
lea    0xdda(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x38(%rbp),%rdi
lea    0xde3(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x18(%rbp),%eax
mov    0x2da5(%rip),%rcx
cmp    (%rcx),%eax
je     125c <sd_pwd+0x10c>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    0x2d6a(%rip),%rcx
cmp    (%rcx),%eax
je     1283 <sd_pwd+0x133>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1283 <sd_pwd+0x133>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1288 <sd_pwd+0x138>
movl   $0x1,-0x4(%rbp)
jmp    1310 <sd_pwd+0x1c0>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,-0x28(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x28(%rbp),%rdx
lea    0xd77(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x28(%rbp),%rdi
call   1040 <xfree@plt>
mov    -0x18(%rbp),%eax
mov    0x2d24(%rip),%rcx
cmp    (%rcx),%eax
je     12dd <sd_pwd+0x18d>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    0x2ce9(%rip),%rcx
cmp    (%rcx),%eax
je     1304 <sd_pwd+0x1b4>
mov    -0x1c(%rbp),%eax
cmp    -0x18(%rbp),%eax
je     1304 <sd_pwd+0x1b4>
mov    -0x38(%rbp),%rdi
call   1030 <fclose@plt>
jmp    1309 <sd_pwd+0x1b9>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sd_pwd>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %r8d,%ebx
mov    %ecx,%ebp
mov    %edi,%r12d
mov    0x2e76(%rip),%r13
cmp    %ecx,0x0(%r13)
jne    1189 <sd_pwd+0x29>
mov    0x2e41(%rip),%rax
jmp    1194 <sd_pwd+0x34>
cmp    %ebx,%ebp
jne    1199 <sd_pwd+0x39>
mov    0x2e44(%rip),%rax
mov    (%rax),%r15
jmp    11aa <sd_pwd+0x4a>
lea    0xe60(%rip),%rsi
mov    %ebp,%edi
call   1070 <fdopen@plt>
mov    %rax,%r15
mov    0x2e1f(%rip),%rax
cmp    %ebx,(%rax)
jne    1204 <sd_pwd+0xa4>
mov    0x2e1c(%rip),%rax
mov    (%rax),%r14
test   %r12d,%r12d
jg     121a <sd_pwd+0xba>
xor    %r12d,%r12d
xor    %edi,%edi
xor    %esi,%esi
call   1050 <getcwd@plt>
mov    %rax,%r13
lea    0xe4f(%rip),%rsi
mov    %r15,%rdi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    %r13,%rdi
call   1040 <xfree@plt>
mov    0x2dfa(%rip),%rax
cmp    %ebp,(%rax)
je     1260 <sd_pwd+0x100>
mov    %r15,%rdi
call   1030 <fclose@plt>
jmp    1260 <sd_pwd+0x100>
lea    0xdf5(%rip),%rsi
mov    %ebx,%edi
call   1070 <fdopen@plt>
mov    %rax,%r14
test   %r12d,%r12d
jle    11c4 <sd_pwd+0x64>
lea    0xde1(%rip),%rdi
mov    $0x1a,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
lea    0xde3(%rip),%rdi
mov    $0xb,%esi
mov    $0x1,%edx
mov    %r14,%rcx
call   1080 <fwrite@plt>
cmp    %ebp,0x0(%r13)
je     125a <sd_pwd+0xfa>
mov    %r15,%rdi
call   1030 <fclose@plt>
mov    $0x1,%r12d
cmp    %ebp,%ebx
je     1277 <sd_pwd+0x117>
mov    0x2d65(%rip),%rax
cmp    %ebx,(%rax)
je     1277 <sd_pwd+0x117>
mov    %r14,%rdi
call   1030 <fclose@plt>
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32* null
@stderr = global i32* null
@STDOUT_FILENO = global i32 0
@.str = [2 x i8] c"a\00"
@STDERR_FILENO = global i32 0
@.str.1 = [27 x i8] c"ERROR: too many arguments\0A\00"
@.str.2 = [12 x i8] c"usage: pwd\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @sd_pwd(i32 %0, i8** %1, i32 %2, i32 %3, i32 %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8**
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i8*
%13 = alloca i32*
%14 = alloca i32*
store i32 %0, i32* %7
store i8** %1, i8*** %8
store i32 %2, i32* %9
store i32 %3, i32* %10
store i32 %4, i32* %11
%15 = load i32*, i32** @stdout
store i32* %15, i32** %13
%16 = load i32*, i32** @stderr
store i32* %16, i32** %14
br label %17
17: ; preds = %5
%18 = load i32, i32* %10
%19 = load i32, i32* @STDOUT_FILENO
%20 = icmp ne i32 %18, %19
br i1 %20, label %21, label %31
21: ; preds = %17
%22 = load i32, i32* %10
%23 = load i32, i32* %11
%24 = icmp eq i32 %22, %23
br i1 %24, label %25, label %27
25: ; preds = %21
%26 = load i32*, i32** %14
store i32* %26, i32** %13
br label %30
27: ; preds = %21
%28 = load i32, i32* %10
%29 = call i32* @fdopen(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %29, i32** %13
br label %30
30: ; preds = %27, %25
br label %33
31: ; preds = %17
%32 = load i32*, i32** @stdout
store i32* %32, i32** %13
br label %33
33: ; preds = %31, %30
%34 = load i32, i32* %11
%35 = load i32, i32* @STDERR_FILENO
%36 = icmp ne i32 %34, %35
br i1 %36, label %37, label %40
37: ; preds = %33
%38 = load i32, i32* %11
%39 = call i32* @fdopen(i32 %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %39, i32** %14
br label %42
40: ; preds = %33
%41 = load i32*, i32** @stderr
store i32* %41, i32** %14
br label %42
42: ; preds = %40, %37
br label %43
43: ; preds = %42
%44 = load i32, i32* %7
%45 = icmp sgt i32 %44, 0
br i1 %45, label %46, label %71
46: ; preds = %43
%47 = load i32*, i32** %14
%48 = call i32 (i32*, i8*, ...) @fprintf(i32* %47, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
%49 = load i32*, i32** %14
%50 = call i32 (i32*, i8*, ...) @fprintf(i32* %49, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0))
br label %51
51: ; preds = %46
%52 = load i32, i32* %10
%53 = load i32, i32* @STDOUT_FILENO
%54 = icmp ne i32 %52, %53
br i1 %54, label %55, label %58
55: ; preds = %51
%56 = load i32*, i32** %13
%57 = call i32 @fclose(i32* %56)
br label %58
58: ; preds = %55, %51
%59 = load i32, i32* %11
%60 = load i32, i32* @STDERR_FILENO
%61 = icmp ne i32 %59, %60
br i1 %61, label %62, label %69
62: ; preds = %58
%63 = load i32, i32* %11
%64 = load i32, i32* %10
%65 = icmp ne i32 %63, %64
br i1 %65, label %66, label %69
66: ; preds = %62
%67 = load i32*, i32** %14
%68 = call i32 @fclose(i32* %67)
br label %69
69: ; preds = %66, %62, %58
br label %70
70: ; preds = %69
store i32 1, i32* %6
br label %100
71: ; preds = %43
%72 = call i8* @getcwd(i32* null, i32 0)
store i8* %72, i8** %12
%73 = load i32*, i32** %13
%74 = load i8*, i8** %12
%75 = call i32 (i32*, i8*, ...) @fprintf(i32* %73, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %74)
%76 = load i8*, i8** %12
%77 = call i32 @xfree(i8* %76)
br label %78
78: ; preds = %71
%79 = load i32, i32* %10
%80 = load i32, i32* @STDOUT_FILENO
%81 = icmp ne i32 %79, %80
br i1 %81, label %82, label %85
82: ; preds = %78
%83 = load i32*, i32** %13
%84 = call i32 @fclose(i32* %83)
br label %85
85: ; preds = %82, %78
%86 = load i32, i32* %11
%87 = load i32, i32* @STDERR_FILENO
%88 = icmp ne i32 %86, %87
br i1 %88, label %89, label %96
89: ; preds = %85
%90 = load i32, i32* %11
%91 = load i32, i32* %10
%92 = icmp ne i32 %90, %91
br i1 %92, label %93, label %96
93: ; preds = %89
%94 = load i32*, i32** %14
%95 = call i32 @fclose(i32* %94)
br label %96
96: ; preds = %93, %89, %85
br label %97
97: ; preds = %96
%98 = load i8**, i8*** %8
%99 = load i32, i32* %9
store i32 0, i32* %6
br label %100
100: ; preds = %97, %70
%101 = load i32, i32* %6
ret i32 %101
}

LLVM IR (-O2):
@stdout = global i32* null
@stderr = global i32* null
@STDOUT_FILENO = global i32 0
@.str = [2 x i8] c"a\00"
@STDERR_FILENO = global i32 0
@.str.1 = [27 x i8] c"ERROR: too many arguments\0A\00"
@.str.2 = [12 x i8] c"usage: pwd\0A\00"
@.str.3 = [4 x i8] c"%s\0A\00"
define i32 @sd_pwd(i32 %0, i8** nocapture readnone %1, i32 %2, i32 %3, i32 %4) {
%6 = load i32, i32* @STDOUT_FILENO
%7 = icmp eq i32 %6, %3
br i1 %7, label %13, label %8
8: ; preds = %5
%9 = load i32*, i32** @stderr
%10 = icmp eq i32 %3, %4
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = tail call i32* @fdopen(i32 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %15
13: ; preds = %5
%14 = load i32*, i32** @stdout
br label %15
15: ; preds = %8, %11, %13
%16 = phi i32* [ %12, %11 ], [ %14, %13 ], [ %9, %8 ]
%17 = load i32, i32* @STDERR_FILENO
%18 = icmp eq i32 %17, %4
br i1 %18, label %21, label %19
19: ; preds = %15
%20 = tail call i32* @fdopen(i32 %4, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
br label %23
21: ; preds = %15
%22 = load i32*, i32** @stderr
br label %23
23: ; preds = %21, %19
%24 = phi i32* [ %20, %19 ], [ %22, %21 ]
%25 = icmp sgt i32 %0, 0
br i1 %25, label %26, label %38
26: ; preds = %23
%27 = tail call i64 @fwrite(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), i64 26, i64 1, i32* %24)
%28 = tail call i64 @fwrite(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i64 11, i64 1, i32* %24)
%29 = load i32, i32* @STDOUT_FILENO
%30 = icmp eq i32 %29, %3
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = tail call i32 @fclose(i32* %16)
br label %33
33: ; preds = %31, %26
%34 = load i32, i32* @STDERR_FILENO
%35 = icmp eq i32 %34, %4
%36 = icmp eq i32 %4, %3
%37 = or i1 %36, %35
br i1 %37, label %54, label %51
38: ; preds = %23
%39 = tail call i8* @getcwd(i32* null, i32 0)
%40 = tail call i32 (i32*, i8*, ...) @fprintf(i32* %16, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8* %39)
%41 = tail call i32 @xfree(i8* %39)
%42 = load i32, i32* @STDOUT_FILENO
%43 = icmp eq i32 %42, %3
br i1 %43, label %46, label %44
44: ; preds = %38
%45 = tail call i32 @fclose(i32* %16)
br label %46
46: ; preds = %44, %38
%47 = load i32, i32* @STDERR_FILENO
%48 = icmp eq i32 %47, %4
%49 = icmp eq i32 %4, %3
%50 = or i1 %49, %48
br i1 %50, label %54, label %51
51: ; preds = %46, %33
%52 = phi i32 [ 1, %33 ], [ 0, %46 ]
%53 = tail call i32 @fclose(i32* %24)
br label %54
54: ; preds = %51, %46, %33
%55 = phi i32 [ 1, %33 ], [ 0, %46 ], [ %52, %51 ]
ret i32 %55
}