#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 */
int /*<<< orphan*/ free(void *);
int /*<<< orphan*/ printf(char *, int);
scalar_t__ pthread_self();
scalar_t__ tq_get(struct tqFormat *, void **);
void *inc_count(void *idp) {
  struct tqFormat *tqh = (struct tqFormat *)idp;
  int my_id = (int)pthread_self();
  void *data;
  int j;
  double result = 0;
  while (tq_get(tqh, &data)) {
    printf("data %c\n", *(char *)data);
    free(data);
    printf("inc_count(): thread %d, working on data\n", my_id);
    for (j = 0; j < 10000000; j++) {
      result = result + result;
    }
    printf("inc_count(): thread %d, done working on data\n", my_id);
  }
  return 0;
}


x86 assembly (clang, -O0):
<inc_count>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    $0x0,%al
call   1060 <pthread_self@plt>
mov    %eax,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1050 <tq_get@plt>
cmp    $0x0,%rax
je     11ed <inc_count+0xad>
mov    -0x20(%rbp),%rax
movsbl (%rax),%esi
lea    0xe75(%rip),%rdi
call   1040 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
mov    -0x14(%rbp),%esi
lea    0xe66(%rip),%rdi
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x989680,-0x24(%rbp)
jge    11d9 <inc_count+0x99>
movsd  -0x30(%rbp),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    11af <inc_count+0x6f>
mov    -0x14(%rbp),%esi
lea    0xe4f(%rip),%rdi
call   1040 <printf@plt>
jmp    1166 <inc_count+0x26>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<inc_count>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
xor    %eax,%eax
call   1060 <pthread_self@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %r14,%rdi
call   1050 <tq_get@plt>
test   %rax,%rax
je     11bc <inc_count+0x7c>
lea    0xe91(%rip),%r15
lea    0xe93(%rip),%r12
lea    0xeb5(%rip),%r13
mov    %rsp,%rbp
mov    (%rsp),%rax
movsbl (%rax),%esi
mov    %r15,%rdi
call   1040 <printf@plt>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %r12,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %r13,%rdi
mov    %ebx,%esi
call   1040 <printf@plt>
mov    %r14,%rdi
mov    %rbp,%rsi
call   1050 <tq_get@plt>
test   %rax,%rax
jne    1180 <inc_count+0x40>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.tqFormat = type { i32 }
@.str = [9 x i8] c"data %c\0A\00"
@.str.1 = [41 x i8] c"inc_count(): thread %d, working on data\0A\00"
@.str.2 = [46 x i8] c"inc_count(): thread %d, done working on data\0A\00"
define i8* @inc_count(i8* %0) {
%2 = alloca i8*
%3 = alloca %struct.tqFormat*
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i32
%7 = alloca double
store i8* %0, i8** %2
%8 = load i8*, i8** %2
%9 = bitcast i8* %8 to %struct.tqFormat*
store %struct.tqFormat* %9, %struct.tqFormat** %3
%10 = call i64 (...) @pthread_self()
%11 = trunc i64 %10 to i32
store i32 %11, i32* %4
store double 0.000000e+00, double* %7
br label %12
12: ; preds = %35, %1
%13 = load %struct.tqFormat*, %struct.tqFormat** %3
%14 = call i64 @tq_get(%struct.tqFormat* %13, i8** %5)
%15 = icmp ne i64 %14, 0
br i1 %15, label %16, label %38
16: ; preds = %12
%17 = load i8*, i8** %5
%18 = load i8, i8* %17
%19 = sext i8 %18 to i32
%20 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %19)
%21 = load i8*, i8** %5
%22 = call i32 @free(i8* %21)
%23 = load i32, i32* %4
%24 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %23)
store i32 0, i32* %6
br label %25
25: ; preds = %32, %16
%26 = load i32, i32* %6
%27 = icmp slt i32 %26, 10000000
br i1 %27, label %28, label %35
28: ; preds = %25
%29 = load double, double* %7
%30 = load double, double* %7
%31 = fadd double %29, %30
store double %31, double* %7
br label %32
32: ; preds = %28
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %25
35: ; preds = %25
%36 = load i32, i32* %4
%37 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %12
38: ; preds = %12
ret i8* null
}

LLVM IR (-O2):
%struct.tqFormat = type { i32 }
@.str = [9 x i8] c"data %c\0A\00"
@.str.1 = [41 x i8] c"inc_count(): thread %d, working on data\0A\00"
@.str.2 = [46 x i8] c"inc_count(): thread %d, done working on data\0A\00"
define noalias i8* @inc_count(i8* %0) {
%2 = alloca i8*
%3 = bitcast i8* %0 to %struct.tqFormat*
%4 = tail call i64 (...) @pthread_self()
%5 = trunc i64 %4 to i32
%6 = bitcast i8** %2 to i8*
%7 = call i64 @tq_get(%struct.tqFormat* %3, i8** %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %20, label %9
9: ; preds = %1, %9
%10 = load i8*, i8** %2
%11 = load i8, i8* %10
%12 = sext i8 %11 to i32
%13 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = load i8*, i8** %2
%15 = call i32 @free(i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.1, i64 0, i64 0), i32 %5)
%17 = call i32 @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.2, i64 0, i64 0), i32 %5)
%18 = call i64 @tq_get(%struct.tqFormat* %3, i8** %2)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %9
20: ; preds = %9, %1
ret i8* null
}