#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 getchar();
int htoi(char *);
int /*<<< orphan*/ printf(char *, char *, int);
main() {
  char s[1024];
  int i, c;
  for (i = 0; (c = getchar()) != '\n'; ++i)
    s[i] = c;
  s[i] = '\0';
  printf("%s: %d\n", s, htoi(s));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x414(%rbp)
mov    $0x0,%al
call   1040 <getchar@plt>
mov    %eax,-0x418(%rbp)
cmp    $0xa,%eax
je     118c <main+0x5c>
mov    -0x418(%rbp),%eax
mov    %al,%cl
movslq -0x414(%rbp),%rax
mov    %cl,-0x410(%rbp,%rax,1)
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
jmp    114c <main+0x1c>
movslq -0x414(%rbp),%rax
movb   $0x0,-0x410(%rbp,%rax,1)
lea    -0x410(%rbp),%rax
mov    %rax,-0x420(%rbp)
lea    -0x410(%rbp),%rdi
call   1050 <htoi@plt>
mov    -0x420(%rbp),%rsi
mov    %eax,%edx
lea    0xe3b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x400,%rsp
xor    %ebx,%ebx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
je     1165 <main+0x35>
xor    %ebx,%ebx
nopl   0x0(%rax,%rax,1)
mov    %al,(%rsp,%rbx,1)
add    $0x1,%rbx
xor    %eax,%eax
call   1040 <getchar@plt>
cmp    $0xa,%eax
jne    1150 <main+0x20>
mov    %ebx,%ebx
movb   $0x0,(%rsp,%rbx,1)
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1050 <htoi@plt>
lea    0xe85(%rip),%rdi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
ret

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

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