#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 /*<<< orphan*/ LC_ALL;
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ setlocale(int /*<<< orphan*/, char *);
int strlen(char *);
int main() {
  setlocale(LC_ALL, "");
  int i, j = 0;
  char nums[6] = "01011";
  for (i = 0; i < strlen(nums); i++) {
    if (nums[i] == '1') {
      j++;
    }
  }
  printf("Soma: %d\n", j);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
lea    0xec0(%rip),%rsi
call   1050 <setlocale@plt>
movl   $0x0,-0xc(%rbp)
mov    0xe9f(%rip),%eax
mov    %eax,-0x12(%rbp)
mov    0xe99(%rip),%ax
mov    %ax,-0xe(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x18(%rbp)
lea    -0x12(%rbp),%rdi
call   1030 <strlen@plt>
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
cmp    %ecx,%eax
jge    11c0 <main+0x90>
movslq -0x8(%rbp),%rax
movsbl -0x12(%rbp,%rax,1),%eax
cmp    $0x31,%eax
jne    11ad <main+0x7d>
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11b2 <main+0x82>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1176 <main+0x46>
mov    -0xc(%rbp),%esi
lea    0xe3c(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    0x2ea1(%rip),%rax
mov    (%rax),%edi
lea    0xec7(%rip),%rsi
call   1050 <setlocale@plt>
movw   $0x31,0xc(%rsp)
movl   $0x31303130,0x8(%rsp)
31
lea    0x8(%rsp),%rdi
call   1030 <strlen@plt>
test   %eax,%eax
jle    11a1 <main+0x71>
xor    %ebx,%ebx
lea    0x8(%rsp),%r14
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
xor    %eax,%eax
cmpb   $0x31,0x8(%rsp,%rbx,1)
sete   %al
add    %eax,%ebp
add    $0x1,%rbx
mov    %r14,%rdi
call   1030 <strlen@plt>
cltq
cmp    %rax,%rbx
jl     1180 <main+0x50>
jmp    11a3 <main+0x73>
xor    %ebp,%ebp
lea    0xe5c(%rip),%rdi
mov    %ebp,%esi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@__const.main.nums = [6 x i8] c"01011\00"
@.str.1 = [10 x i8] c"Soma: %d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [6 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @LC_ALL
%6 = call i32 @setlocale(i32 %5, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %3
%7 = bitcast [6 x i8]* %4 to i8*
store i32 0, i32* %2
br label %8
8: ; preds = %24, %0
%9 = load i32, i32* %2
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 0
%11 = call i32 @strlen(i8* %10)
%12 = icmp slt i32 %9, %11
br i1 %12, label %13, label %27
13: ; preds = %8
%14 = load i32, i32* %2
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds [6 x i8], [6 x i8]* %4, i64 0, i64 %15
%17 = load i8, i8* %16
%18 = sext i8 %17 to i32
%19 = icmp eq i32 %18, 49
br i1 %19, label %20, label %23
20: ; preds = %13
%21 = load i32, i32* %3
%22 = add nsw i32 %21, 1
store i32 %22, i32* %3
br label %23
23: ; preds = %20, %13
br label %24
24: ; preds = %23
%25 = load i32, i32* %2
%26 = add nsw i32 %25, 1
store i32 %26, i32* %2
br label %8
27: ; preds = %8
%28 = load i32, i32* %3
%29 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %28)
ret i32 0
}

LLVM IR (-O2):
@LC_ALL = global i32 0
@.str = [1 x i8] zeroinitializer
@__const.main.nums = [6 x i8] c"01011\00"
@.str.1 = [10 x i8] c"Soma: %d\0A\00"
define i32 @main() {
%1 = alloca [6 x i8]
%2 = load i32, i32* @LC_ALL
%3 = tail call i32 @setlocale(i32 %2, i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str, i64 0, i64 0))
%4 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 0
%5 = call i32 @strlen(i8* %4)
%6 = icmp sgt i32 %5, 0
br i1 %6, label %7, label %19
7: ; preds = %0, %7
%8 = phi i64 [ %15, %7 ], [ 0, %0 ]
%9 = phi i32 [ %14, %7 ], [ 0, %0 ]
%10 = getelementptr inbounds [6 x i8], [6 x i8]* %1, i64 0, i64 %8
%11 = load i8, i8* %10
%12 = icmp eq i8 %11, 49
%13 = zext i1 %12 to i32
%14 = add nuw nsw i32 %9, %13
%15 = add nuw nsw i64 %8, 1
%16 = call i32 @strlen(i8* %4)
%17 = sext i32 %16 to i64
%18 = icmp slt i64 %15, %17
br i1 %18, label %7, label %19
19: ; preds = %7, %0
%20 = phi i32 [ 0, %0 ], [ %14, %7 ]
%21 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %20)
ret i32 0
}