#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 STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ printf(char *, ...);
int read(int, char *, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int sscanf(char *, char *, int *, int *);
int strlen(char *);
int write(int, char *, int);
int main(void) {
  int fdin, fdout, n, int1, int2;
  char line[128];
  fdin = STDIN_FILENO;
  fdout = STDOUT_FILENO;
  while ((n = read(fdin, line, 128)) > 0) {
    line[n] = 0;
    printf("source: %s\n", line);
    if (sscanf(line, "%d%d", &int1, &int2) == 2) {
      sprintf(line, "%d\n", int1 + int2);
      n = strlen(line);
      if (write(fdout, line, n) != n) {
        printf("write error\n");
        return 0;
      }
    } else {
      if (write(fdout, "invalid args\n", 13) != 13) {
        printf("write msg error\n");
        return 0;
      }
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xa0,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x8(%rbp)
mov    0x2e6b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x80,%edx
call   1060 <read@plt>
mov    %eax,-0x10(%rbp)
cmp    $0x0,%eax
jle    1292 <main+0x132>
movslq -0x10(%rbp),%rax
movb   $0x0,-0xa0(%rbp,%rax,1)
lea    -0xa0(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
lea    -0xa0(%rbp),%rdi
lea    0xe33(%rip),%rsi
lea    -0x14(%rbp),%rdx
lea    -0x18(%rbp),%rcx
call   1070 <sscanf@plt>
cmp    $0x2,%eax
jne    1251 <main+0xf1>
lea    -0xa0(%rbp),%rdi
mov    -0x14(%rbp),%edx
add    -0x18(%rbp),%edx
lea    0xe0e(%rip),%rsi
call   1080 <sprintf@plt>
lea    -0xa0(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x10(%rbp)
mov    -0xc(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    -0x10(%rbp),%edx
call   1030 <write@plt>
cmp    -0x10(%rbp),%eax
je     124c <main+0xec>
lea    0xddc(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <main+0x139>
jmp    128d <main+0x12d>
mov    -0xc(%rbp),%edi
lea    0xdc7(%rip),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
cmp    $0xd,%eax
je     1288 <main+0x128>
lea    0xdbb(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0x0,-0x4(%rbp)
jmp    1299 <main+0x139>
jmp    128d <main+0x12d>
jmp    118a <main+0x2a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0xa0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x98,%rsp
mov    0x2e50(%rip),%rax
mov    (%rax),%r13d
mov    0x2e5e(%rip),%rax
mov    (%rax),%eax
mov    %eax,(%rsp)
lea    0x10(%rsp),%rsi
mov    %r13d,%edi
mov    $0x80,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    129d <main+0x12d>
lea    0xe48(%rip),%rbx
lea    0x10(%rsp),%r14
lea    0xe48(%rip),%rbp
lea    0xc(%rsp),%r12
lea    0x8(%rsp),%r15
mov    %r13d,0x4(%rsp)
jmp    1215 <main+0xa5>
cs nopw 0x0(%rax,%rax,1)
nop
mov    (%rsp),%edi
lea    0xe2b(%rip),%rsi
mov    $0xd,%edx
call   1040 <write@plt>
cmp    $0xd,%eax
jne    1291 <main+0x121>
mov    %r13d,%edi
mov    %r14,%rsi
mov    $0x80,%edx
call   1070 <read@plt>
test   %eax,%eax
jle    129d <main+0x12d>
mov    %eax,%eax
movb   $0x0,0x10(%rsp,%rax,1)
mov    %rbx,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
mov    %r12,%rdx
mov    %r15,%rcx
call   1080 <sscanf@plt>
cmp    $0x2,%eax
jne    11e0 <main+0x70>
mov    0x8(%rsp),%edx
add    0xc(%rsp),%edx
mov    %r14,%rdi
lea    0xdc0(%rip),%rsi
call   1090 <sprintf@plt>
mov    %r14,%rdi
call   1050 <strlen@plt>
mov    %r15,%r13
mov    %r12,%r15
mov    %eax,%r12d
mov    (%rsp),%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1040 <write@plt>
cmp    %r12d,%eax
mov    %r15,%r12
mov    %r13,%r15
mov    0x4(%rsp),%r13d
je     11fd <main+0x8d>
lea    0xda4(%rip),%rdi
jmp    1298 <main+0x128>
lea    0xd8b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x98,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [12 x i8] c"source: %s\0A\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.3 = [13 x i8] c"write error\0A\00"
@.str.4 = [14 x i8] c"invalid args\0A\00"
@.str.5 = [17 x i8] c"write msg error\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
%7 = alloca [128 x i8]
store i32 0, i32* %1
%8 = load i32, i32* @STDIN_FILENO
store i32 %8, i32* %2
%9 = load i32, i32* @STDOUT_FILENO
store i32 %9, i32* %3
br label %10
10: ; preds = %48, %0
%11 = load i32, i32* %2
%12 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 128)
store i32 %13, i32* %4
%14 = icmp sgt i32 %13, 0
br i1 %14, label %15, label %49
15: ; preds = %10
%16 = load i32, i32* %4
%17 = sext i32 %16 to i64
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %19)
%21 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%22 = call i32 @sscanf(i8* %21, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %5, i32* %6)
%23 = icmp eq i32 %22, 2
br i1 %23, label %24, label %41
24: ; preds = %15
%25 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%26 = load i32, i32* %5
%27 = load i32, i32* %6
%28 = add nsw i32 %26, %27
%29 = call i32 @sprintf(i8* %25, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%31 = call i32 @strlen(i8* %30)
store i32 %31, i32* %4
%32 = load i32, i32* %3
%33 = getelementptr inbounds [128 x i8], [128 x i8]* %7, i64 0, i64 0
%34 = load i32, i32* %4
%35 = call i32 @write(i32 %32, i8* %33, i32 %34)
%36 = load i32, i32* %4
%37 = icmp ne i32 %35, %36
br i1 %37, label %38, label %40
38: ; preds = %24
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i64 0, i64 0))
store i32 0, i32* %1
br label %50
40: ; preds = %24
br label %48
41: ; preds = %15
%42 = load i32, i32* %3
%43 = call i32 @write(i32 %42, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 13)
%44 = icmp ne i32 %43, 13
br i1 %44, label %45, label %47
45: ; preds = %41
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.5, i64 0, i64 0))
store i32 0, i32* %1
br label %50
47: ; preds = %41
br label %48
48: ; preds = %47, %40
br label %10
49: ; preds = %10
store i32 0, i32* %1
br label %50
50: ; preds = %49, %45, %38
%51 = load i32, i32* %1
ret i32 %51
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@STDOUT_FILENO = global i32 0
@.str = [12 x i8] c"source: %s\0A\00"
@.str.1 = [5 x i8] c"%d%d\00"
@.str.2 = [4 x i8] c"%d\0A\00"
@.str.4 = [14 x i8] c"invalid args\0A\00"
@str = [16 x i8] c"write msg error\00"
@str.6 = [12 x i8] c"write error\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [128 x i8]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = load i32, i32* @STDIN_FILENO
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @read(i32 %7, i8* %6, i32 128)
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %35
11: ; preds = %0, %29
%12 = phi i32 [ %30, %29 ], [ %9, %0 ]
%13 = zext i32 %12 to i64
%14 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 %13
store i8 0, i8* %14
%15 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %6)
%16 = call i32 @sscanf(i8* %6, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32* %1, i32* %2)
%17 = icmp eq i32 %16, 2
br i1 %17, label %18, label %26
18: ; preds = %11
%19 = load i32, i32* %1
%20 = load i32, i32* %2
%21 = add nsw i32 %20, %19
%22 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %21)
%23 = call i32 @strlen(i8* %6)
%24 = call i32 @write(i32 %8, i8* %6, i32 %23)
%25 = icmp eq i32 %24, %23
br i1 %25, label %29, label %32
26: ; preds = %11
%27 = call i32 @write(i32 %8, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i32 13)
%28 = icmp eq i32 %27, 13
br i1 %28, label %29, label %32
29: ; preds = %26, %18
%30 = call i32 @read(i32 %7, i8* %6, i32 128)
%31 = icmp sgt i32 %30, 0
br i1 %31, label %11, label %35
32: ; preds = %26, %18
%33 = phi i8* [ getelementptr inbounds ([12 x i8], [12 x i8]* @str.6, i64 0, i64 0), %18 ], [ getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0), %26 ]
%34 = call i32 @puts(i8* dereferenceable(1) %33)
br label %35
35: ; preds = %29, %32, %0
ret i32 0
}