#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__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ stdin;
int /*<<< orphan*/ stdout;
int main(int argc, char **argv) {
  if (argc == 2)
    fputs(argv[1], stdout);
  char buf[128];
  while (fgets(buf, 128, stdin)) {
    fputs(buf, stdout);
  }
  return 77;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    1159 <main+0x39>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    115e <main+0x3e>
lea    -0x90(%rbp),%rdi
mov    0x2e7c(%rip),%rax
mov    (%rax),%edx
mov    $0x80,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     119c <main+0x7c>
lea    -0x90(%rbp),%rdi
mov    0x2e48(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
jmp    115e <main+0x3e>
mov    $0x4d,%eax
add    $0x90,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x80,%rsp
cmp    $0x2,%edi
jne    1143 <main+0x23>
mov    0x8(%rsi),%rdi
mov    0x2e9c(%rip),%rax
mov    (%rax),%esi
call   1030 <fputs@plt>
mov    0x2e9e(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rdi
mov    $0x80,%esi
call   1040 <fgets@plt>
test   %rax,%rax
je     1190 <main+0x70>
mov    0x2e72(%rip),%r15
mov    %rsp,%rbx
nopl   0x0(%rax)
mov    (%r15),%esi
mov    %rbx,%rdi
call   1030 <fputs@plt>
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x80,%esi
call   1040 <fgets@plt>
test   %rax,%rax
jne    1170 <main+0x50>
mov    $0x4d,%eax
add    $0x80,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdout = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp eq i32 %7, 2
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @stdout
%14 = call i32 @fputs(i8* %12, i32 %13)
br label %15
15: ; preds = %9, %2
br label %16
16: ; preds = %21, %15
%17 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%18 = load i32, i32* @stdin
%19 = call i64 @fgets(i8* %17, i32 128, i32 %18)
%20 = icmp ne i64 %19, 0
br i1 %20, label %21, label %25
21: ; preds = %16
%22 = getelementptr inbounds [128 x i8], [128 x i8]* %6, i64 0, i64 0
%23 = load i32, i32* @stdout
%24 = call i32 @fputs(i8* %22, i32 %23)
br label %16
25: ; preds = %16
ret i32 77
}

LLVM IR (-O2):
@stdout = global i32 0
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [128 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %5, label %10
5: ; preds = %2
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = load i32, i32* @stdout
%9 = tail call i32 @fputs(i8* %7, i32 %8)
br label %10
10: ; preds = %5, %2
%11 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %11, i32 128, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %21, label %15
15: ; preds = %10, %15
%16 = load i32, i32* @stdout
%17 = call i32 @fputs(i8* %11, i32 %16)
%18 = load i32, i32* @stdin
%19 = call i64 @fgets(i8* %11, i32 128, i32 %18)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %15
21: ; preds = %15, %10
ret i32 77
}