#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 size_t ssize_t;
typedef int /*<<< orphan*/ invalid_arg_err;
typedef int /*<<< orphan*/ input_buff;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, size_t, int);
int /*<<< orphan*/ perror(char *);
size_t read(int /*<<< orphan*/, char *, int);
int sprintf(char *, char *, int);
int sscanf(char *, char *, int *, int *);
int /*<<< orphan*/ stderr;
size_t write(int /*<<< orphan*/, char *, int);
int main(void) {
  static char output_buff[32];
  static char input_buff[32];
  static char invalid_arg_err[] = "Invalid arguments.\n";
  size_t invalid_arg_err_sz = sizeof(invalid_arg_err) - 1;
  ssize_t n;
  while ((n = read(STDIN_FILENO, input_buff, sizeof(input_buff))) > 0) {
    ssize_t sent;
    int op1, op2;
    if (sscanf(input_buff, "%d%d", &op1, &op2) != 2) {
      if ((sent = write(STDOUT_FILENO, invalid_arg_err, invalid_arg_err_sz)) !=
          invalid_arg_err_sz) {
        if (sent >= 0)
          fprintf(stderr,
                  "Partial write detected when reporting invalid arguments "
                  "(%zd/%zd)\n",
                  sent, invalid_arg_err_sz);
        else
          perror("write(2) error when reporting invalid arguments");
        exit(EXIT_FAILURE);
      }
      continue;
    }
    int len = sprintf(output_buff, "%d\n", op1 + op2);
    if ((sent = write(STDOUT_FILENO, output_buff, len)) != len) {
      if (len >= 0)
        fprintf(stderr, "Partial write detected when sending result (%zd/%d)\n",
                sent, len);
      else
        perror("write(2) error when sending result");
    }
  }
  if (n < 0) {
    perror("read(2) error");
    exit(EXIT_FAILURE);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x13,-0x10(%rbp)
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0x2f19(%rip),%rsi
mov    $0x20,%edx
call   1040 <read@plt>
mov    %rax,-0x18(%rbp)
cmp    $0x0,%rax
jbe    12d0 <main+0x160>
lea    0x2efa(%rip),%rdi
lea    0xe43(%rip),%rsi
lea    -0x24(%rbp),%rdx
lea    -0x28(%rbp),%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
je     124a <main+0xda>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    %eax,%edx
lea    0x2e77(%rip),%rsi
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
cmp    -0x10(%rbp),%rax
je     1245 <main+0xd5>
cmpq   $0x0,-0x20(%rbp)
jb     122b <main+0xbb>
mov    0x2dca(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x10(%rbp),%rax
mov    %eax,%ecx
lea    0xde4(%rip),%rsi
call   1050 <fprintf@plt>
jmp    1237 <main+0xc7>
lea    0xe16(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d92(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
jmp    1187 <main+0x17>
mov    -0x24(%rbp),%edx
add    -0x28(%rbp),%edx
lea    0x2e39(%rip),%rdi
lea    0xe1a(%rip),%rsi
call   1080 <sprintf@plt>
mov    %eax,-0x2c(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
mov    -0x2c(%rbp),%edx
lea    0x2e17(%rip),%rsi
call   1030 <write@plt>
mov    %rax,-0x20(%rbp)
movslq -0x2c(%rbp),%rcx
cmp    %rcx,%rax
je     12cb <main+0x15b>
cmpl   $0x0,-0x2c(%rbp)
jl     12ba <main+0x14a>
mov    0x2d38(%rip),%rax
mov    (%rax),%edi
mov    -0x20(%rbp),%rdx
mov    -0x2c(%rbp),%ecx
lea    0xdcc(%rip),%rsi
call   1050 <fprintf@plt>
jmp    12c6 <main+0x156>
lea    0xdf0(%rip),%rdi
call   1070 <perror@plt>
jmp    12cb <main+0x15b>
jmp    1187 <main+0x17>
cmpq   $0x0,-0x18(%rbp)
jae    12f5 <main+0x185>
lea    0xdf2(%rip),%rdi
call   1070 <perror@plt>
mov    0x2ce2(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
lea    0x2f25(%rip),%rsi
mov    $0x20,%edx
call   1040 <read@plt>
test   %rax,%rax
je     1274 <main+0x104>
lea    0x2f0b(%rip),%rbx
lea    0x4(%rsp),%r15
mov    %rsp,%r12
lea    0x2edc(%rip),%r13
mov    0x2e35(%rip),%r14
jmp    11f9 <main+0x89>
nopl   (%rax)
mov    (%r14),%edi
lea    0x2e96(%rip),%rsi
mov    $0x13,%edx
call   1030 <write@plt>
cmp    $0x13,%rax
jne    1285 <main+0x115>
mov    0x2de3(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0x20,%edx
call   1040 <read@plt>
test   %rax,%rax
je     1274 <main+0x104>
mov    %rbx,%rdi
lea    0xdfd(%rip),%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1060 <sscanf@plt>
cmp    $0x2,%eax
jne    11c0 <main+0x50>
mov    (%rsp),%edx
add    0x4(%rsp),%edx
mov    %r13,%rdi
lea    0xe24(%rip),%rsi
call   1080 <sprintf@plt>
mov    %eax,%ebp
mov    (%r14),%edi
mov    %r13,%rsi
mov    %eax,%edx
call   1030 <write@plt>
movslq %ebp,%rcx
cmp    %rcx,%rax
je     11de <main+0x6e>
test   %ebp,%ebp
js     1263 <main+0xf3>
mov    0x2d8d(%rip),%rcx
mov    (%rcx),%edi
lea    0xdf8(%rip),%rsi
mov    %rax,%rdx
mov    %ebp,%ecx
call   1050 <fprintf@plt>
jmp    11de <main+0x6e>
lea    0xe17(%rip),%rdi
call   1070 <perror@plt>
jmp    11de <main+0x6e>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2d4c(%rip),%rcx
mov    (%rcx),%edi
lea    0xd70(%rip),%rsi
mov    %rax,%rdx
mov    $0x13,%ecx
call   1050 <fprintf@plt>
mov    0x2d27(%rip),%rax
mov    (%rax),%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@main.output_buff = internal global [32 x i8] zeroinitializer
@main.input_buff = internal global [32 x i8] zeroinitializer
@main.invalid_arg_err = internal global [20 x i8] c"Invalid arguments.\0A\00"
@STDIN_FILENO = global i32 0
@.str = [5 x i8] c"%d%d\00"
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str.1 = [67 x i8] c"Partial write detected when reporting invalid arguments (%zd/%zd)\0A\00"
@.str.2 = [48 x i8] c"write(2) error when reporting invalid arguments\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [53 x i8] c"Partial write detected when sending result (%zd/%d)\0A\00"
@.str.5 = [35 x i8] c"write(2) error when sending result\00"
@.str.6 = [14 x i8] c"read(2) error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i64
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32
store i32 0, i32* %1
store i64 19, i64* %2
br label %8
8: ; preds = %59, %36, %0
%9 = load i32, i32* @STDIN_FILENO
%10 = call i64 @read(i32 %9, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.input_buff, i64 0, i64 0), i32 32)
store i64 %10, i64* %3
%11 = icmp ugt i64 %10, 0
br i1 %11, label %12, label %60
12: ; preds = %8
%13 = call i32 @sscanf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.input_buff, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %5, i32* %6)
%14 = icmp ne i32 %13, 2
br i1 %14, label %15, label %37
15: ; preds = %12
%16 = load i32, i32* @STDOUT_FILENO
%17 = load i64, i64* %2
%18 = trunc i64 %17 to i32
%19 = call i64 @write(i32 %16, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @main.invalid_arg_err, i64 0, i64 0), i32 %18)
store i64 %19, i64* %4
%20 = load i64, i64* %2
%21 = icmp ne i64 %19, %20
br i1 %21, label %22, label %36
22: ; preds = %15
%23 = load i64, i64* %4
%24 = icmp uge i64 %23, 0
br i1 %24, label %25, label %31
25: ; preds = %22
%26 = load i32, i32* @stderr
%27 = load i64, i64* %4
%28 = load i64, i64* %2
%29 = trunc i64 %28 to i32
%30 = call i32 @fprintf(i32 %26, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i64 %27, i32 %29)
br label %33
31: ; preds = %22
%32 = call i32 @perror(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.2, i64 0, i64 0))
br label %33
33: ; preds = %31, %25
%34 = load i32, i32* @EXIT_FAILURE
%35 = call i32 @exit(i32 %34)
unreachable
36: ; preds = %15
br label %8
37: ; preds = %12
%38 = load i32, i32* %5
%39 = load i32, i32* %6
%40 = add nsw i32 %38, %39
%41 = call i32 @sprintf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.output_buff, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %40)
store i32 %41, i32* %7
%42 = load i32, i32* @STDOUT_FILENO
%43 = load i32, i32* %7
%44 = call i64 @write(i32 %42, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.output_buff, i64 0, i64 0), i32 %43)
store i64 %44, i64* %4
%45 = load i32, i32* %7
%46 = sext i32 %45 to i64
%47 = icmp ne i64 %44, %46
br i1 %47, label %48, label %59
48: ; preds = %37
%49 = load i32, i32* %7
%50 = icmp sge i32 %49, 0
br i1 %50, label %51, label %56
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = load i64, i64* %4
%54 = load i32, i32* %7
%55 = call i32 @fprintf(i32 %52, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i64 %53, i32 %54)
br label %58
56: ; preds = %48
%57 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %58
58: ; preds = %56, %51
br label %59
59: ; preds = %58, %37
br label %8
60: ; preds = %8
%61 = load i64, i64* %3
%62 = icmp ult i64 %61, 0
br i1 %62, label %63, label %67
63: ; preds = %60
%64 = call i32 @perror(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.6, i64 0, i64 0))
%65 = load i32, i32* @EXIT_FAILURE
%66 = call i32 @exit(i32 %65)
unreachable
67: ; preds = %60
ret i32 0
}

LLVM IR (-O2):
@main.output_buff = internal global [32 x i8] zeroinitializer
@main.input_buff = internal global [32 x i8] zeroinitializer
@main.invalid_arg_err = internal global [20 x i8] c"Invalid arguments.\0A\00"
@STDIN_FILENO = global i32 0
@.str = [5 x i8] c"%d%d\00"
@STDOUT_FILENO = global i32 0
@stderr = global i32 0
@.str.1 = [67 x i8] c"Partial write detected when reporting invalid arguments (%zd/%zd)\0A\00"
@EXIT_FAILURE = global i32 0
@.str.3 = [4 x i8] c"%d\0A\00"
@.str.4 = [53 x i8] c"Partial write detected when sending result (%zd/%d)\0A\00"
@.str.5 = [35 x i8] c"write(2) error when sending result\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = load i32, i32* @STDIN_FILENO
%4 = call i64 @read(i32 %3, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.input_buff, i64 0, i64 0), i32 32)
%5 = icmp eq i64 %4, 0
br i1 %5, label %41, label %6
6: ; preds = %0
%7 = bitcast i32* %1 to i8*
%8 = bitcast i32* %2 to i8*
br label %9
9: ; preds = %6, %37
%10 = call i32 @sscanf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.input_buff, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i32* %1, i32* %2)
%11 = icmp eq i32 %10, 2
br i1 %11, label %21, label %12
12: ; preds = %9
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i64 @write(i32 %13, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @main.invalid_arg_err, i64 0, i64 0), i32 19)
%15 = icmp eq i64 %14, 19
br i1 %15, label %37, label %16
16: ; preds = %12
%17 = load i32, i32* @stderr
%18 = call i32 @fprintf(i32 %17, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), i64 %14, i32 19)
%19 = load i32, i32* @EXIT_FAILURE
%20 = call i32 @exit(i32 %19)
unreachable
21: ; preds = %9
%22 = load i32, i32* %1
%23 = load i32, i32* %2
%24 = add nsw i32 %23, %22
%25 = call i32 @sprintf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @main.output_buff, i64 0, i64 0), i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %24)
%26 = load i32, i32* @STDOUT_FILENO
%27 = call i64 @write(i32 %26, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.output_buff, i64 0, i64 0), i32 %25)
%28 = sext i32 %25 to i64
%29 = icmp eq i64 %27, %28
br i1 %29, label %37, label %30
30: ; preds = %21
%31 = icmp sgt i32 %25, -1
br i1 %31, label %32, label %35
32: ; preds = %30
%33 = load i32, i32* @stderr
%34 = call i32 @fprintf(i32 %33, i8* getelementptr inbounds ([53 x i8], [53 x i8]* @.str.4, i64 0, i64 0), i64 %27, i32 %25)
br label %37
35: ; preds = %30
%36 = call i32 @perror(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0))
br label %37
37: ; preds = %21, %35, %32, %12
%38 = load i32, i32* @STDIN_FILENO
%39 = call i64 @read(i32 %38, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @main.input_buff, i64 0, i64 0), i32 32)
%40 = icmp eq i64 %39, 0
br i1 %40, label %41, label %9
41: ; preds = %37, %0
ret i32 0
}