#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__ condition(int, int, int);
int getchar();
int /*<<< orphan*/ printf(char *, char *);
int main() {
  int i, lim, c;
  char s[1000];
  lim = 1000;
  i = 0;
  while (condition(1000, i, c = getchar())) {
    s[i] = c;
    ++i;
  }
  s[i] = '\0';
  printf("%s\n", s);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x410,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x3e8,-0xc(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x404(%rbp)
mov    $0x0,%al
call   1050 <getchar@plt>
mov    -0x404(%rbp),%esi
mov    %eax,%edx
mov    %edx,-0x10(%rbp)
mov    $0x3e8,%edi
call   1030 <condition@plt>
cmp    $0x0,%rax
je     119d <main+0x6d>
mov    -0x10(%rbp),%eax
mov    %al,%cl
movslq -0x8(%rbp),%rax
mov    %cl,-0x400(%rbp,%rax,1)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1150 <main+0x20>
movslq -0x8(%rbp),%rax
movb   $0x0,-0x400(%rbp,%rax,1)
lea    -0x400(%rbp),%rsi
lea    0xe49(%rip),%rdi
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x410,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x3e8,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
mov    $0x3e8,%edi
xor    %esi,%esi
mov    %eax,%edx
call   1030 <condition@plt>
test   %rax,%rax
je     1186 <main+0x56>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %bpl,(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1050 <getchar@plt>
mov    %eax,%ebp
mov    $0x3e8,%edi
mov    %ebx,%esi
mov    %eax,%edx
call   1030 <condition@plt>
test   %rax,%rax
jne    1160 <main+0x30>
mov    %ebx,%ebx
movb   $0x0,(%rsp,%rbx,1)
lea    0xe6f(%rip),%rdi
mov    %rsp,%rsi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x3e8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i8]
store i32 0, i32* %1
store i32 1000, i32* %3
store i32 0, i32* %2
br label %6
6: ; preds = %11, %0
%7 = load i32, i32* %2
%8 = call i32 (...) @getchar()
store i32 %8, i32* %4
%9 = call i64 @condition(i32 1000, i32 %7, i32 %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %19
11: ; preds = %6
%12 = load i32, i32* %4
%13 = trunc i32 %12 to i8
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %15
store i8 %13, i8* %16
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %6
19: ; preds = %6
%20 = load i32, i32* %2
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 %21
store i8 0, i8* %22
%23 = getelementptr inbounds [1000 x i8], [1000 x i8]* %5, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %23)
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [4 x i8] c"%s\0A\00"
define i32 @main() {
%1 = alloca [1000 x i8]
%2 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 0
%3 = tail call i32 (...) @getchar()
%4 = tail call i64 @condition(i32 1000, i32 0, i32 %3)
%5 = icmp eq i64 %4, 0
br i1 %5, label %18, label %6
6: ; preds = %0, %6
%7 = phi i64 [ %11, %6 ], [ 0, %0 ]
%8 = phi i32 [ %12, %6 ], [ %3, %0 ]
%9 = trunc i32 %8 to i8
%10 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %7
store i8 %9, i8* %10
%11 = add nuw i64 %7, 1
%12 = tail call i32 (...) @getchar()
%13 = trunc i64 %11 to i32
%14 = tail call i64 @condition(i32 1000, i32 %13, i32 %12)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %6
16: ; preds = %6
%17 = and i64 %11, 4294967295
br label %18
18: ; preds = %16, %0
%19 = phi i64 [ 0, %0 ], [ %17, %16 ]
%20 = getelementptr inbounds [1000 x i8], [1000 x i8]* %1, i64 0, i64 %19
store i8 0, i8* %20
%21 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* %2)
ret i32 0
}