#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*/ printf(char *, int);
scalar_t__ strncmp(char *, char *, int);
char *feed(char *twitter_resp) {
  char *ptr = twitter_resp;
  int bracket_count = 0, tweet_count = 0;
  while (*ptr) {
    if (strncmp(ptr, "{", 1) == 0)
      bracket_count++;
    if (strncmp(ptr, "}", 1) == 0)
      bracket_count--;
    ptr++;
    if (bracket_count == 0)
      tweet_count++;
  }
  printf("%i\n", tweet_count);
  return twitter_resp;
}


x86 assembly (clang, -O0):
<feed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rax
cmpb   $0x0,(%rax)
je     11c3 <feed+0xa3>
mov    -0x10(%rbp),%rdi
lea    0xea6(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    1177 <feed+0x57>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe80(%rip),%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x0,%rax
jne    119f <feed+0x7f>
mov    -0x14(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x10(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    11be <feed+0x9e>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1142 <feed+0x22>
mov    -0x18(%rbp),%esi
lea    0xe37(%rip),%rdi
call   1040 <printf@plt>
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<feed>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
cmpb   $0x0,(%rdi)
je     1195 <feed+0x75>
xor    %r13d,%r13d
lea    0xec3(%rip),%r15
lea    0xebe(%rip),%r12
xor    %ebp,%ebp
mov    %r14,%rbx
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
cmp    $0x1,%rax
adc    $0x0,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
mov    $0x1,%edx
call   1030 <strncmp@plt>
xor    %ecx,%ecx
test   %rax,%rax
sete   %cl
xor    %eax,%eax
sub    %ecx,%ebp
sete   %al
add    %eax,%r13d
cmpb   $0x0,0x1(%rbx)
lea    0x1(%rbx),%rbx
jne    1150 <feed+0x30>
jmp    1198 <feed+0x78>
xor    %r13d,%r13d
lea    0xe65(%rip),%rdi
mov    %r13d,%esi
call   1040 <printf@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"{\00"
@.str.1 = [2 x i8] c"}\00"
@.str.2 = [4 x i8] c"%i\0A\00"
define i8* @feed(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i32
%5 = alloca i32
store i8* %0, i8** %2
%6 = load i8*, i8** %2
store i8* %6, i8** %3
store i32 0, i32* %4
store i32 0, i32* %5
br label %7
7: ; preds = %33, %1
%8 = load i8*, i8** %3
%9 = load i8, i8* %8
%10 = icmp ne i8 %9, 0
br i1 %10, label %11, label %34
11: ; preds = %7
%12 = load i8*, i8** %3
%13 = call i64 @strncmp(i8* %12, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %18
18: ; preds = %15, %11
%19 = load i8*, i8** %3
%20 = call i64 @strncmp(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %18
%23 = load i32, i32* %4
%24 = add nsw i32 %23, -1
store i32 %24, i32* %4
br label %25
25: ; preds = %22, %18
%26 = load i8*, i8** %3
%27 = getelementptr inbounds i8, i8* %26, i32 1
store i8* %27, i8** %3
%28 = load i32, i32* %4
%29 = icmp eq i32 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25
%31 = load i32, i32* %5
%32 = add nsw i32 %31, 1
store i32 %32, i32* %5
br label %33
33: ; preds = %30, %25
br label %7
34: ; preds = %7
%35 = load i32, i32* %5
%36 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %35)
%37 = load i8*, i8** %2
ret i8* %37
}

LLVM IR (-O2):
@.str = [2 x i8] c"{\00"
@.str.1 = [2 x i8] c"}\00"
@.str.2 = [4 x i8] c"%i\0A\00"
define i8* @feed(i8* returned %0) {
%2 = load i8, i8* %0
%3 = icmp eq i8 %2, 0
br i1 %3, label %22, label %4
4: ; preds = %1, %4
%5 = phi i32 [ %19, %4 ], [ 0, %1 ]
%6 = phi i32 [ %15, %4 ], [ 0, %1 ]
%7 = phi i8* [ %16, %4 ], [ %0, %1 ]
%8 = tail call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32 1)
%9 = icmp eq i64 %8, 0
%10 = zext i1 %9 to i32
%11 = add nsw i32 %6, %10
%12 = tail call i64 @strncmp(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
%13 = icmp eq i64 %12, 0
%14 = sext i1 %13 to i32
%15 = add nsw i32 %11, %14
%16 = getelementptr inbounds i8, i8* %7, i64 1
%17 = icmp eq i32 %15, 0
%18 = zext i1 %17 to i32
%19 = add nuw nsw i32 %5, %18
%20 = load i8, i8* %16
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %4
22: ; preds = %4, %1
%23 = phi i32 [ 0, %1 ], [ %19, %4 ]
%24 = tail call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %23)
ret i8* %0
}