#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 */
typedef int /*<<< orphan*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ pclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *popen(char *, char *);
int /*<<< orphan*/ sprintf(char *, char *, char *);
int sscanf(char *, char *, unsigned short *);
unsigned short get_task_id(char *uuid) {
  FILE *cmd;
  char line[128];
  char format[128];
  int ret;
  unsigned short id = 0;
  sprintf(format, "%s %%hu", uuid);
  cmd = popen("task rc.report.all.columns:uuid,id rc.report.all.labels:UUID,id "
              "rc.report.all.sort:id- all status:pending rc._forcecolor=no",
              "r");
  while (fgets(line, sizeof(line) - 1, cmd) != NULL) {
    ret = sscanf(line, format, &id);
    if (ret > 0) {
      break;
    }
  }
  pclose(cmd);
  return id;
}


x86 assembly (clang, -O0):
<get_task_id>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    %rdi,-0x8(%rbp)
movw   $0x0,-0x116(%rbp)
lea    -0x110(%rbp),%rdi
mov    -0x8(%rbp),%rdx
lea    0xe86(%rip),%rsi
call   1070 <sprintf@plt>
lea    0xe82(%rip),%rdi
lea    0xef7(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,-0x10(%rbp)
lea    -0x90(%rbp),%rdi
mov    -0x10(%rbp),%rdx
mov    $0x7f,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     11ec <get_task_id+0x9c>
lea    -0x90(%rbp),%rdi
lea    -0x110(%rbp),%rsi
lea    -0x116(%rbp),%rdx
call   1050 <sscanf@plt>
mov    %eax,-0x114(%rbp)
cmpl   $0x0,-0x114(%rbp)
jle    11e7 <get_task_id+0x97>
jmp    11ec <get_task_id+0x9c>
jmp    1196 <get_task_id+0x46>
mov    -0x10(%rbp),%rdi
call   1030 <pclose@plt>
movzwl -0x116(%rbp),%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_task_id>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x118,%rsp
mov    %rdi,%rdx
movw   $0x0,0xe(%rsp)
lea    0xe91(%rip),%rsi
lea    0x10(%rsp),%r14
mov    %r14,%rdi
call   1070 <sprintf@plt>
lea    0xe85(%rip),%rdi
lea    0xefa(%rip),%rsi
call   1060 <popen@plt>
mov    %rax,%rbx
lea    0x90(%rsp),%r15
lea    0xe(%rsp),%r12
nop
mov    %r15,%rdi
mov    $0x7f,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11c7 <get_task_id+0x77>
mov    %r15,%rdi
mov    %r14,%rsi
mov    %r12,%rdx
call   1050 <sscanf@plt>
test   %eax,%eax
jle    11a0 <get_task_id+0x50>
mov    %rbx,%rdi
call   1030 <pclose@plt>
movzwl 0xe(%rsp),%eax
add    $0x118,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [8 x i8] c"%s %%hu\00"
@.str.1 = [124 x i8] c"task rc.report.all.columns:uuid,id rc.report.all.labels:UUID,id rc.report.all.sort:id- all status:pending rc._forcecolor=no\00"
@.str.2 = [2 x i8] c"r\00"
define zeroext i16 @get_task_id(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [128 x i8]
%5 = alloca [128 x i8]
%6 = alloca i32
%7 = alloca i16
store i8* %0, i8** %2
store i16 0, i16* %7
%8 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%9 = load i8*, i8** %2
%10 = call i32 @sprintf(i8* %8, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %9)
%11 = call i32* @popen(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %11, i32** %3
br label %12
12: ; preds = %24, %1
%13 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32* @fgets(i8* %13, i32 127, i32* %14)
%16 = icmp ne i32* %15, null
br i1 %16, label %17, label %25
17: ; preds = %12
%18 = getelementptr inbounds [128 x i8], [128 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%20 = call i32 @sscanf(i8* %18, i8* %19, i16* %7)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp sgt i32 %21, 0
br i1 %22, label %23, label %24
23: ; preds = %17
br label %25
24: ; preds = %17
br label %12
25: ; preds = %23, %12
%26 = load i32*, i32** %3
%27 = call i32 @pclose(i32* %26)
%28 = load i16, i16* %7
ret i16 %28
}

LLVM IR (-O2):
@.str = [8 x i8] c"%s %%hu\00"
@.str.1 = [124 x i8] c"task rc.report.all.columns:uuid,id rc.report.all.labels:UUID,id rc.report.all.sort:id- all status:pending rc._forcecolor=no\00"
@.str.2 = [2 x i8] c"r\00"
define zeroext i16 @get_task_id(i8* %0) {
%2 = alloca [128 x i8]
%3 = alloca [128 x i8]
%4 = alloca i16
%5 = getelementptr inbounds [128 x i8], [128 x i8]* %2, i64 0, i64 0
%6 = getelementptr inbounds [128 x i8], [128 x i8]* %3, i64 0, i64 0
%7 = bitcast i16* %4 to i8*
store i16 0, i16* %4
%8 = call i32 @sprintf(i8* %6, i8* dereferenceable(1) getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i8* %0)
%9 = tail call i32* @popen(i8* getelementptr inbounds ([124 x i8], [124 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
br label %10
10: ; preds = %13, %1
%11 = call i32* @fgets(i8* %5, i32 127, i32* %9)
%12 = icmp eq i32* %11, null
br i1 %12, label %16, label %13
13: ; preds = %10
%14 = call i32 @sscanf(i8* %5, i8* %6, i16* %4)
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %10
16: ; preds = %13, %10
%17 = call i32 @pclose(i32* %9)
%18 = load i16, i16* %4
ret i16 %18
}