#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 */
struct tqFormat {
  int dummy;
};

/* Variables and functions */
char *malloc(int);
int /*<<< orphan*/ printf(char *, char);
int /*<<< orphan*/ tq_add(struct tqFormat *, char *);
int /*<<< orphan*/ tq_end(struct tqFormat *);
void *add_data(void *idp) {
  struct tqFormat *tqh = (struct tqFormat *)idp;
  int my_id = 0;
  int i;
  char c;
  char *cp;
  printf("Starting watch_count(): thread %d\n", my_id);
  for (i = 0; i < 26; i++) {
    c = (char)((int)'a' + i);
    cp = malloc(sizeof(char));
    *cp = c;
    printf("trying to add %c\n", *cp);
    tq_add(tqh, cp);
  }
  tq_end(tqh);
  return 0;
}


x86 assembly (clang, -O0):
<add_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x14(%rbp),%eax
lea    0xe9b(%rip),%rdi
movsbl %al,%esi
call   1050 <printf@plt>
movl   $0x0,-0x18(%rbp)
cmpl   $0x1a,-0x18(%rbp)
jge    11cc <add_data+0x8c>
mov    -0x18(%rbp),%eax
add    $0x61,%eax
mov    %al,-0x19(%rbp)
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x19(%rbp),%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
lea    0xe7a(%rip),%rdi
movsbl (%rax),%esi
call   1050 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1040 <tq_add@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1174 <add_data+0x34>
mov    -0x10(%rbp),%rdi
call   1030 <tq_end@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<add_data>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %rdi,%r15
lea    0xeae(%rip),%rdi
xor    %esi,%esi
call   1050 <printf@plt>
mov    $0xffffffe6,%ebx
lea    0xebe(%rip),%r14
cs nopw 0x0(%rax,%rax,1)
nop
lea    0x7b(%rbx),%ebp
mov    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%r12
mov    %bpl,(%rax)
movsbl %bpl,%esi
mov    %r14,%rdi
call   1050 <printf@plt>
mov    %r15,%rdi
mov    %r12,%rsi
call   1040 <tq_add@plt>
inc    %ebx
jne    1170 <add_data+0x30>
mov    %r15,%rdi
call   1030 <tq_end@plt>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tqFormat = type { i32 }
@.str = [35 x i8] c"Starting watch_count(): thread %d\0A\00"
@.str.1 = [18 x i8] c"trying to add %c\0A\00"
define i8* @add_data(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tqFormat*
%4 = alloca i32
%5 = alloca i32
%6 = alloca i8
%7 = alloca i8*
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to %struct.tqFormat*
store %struct.tqFormat* %9, %struct.tqFormat** %3
store i32 0, i32* %4
%10 = load i32, i32* %4
%11 = trunc i32 %10 to i8
%12 = call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext %11)
store i32 0, i32* %5
br label %13
13: ; preds = %29, %1
%14 = load i32, i32* %5
%15 = icmp slt i32 %14, 26
br i1 %15, label %16, label %32
16: ; preds = %13
%17 = load i32, i32* %5
%18 = add nsw i32 97, %17
%19 = trunc i32 %18 to i8
store i8 %19, i8* %6
%20 = call i8* @malloc(i32 1)
store i8* %20, i8** %7
%21 = load i8, i8* %6
%22 = load i8*, i8** %7
store i8 %21, i8* %22
%23 = load i8*, i8** %7
%24 = load i8, i8* %23
%25 = call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8 signext %24)
%26 = load %struct.tqFormat*, %struct.tqFormat** %3
%27 = load i8*, i8** %7
%28 = call i32 @tq_add(%struct.tqFormat* %26, i8* %27)
br label %29
29: ; preds = %16
%30 = load i32, i32* %5
%31 = add nsw i32 %30, 1
store i32 %31, i32* %5
br label %13
32: ; preds = %13
%33 = load %struct.tqFormat*, %struct.tqFormat** %3
%34 = call i32 @tq_end(%struct.tqFormat* %33)
ret i8* null
}

LLVM IR (-O2):
%struct.tqFormat = type { i32 }
@.str = [35 x i8] c"Starting watch_count(): thread %d\0A\00"
@.str.1 = [18 x i8] c"trying to add %c\0A\00"
define noalias i8* @add_data(i8* %0) {
%2 = bitcast i8* %0 to %struct.tqFormat*
%3 = tail call i32 @printf(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext 0)
br label %4
4: ; preds = %1, %4
%5 = phi i32 [ 0, %1 ], [ %11, %4 ]
%6 = trunc i32 %5 to i8
%7 = add nuw nsw i8 %6, 97
%8 = tail call dereferenceable_or_null(1) i8* @malloc(i32 1)
store i8 %7, i8* %8
%9 = tail call i32 @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8 signext %7)
%10 = tail call i32 @tq_add(%struct.tqFormat* %2, i8* %8)
%11 = add nuw nsw i32 %5, 1
%12 = icmp eq i32 %11, 26
br i1 %12, label %13, label %4
13: ; preds = %4
%14 = tail call i32 @tq_end(%struct.tqFormat* %2)
ret i8* null
}