#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 */
int atoi(char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fflush(int /*<<< orphan*/);
int /*<<< orphan*/ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int confirm_cwd(void) {
  int code;
  char buf[1024];
  fflush(stdout);
  if (!fgets(buf, 1023, stdin))
    exit(0);
  if (*buf != 'S') {
    printf("L %s\n", "L CCP was expecting an S. Sorry - exiting");
    printf("Q\n");
    exit(0);
  }
  code = atoi(buf + 2);
  printf("X\n");
  return (code < 300);
}


x86 assembly (clang, -O0):
<confirm_cwd>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
mov    0x2e76(%rip),%rax
mov    (%rax),%edi
call   1050 <fflush@plt>
lea    -0x410(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%edx
mov    $0x3ff,%esi
call   1040 <fgets@plt>
cmp    $0x0,%eax
jne    1193 <confirm_cwd+0x43>
xor    %edi,%edi
call   1070 <exit@plt>
movsbl -0x410(%rbp),%eax
cmp    $0x53,%eax
je     11cd <confirm_cwd+0x7d>
lea    0xe56(%rip),%rdi
lea    0xe55(%rip),%rsi
mov    $0x0,%al
call   1030 <printf@plt>
lea    0xe71(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1070 <exit@plt>
lea    -0x410(%rbp),%rdi
add    $0x2,%rdi
call   1060 <atoi@plt>
mov    %eax,-0x4(%rbp)
lea    0xe4c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
cmpl   $0x12c,-0x4(%rbp)
setl   %al
and    $0x1,%al
movzbl %al,%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<confirm_cwd>:
push   %rbx
sub    $0x400,%rsp
mov    0x2e69(%rip),%rax
mov    (%rax),%edi
call   1060 <fflush@plt>
mov    0x2e6b(%rip),%rax
mov    (%rax),%edx
mov    %rsp,%rdi
mov    $0x3ff,%esi
call   1050 <fgets@plt>
test   %eax,%eax
je     11c2 <confirm_cwd+0x62>
cmpb   $0x53,(%rsp)
jne    11c9 <confirm_cwd+0x69>
lea    0x2(%rsp),%rdi
call   1070 <atoi@plt>
mov    %eax,%ebx
lea    0xe87(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
cmp    $0x12c,%ebx
setl   %al
add    $0x400,%rsp
pop    %rbx
ret
xor    %edi,%edi
call   1080 <exit@plt>
lea    0xe30(%rip),%rdi
lea    0xe2f(%rip),%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe4d(%rip),%rdi
call   1030 <puts@plt>
xor    %edi,%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
@.str = [6 x i8] c"L %s\0A\00"
@.str.1 = [42 x i8] c"L CCP was expecting an S. Sorry - exiting\00"
@.str.2 = [3 x i8] c"Q\0A\00"
@.str.3 = [3 x i8] c"X\0A\00"
define i32 @confirm_cwd() {
%1 = alloca i32
%2 = alloca [1024 x i8]
%3 = load i32, i32* @stdout
%4 = call i32 @fflush(i32 %3)
%5 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%6 = load i32, i32* @stdin
%7 = call i32 @fgets(i8* %5, i32 1023, i32 %6)
%8 = icmp ne i32 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %0
%10 = call i32 @exit(i32 0)
unreachable
11: ; preds = %0
%12 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%13 = load i8, i8* %12
%14 = sext i8 %13 to i32
%15 = icmp ne i32 %14, 83
br i1 %15, label %16, label %20
16: ; preds = %11
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%18 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%19 = call i32 @exit(i32 0)
unreachable
20: ; preds = %11
%21 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%22 = getelementptr inbounds i8, i8* %21, i64 2
%23 = call i32 @atoi(i8* %22)
store i32 %23, i32* %1
%24 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0))
%25 = load i32, i32* %1
%26 = icmp slt i32 %25, 300
%27 = zext i1 %26 to i32
ret i32 %27
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
@.str = [6 x i8] c"L %s\0A\00"
@.str.1 = [42 x i8] c"L CCP was expecting an S. Sorry - exiting\00"
@str = [2 x i8] c"X\00"
@str.4 = [2 x i8] c"Q\00"
define i32 @confirm_cwd() {
%1 = alloca [1024 x i8]
%2 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @stdout
%4 = tail call i32 @fflush(i32 %3)
%5 = load i32, i32* @stdin
%6 = call i32 @fgets(i8* %2, i32 1023, i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @exit(i32 0)
unreachable
10: ; preds = %0
%11 = load i8, i8* %2
%12 = icmp eq i8 %11, 83
br i1 %12, label %17, label %13
13: ; preds = %10
%14 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str.4, i64 0, i64 0))
%16 = call i32 @exit(i32 0)
unreachable
17: ; preds = %10
%18 = getelementptr inbounds [1024 x i8], [1024 x i8]* %1, i64 0, i64 2
%19 = call i32 @atoi(i8* %18)
%20 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([2 x i8], [2 x i8]* @str, i64 0, i64 0))
%21 = icmp slt i32 %19, 300
%22 = zext i1 %21 to i32
ret i32 %22
}