#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 ssize_t;

/* Variables and functions */
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
scalar_t__ memcmp(char *, char *, int);
int read(int /*<<< orphan*/, char *, int);
int /*<<< orphan*/ stderr;
int write(int, char *, int);
int main(int argc, char **argv) {
  char buffer[1024];
  ssize_t n;
  n = read(0, buffer, 1024);
  if (n < 1024) {
    fprintf(stderr, "read error\n");
    return 3;
  }
  if (buffer[156] != 'g')
    return 1;
  if (memcmp(&buffer[512], "52 comment=", 11))
    return 1;
  n = write(1, &buffer[523], 41);
  if (n < 41) {
    fprintf(stderr, "write error\n");
    return 2;
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x410(%rbp),%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1040 <read@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x400,-0x414(%rbp)
jge    11a3 <main+0x63>
mov    0x2e57(%rip),%rax
mov    (%rax),%edi
lea    0xe6e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x3,-0x4(%rbp)
jmp    124c <main+0x10c>
movsbl -0x374(%rbp),%eax
cmp    $0x67,%eax
je     11bf <main+0x7f>
movl   $0x1,-0x4(%rbp)
jmp    124c <main+0x10c>
lea    -0x410(%rbp),%rdi
add    $0x200,%rdi
lea    0xe38(%rip),%rsi
mov    $0xb,%edx
call   1050 <memcmp@plt>
cmp    $0x0,%rax
je     11f4 <main+0xb4>
movl   $0x1,-0x4(%rbp)
jmp    124c <main+0x10c>
lea    -0x410(%rbp),%rsi
add    $0x20b,%rsi
mov    $0x1,%edi
mov    $0x29,%edx
call   1030 <write@plt>
mov    %eax,-0x414(%rbp)
cmpl   $0x29,-0x414(%rbp)
jge    1245 <main+0x105>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
lea    0xde4(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    124c <main+0x10c>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x400,%edx
call   1040 <read@plt>
cmp    $0x3ff,%eax
jg     117a <main+0x3a>
mov    0x2e7b(%rip),%rax
mov    (%rax),%edi
lea    0xe92(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x3,%ebx
jmp    11df <main+0x9f>
mov    $0x1,%ebx
cmpb   $0x67,0x9c(%rsp)
67
jne    11df <main+0x9f>
lea    0x200(%rsp),%rdi
lea    0xe74(%rip),%rsi
mov    $0xb,%edx
call   1050 <memcmp@plt>
test   %rax,%rax
jne    11df <main+0x9f>
lea    0x20b(%rsp),%rsi
mov    $0x1,%edi
mov    $0x29,%edx
call   1030 <write@plt>
xor    %ebx,%ebx
cmp    $0x28,%eax
jg     11df <main+0x9f>
mov    0x2e14(%rip),%rax
mov    (%rax),%edi
lea    0xe43(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x2,%ebx
mov    %ebx,%eax
add    $0x400,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [12 x i8] c"read error\0A\00"
@.str.1 = [12 x i8] c"52 comment=\00"
@.str.2 = [13 x i8] c"write error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [1024 x i8]
%7 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 0
%9 = call i32 @read(i32 0, i8* %8, i32 1024)
store i32 %9, i32* %7
%10 = load i32, i32* %7
%11 = icmp slt i32 %10, 1024
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
store i32 3, i32* %3
br label %35
15: ; preds = %2
%16 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 156
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp ne i32 %18, 103
br i1 %19, label %20, label %21
20: ; preds = %15
store i32 1, i32* %3
br label %35
21: ; preds = %15
%22 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 512
%23 = call i64 @memcmp(i8* %22, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%24 = icmp ne i64 %23, 0
br i1 %24, label %25, label %26
25: ; preds = %21
store i32 1, i32* %3
br label %35
26: ; preds = %21
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %6, i64 0, i64 523
%28 = call i32 @write(i32 1, i8* %27, i32 41)
store i32 %28, i32* %7
%29 = load i32, i32* %7
%30 = icmp slt i32 %29, 41
br i1 %30, label %31, label %34
31: ; preds = %26
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
store i32 2, i32* %3
br label %35
34: ; preds = %26
store i32 0, i32* %3
br label %35
35: ; preds = %34, %31, %25, %20, %12
%36 = load i32, i32* %3
ret i32 %36
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [12 x i8] c"read error\0A\00"
@.str.1 = [12 x i8] c"52 comment=\00"
@.str.2 = [13 x i8] c"write error\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [1024 x i8]
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%5 = call i32 @read(i32 0, i8* %4, i32 1024)
%6 = icmp slt i32 %5, 1024
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0))
br label %25
10: ; preds = %2
%11 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 156
%12 = load i8, i8* %11
%13 = icmp eq i8 %12, 103
br i1 %13, label %14, label %25
14: ; preds = %10
%15 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 512
%16 = call i64 @memcmp(i8* %15, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0), i32 11)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %14
%19 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 523
%20 = call i32 @write(i32 1, i8* %19, i32 41)
%21 = icmp slt i32 %20, 41
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* @stderr
%24 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.2, i64 0, i64 0))
br label %25
25: ; preds = %18, %14, %10, %22, %7
%26 = phi i32 [ 3, %7 ], [ 2, %22 ], [ 1, %10 ], [ 1, %14 ], [ 0, %18 ]
ret i32 %26
}