#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 */

/* Variables and functions */
scalar_t__ chdir(char *);
int /*<<< orphan*/ free(char *);
char *getcwd(char *, int);
int /*<<< orphan*/ printf(char *, char *, int);
int /*<<< orphan*/ strcmp(char *, char *);
int test_getcwd(void) {
  char buf[100], *d;
  do {
    if (!(0 == chdir("/"))) {
      printf("expression '%s' untrue at %d\n", "0 == chdir(\"/\")", 32);
      return 0;
    }
  } while (0);
  do {
    if (!(buf == getcwd(buf, sizeof buf))) {
      printf("expression '%s' untrue at %d\n", "buf == getcwd(buf, sizeof buf)",
             33);
      return 0;
    }
  } while (0);
  do {
    if (!(!strcmp(buf, "/"))) {
      printf("expression '%s' untrue at %d\n", "!strcmp(buf, \"/\")", 34);
      return 0;
    }
  } while (0);
  d = getcwd(NULL, 0);
  do {
    if (!(NULL != d)) {
      printf("expression '%s' untrue at %d\n", "NULL != d", 37);
      return 0;
    }
  } while (0);
  do {
    if (!(!strcmp(d, "/"))) {
      printf("expression '%s' untrue at %d\n", "!strcmp(d, \"/\")", 38);
      return 0;
    }
  } while (0);
  free(d);
  return 1;
}


x86 assembly (clang, -O0):
<test_getcwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
lea    0xe9e(%rip),%rdi
call   1040 <chdir@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1199 <test_getcwd+0x49>
lea    0xe86(%rip),%rdi
lea    0xe9d(%rip),%rsi
mov    $0x20,%edx
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d4 <test_getcwd+0x184>
jmp    119e <test_getcwd+0x4e>
jmp    11a3 <test_getcwd+0x53>
lea    -0x70(%rbp),%rax
mov    %rax,-0x80(%rbp)
lea    -0x70(%rbp),%rdi
mov    $0x64,%esi
call   1060 <getcwd@plt>
mov    %rax,%rcx
mov    -0x80(%rbp),%rax
cmp    %rcx,%rax
je     11ed <test_getcwd+0x9d>
lea    0xe32(%rip),%rdi
lea    0xe59(%rip),%rsi
mov    $0x21,%edx
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d4 <test_getcwd+0x184>
jmp    11f2 <test_getcwd+0xa2>
jmp    11f7 <test_getcwd+0xa7>
lea    -0x70(%rbp),%rdi
lea    0xdfe(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     1234 <test_getcwd+0xe4>
lea    0xdeb(%rip),%rdi
lea    0xe31(%rip),%rsi
mov    $0x22,%edx
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d4 <test_getcwd+0x184>
jmp    1239 <test_getcwd+0xe9>
xor    %eax,%eax
mov    %eax,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
mov    %rax,-0x78(%rbp)
xor    %eax,%eax
cmp    -0x78(%rbp),%rax
jne    1278 <test_getcwd+0x128>
lea    0xda7(%rip),%rdi
lea    0xdff(%rip),%rsi
mov    $0x25,%edx
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d4 <test_getcwd+0x184>
jmp    127d <test_getcwd+0x12d>
jmp    1282 <test_getcwd+0x132>
mov    -0x78(%rbp),%rdi
lea    0xd73(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%eax
je     12bf <test_getcwd+0x16f>
lea    0xd60(%rip),%rdi
lea    0xdc2(%rip),%rsi
mov    $0x26,%edx
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    12d4 <test_getcwd+0x184>
jmp    12c4 <test_getcwd+0x174>
mov    -0x78(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_getcwd>:
push   %r14
push   %rbx
sub    $0x68,%rsp
lea    0xea2(%rip),%rdi
call   1040 <chdir@plt>
test   %rax,%rax
je     117d <test_getcwd+0x2d>
lea    0xe93(%rip),%rdi
lea    0xeaa(%rip),%rsi
mov    $0x20,%edx
jmp    11fc <test_getcwd+0xac>
mov    %rsp,%rbx
mov    %rbx,%rdi
mov    $0x64,%esi
call   1060 <getcwd@plt>
cmp    %rax,%rbx
je     11a7 <test_getcwd+0x57>
lea    0xe69(%rip),%rdi
lea    0xe90(%rip),%rsi
mov    $0x21,%edx
jmp    11fc <test_getcwd+0xac>
cmpw   $0x2f,(%rsp)
jne    11e9 <test_getcwd+0x99>
xor    %ebx,%ebx
xor    %edi,%edi
xor    %esi,%esi
call   1060 <getcwd@plt>
test   %rax,%rax
je     120d <test_getcwd+0xbd>
mov    %rax,%r14
lea    0xe38(%rip),%rsi
mov    %rax,%rdi
call   1070 <strcmp@plt>
test   %eax,%eax
je     1227 <test_getcwd+0xd7>
lea    0xe27(%rip),%rdi
lea    0xe89(%rip),%rsi
mov    $0x26,%edx
jmp    11fc <test_getcwd+0xac>
lea    0xe12(%rip),%rdi
lea    0xe58(%rip),%rsi
mov    $0x22,%edx
call   1050 <printf@plt>
xor    %ebx,%ebx
mov    %ebx,%eax
add    $0x68,%rsp
pop    %rbx
pop    %r14
ret
lea    0xdee(%rip),%rdi
lea    0xe46(%rip),%rsi
mov    $0x25,%edx
call   1050 <printf@plt>
jmp    1203 <test_getcwd+0xb3>
mov    %r14,%rdi
call   1030 <free@plt>
mov    $0x1,%ebx
jmp    1203 <test_getcwd+0xb3>

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@.str.1 = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.2 = [16 x i8] c"0 == chdir(\22/\22)\00"
@.str.3 = [31 x i8] c"buf == getcwd(buf, sizeof buf)\00"
@.str.4 = [18 x i8] c"!strcmp(buf, \22/\22)\00"
@.str.5 = [10 x i8] c"NULL != d\00"
@.str.6 = [16 x i8] c"!strcmp(d, \22/\22)\00"
define i32 @test_getcwd() {
%1 = alloca i32
%2 = alloca [100 x i8]
%3 = alloca i8*
br label %4
4: ; preds = %0
%5 = call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%6 = icmp eq i64 0, %5
br i1 %6, label %9, label %7
7: ; preds = %4
%8 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 32)
store i32 0, i32* %1
br label %46
9: ; preds = %4
br label %10
10: ; preds = %9
br label %11
11: ; preds = %10
%12 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%13 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%14 = call i8* @getcwd(i8* %13, i32 100)
%15 = icmp eq i8* %12, %14
br i1 %15, label %18, label %16
16: ; preds = %11
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 33)
store i32 0, i32* %1
br label %46
18: ; preds = %11
br label %19
19: ; preds = %18
br label %20
20: ; preds = %19
%21 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%22 = call i32 @strcmp(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%23 = icmp ne i32 %22, 0
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 34)
store i32 0, i32* %1
br label %46
26: ; preds = %20
br label %27
27: ; preds = %26
%28 = call i8* @getcwd(i8* null, i32 0)
store i8* %28, i8** %3
br label %29
29: ; preds = %27
%30 = load i8*, i8** %3
%31 = icmp ne i8* null, %30
br i1 %31, label %34, label %32
32: ; preds = %29
%33 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 37)
store i32 0, i32* %1
br label %46
34: ; preds = %29
br label %35
35: ; preds = %34
br label %36
36: ; preds = %35
%37 = load i8*, i8** %3
%38 = call i32 @strcmp(i8* %37, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%39 = icmp ne i32 %38, 0
br i1 %39, label %40, label %42
40: ; preds = %36
%41 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 38)
store i32 0, i32* %1
br label %46
42: ; preds = %36
br label %43
43: ; preds = %42
%44 = load i8*, i8** %3
%45 = call i32 @free(i8* %44)
store i32 1, i32* %1
br label %46
46: ; preds = %43, %40, %32, %24, %16, %7
%47 = load i32, i32* %1
ret i32 %47
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@.str.1 = [30 x i8] c"expression '%s' untrue at %d\0A\00"
@.str.2 = [16 x i8] c"0 == chdir(\22/\22)\00"
@.str.3 = [31 x i8] c"buf == getcwd(buf, sizeof buf)\00"
@.str.4 = [18 x i8] c"!strcmp(buf, \22/\22)\00"
@.str.5 = [10 x i8] c"NULL != d\00"
@.str.6 = [16 x i8] c"!strcmp(d, \22/\22)\00"
define i32 @test_getcwd() {
%1 = alloca [100 x i8]
%2 = getelementptr inbounds [100 x i8], [100 x i8]* %1, i64 0, i64 0
%3 = tail call i64 @chdir(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i64 %3, 0
br i1 %4, label %7, label %5
5: ; preds = %0
%6 = tail call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 32)
br label %30
7: ; preds = %0
%8 = call i8* @getcwd(i8* %2, i32 100)
%9 = icmp eq i8* %2, %8
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.3, i64 0, i64 0), i32 33)
br label %30
12: ; preds = %7
%13 = bitcast [100 x i8]* %1 to i16*
%14 = load i16, i16* %13
%15 = icmp eq i16 %14, 47
br i1 %15, label %18, label %16
16: ; preds = %12
%17 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.4, i64 0, i64 0), i32 34)
br label %30
18: ; preds = %12
%19 = call i8* @getcwd(i8* null, i32 0)
%20 = icmp eq i8* %19, null
br i1 %20, label %21, label %23
21: ; preds = %18
%22 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 37)
br label %30
23: ; preds = %18
%24 = call i32 @strcmp(i8* %19, i8* dereferenceable(2) getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %23
%27 = call i32 @printf(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.6, i64 0, i64 0), i32 38)
br label %30
28: ; preds = %23
%29 = call i32 @free(i8* %19)
br label %30
30: ; preds = %28, %26, %21, %16, %10, %5
%31 = phi i32 [ 0, %16 ], [ 0, %26 ], [ 1, %28 ], [ 0, %21 ], [ 0, %10 ], [ 0, %5 ]
ret i32 %31
}